x_start = np.array([-3.0, 0.0])
x_goal = np.array([0.0, 0.0])

###########################
# Create objects
###########################

Robot = Manipulator.OneLinkManipulator()

PD = linear.PD(kp=5, kd=2)
PID = linear.PID(kp=5, kd=2, ki=4)
CTC = ComputedTorque.ComputedTorqueController(Robot)
SLD = ComputedTorque.SlidingModeController(Robot)
RRT = RandomTree.RRT(Robot, x_start)
VI = DPO.ValueIteration1DOF(Robot, 'quadratic')

############################
# Params
############################

tmax = 8  # max motor torque
Robot.u_ub = np.array([tmax])  # Control Upper Bounds
Robot.u_lb = np.array([-tmax])  # Control Lower Bounds
RRT.x_start = x_start
RRT.discretizeactions(3)
RRT.dt = 0.1
RRT.goal_radius = 0.3
RRT.max_nodes = 5000
RRT.max_solution_time = 5
RRT.dyna_plot = True
Ejemplo n.º 2
0
@author: alex
"""

from AlexRobotics.dynamic import Manipulator   as M
from AlexRobotics.control import DPO           as DPO

import matplotlib.pyplot as plt

""" Define system """

# Define dynamic system
R  =  M.OneLinkManipulator()

# Define controller
cost_function = 'quadratic'
ValueIterationAlgo     = DPO.ValueIteration1DOF( R , cost_function )

path = 'data/'

ValueIterationAlgo.first_step()
ValueIterationAlgo.load_data( path + 'R1' + cost_function )
#ValueIterationAlgo.compute_steps(200)
ValueIterationAlgo.compute_steps(1)
ValueIterationAlgo.save_data( path + 'R1' + cost_function ) 

# Plot Value Iteration Results
ValueIterationAlgo.plot_raw()
ValueIterationAlgo.plot_J_nice( 2 )

# Assign Controller
ValueIterationAlgo.assign_interpol_controller() 
from AlexRobotics.dynamic import simple1DOF as RD1
from AlexRobotics.control import DPO as DPO

import matplotlib.pyplot as plt
""" Define system """

# Define dynamic system
pendulum = RD1.Pendulum()
m = 0.5
l = 1
g = 9.8
pendulum.setparams(m, g, l)

# Define controller
cost_function = 'quadratic'
ValueIterationAlgo = DPO.ValueIteration1DOF(pendulum, cost_function)

path = 'data/'

ValueIterationAlgo.first_step()
ValueIterationAlgo.load_data(path + cost_function + 'pendulum')
ValueIterationAlgo.compute_steps(1)
ValueIterationAlgo.save_data(path + cost_function + 'pendulum')

# Plot Value Iteration Results
ValueIterationAlgo.plot_raw()

# Assign Controller
ValueIterationAlgo.assign_interpol_controller()
""" Simulation and plotting """
@author: alex
"""

from AlexRobotics.dynamic import Manipulator as M
from AlexRobotics.control import DPO as DPO

import numpy as np
import matplotlib.pyplot as plt

# Define dynamic system
R = M.OneLinkManipulator()

# Define controller
cost_function = 'quadratic'
QLearningAlgo = DPO.QLearning1DOF(R, cost_function)

path = 'data/'
name = 'R1_Qlearning' + cost_function

#n_steps = 10000
n_steps = 1

QLearningAlgo.first_step()
QLearningAlgo.load_data(name)

x0 = np.array([3, 0])
QLearningAlgo.x0 = x0

QLearningAlgo.training(n_steps, True, True)
CTC_controller = RminCTC.RminComputedTorqueController(R)

CTC_controller.load_trajectory(RRT.solution)

CTC_controller.w0 = 1.0
CTC_controller.zeta = 0.7
CTC_controller.n_gears = 2
CTC_controller.traj_ref_pts = 'interpol'
CTC_controller.hysteresis = True
CTC_controller.hys_level = 1.0
CTC_controller.min_delay = 0.1
""" Value Iteration """

# Define controller
cost_function = 'quadratic'
ValueIterationAlgo = DPO.ValueIteration_hybrid_1DOF(R, cost_function)

ValueIterationAlgo.first_step()
ValueIterationAlgo.load_data(path + 'R1H' + cost_function)
#ValueIterationAlgo.compute_steps(50)
ValueIterationAlgo.compute_steps(1)
ValueIterationAlgo.save_data(path + 'R1H' + cost_function)

#ValueIterationAlgo.plot_raw_nice( 2 )
""" RRT Simulation """

R.ctl = CTC_controller.ctl
tf = RRT.time_to_goal + 5
n = int(10 / 0.001) + 1

R.computeSim(x_start, tf, n, solver='euler')