# Objectives
###########################

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
Created on Sat Mar  5 20:24:50 2016

@author: alex
"""

from AlexRobotics.dynamic import Manipulator as M
from AlexRobotics.control import ComputedTorque as CTC

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

# Define dynamic system
R = M.TwoLinkManipulator()

# Define controller
CTC_controller = CTC.SlidingModeController(R)
CTC_controller.lam = 1
CTC_controller.nab = 1
CTC_controller.D = 0

# Asign feedback law to the dynamic system
R.ctl = CTC_controller.ctl
""" Simulation and plotting """

# Ploting a trajectory
x0 = [3, -1, 0, 0]
tf = 10
dt = 0.01
n = int(tf / dt) + 1

R.plotAnimation(x0, tf, n, solver='euler')