ep_trajectory_controller.py
Go to the documentation of this file.
00001 
00002 import numpy as np
00003 
00004 import roslib
00005 roslib.load_manifest('hrl_generic_arms')
00006 import rospy
00007 
00008 from equilibrium_point_control.ep_control import EPGenerator, EPC, EPStopConditions
00009 
00010 ##
00011 # Returns a minimum jerk trajectory from x=0..1 given
00012 # the number of samples in the trajectory.  Assumes
00013 # x_i = 0, x_f = 1, v_i = 0, v_f = 0.
00014 def min_jerk_traj(n):
00015     return [(10 * t**3 - 15 * t**4 + 6 * t**5)
00016             for t in np.linspace(0, 1, n)]
00017 
00018 ##
00019 # Implements a generic equilibirum point generator given a list
00020 # of EPs and the arm object to execute them on.
00021 class EPTrajectoryControl(EPGenerator):
00022     def __init__(self, control_arm, trajectory, time_step=0.1):
00023         self.control_arm = control_arm
00024         self.trajectory = trajectory
00025         self.time_step = time_step
00026         self.t_i = 0
00027 
00028     def generate_ep(self):
00029         ep_new = self.trajectory[self.t_i]
00030         self.t_i += 1
00031         return EPStopConditions.CONTINUE, ep_new
00032 
00033     def control_ep(self, ep):
00034         self.control_arm.set_ep(ep, self.time_step)
00035 
00036     def clamp_ep(self, ep):
00037         return ep
00038         
00039     def terminate_check(self):
00040         if self.t_i == len(self.trajectory):
00041             return EPStopConditions.SUCCESSFUL
00042         return EPStopConditions.CONTINUE
00043 
00044 ##
00045 # Equilbrium Point Control object used to execute a trajectory from 
00046 # the current EP to the end EP using a minimum jerk interpolation.
00047 class EPArmController(EPC):
00048     def __init__(self, arm, time_step=0.1, epc_name='epc_arm_controller'):
00049         super(EPArmController, self).__init__(epc_name)
00050         self.arm = arm
00051         self.time_step = time_step
00052 
00053     def execute_interpolated_ep(self, end_ep, duration, blocking=True):
00054         num_samps = duration / self.time_step
00055         joint_traj = self.arm.interpolate_ep(self.arm.get_ep(), end_ep, min_jerk_traj(num_samps))
00056         ep_traj_control = EPTrajectoryControl(self.arm, joint_traj, self.time_step)
00057         def exec_motion(event):
00058             self.epc_motion(ep_traj_control, self.time_step)
00059         if blocking:
00060             exec_motion(None)
00061         else:
00062             rospy.Timer(rospy.Duration(0.01), exec_motion, oneshot=True)


hrl_generic_arms
Author(s): Kelsey Hawkins
autogenerated on Wed Nov 27 2013 11:53:37