3333# This is an example of how to interface the robot without any additional ROS components. For
3434# real-life applications, we do recommend to use something like MoveIt!
3535
36- import time
36+ from math import pi
3737
3838import rclpy
3939from rclpy .action import ActionClient
4949 {
5050 "positions" : [0.043128 , - 1.28824 , 1.37179 , - 1.82208 , - 1.63632 , - 0.18 ],
5151 "velocities" : [0 , 0 , 0 , 0 , 0 , 0 ],
52+ "accelerations" : [0 , 0 , 0 , 0 , 0 , 0 ],
5253 "time_from_start" : Duration (sec = 4 , nanosec = 0 ),
5354 },
5455 {
5556 "positions" : [- 0.195016 , - 1.70093 , 0.902027 , - 0.944217 , - 1.52982 , - 0.195171 ],
5657 "velocities" : [0 , 0 , 0 , 0 , 0 , 0 ],
58+ "accelerations" : [0 , 0 , 0 , 0 , 0 , 0 ],
5759 "time_from_start" : Duration (sec = 8 , nanosec = 0 ),
5860 },
5961 ],
6062 "traj1" : [
6163 {
6264 "positions" : [- 0.195016 , - 1.70094 , 0.902027 , - 0.944217 , - 1.52982 , - 0.195171 ],
6365 "velocities" : [0 , 0 , 0 , 0 , 0 , 0 ],
66+ "accelerations" : [0 , 0 , 0 , 0 , 0 , 0 ],
6467 "time_from_start" : Duration (sec = 0 , nanosec = 0 ),
6568 },
6669 {
6770 "positions" : [0.30493 , - 0.982258 , 0.955637 , - 1.48215 , - 1.72737 , 0.204445 ],
6871 "velocities" : [0 , 0 , 0 , 0 , 0 , 0 ],
72+ "accelerations" : [0 , 0 , 0 , 0 , 0 , 0 ],
6973 "time_from_start" : Duration (sec = 8 , nanosec = 0 ),
7074 },
7175 ],
7276}
77+ HOME = {
78+ "elbow_joint" : 0.0 ,
79+ "shoulder_lift_joint" : - 1.5708 ,
80+ "shoulder_pan_joint" : 0.0 ,
81+ "wrist_1_joint" : - 1.5708 ,
82+ "wrist_2_joint" : 0.0 ,
83+ "wrist_3_joint" : 0.0 ,
84+ }
7385
7486
7587class JTCClient (rclpy .node .Node ):
@@ -96,6 +108,23 @@ def __init__(self):
96108 if self .joints is None or len (self .joints ) == 0 :
97109 raise Exception ('"joints" parameter is required' )
98110
111+ waypts = [[HOME [joint ] + i * pi / 4 for joint in self .joints ] for i in [0 , - 1 , 1 ]]
112+ time_vec = [
113+ Duration (sec = 4 , nanosec = 0 ),
114+ Duration (sec = 8 , nanosec = 0 ),
115+ Duration (sec = 12 , nanosec = 0 ),
116+ ]
117+ TRAJECTORIES ["test_traj" ] = [
118+ {
119+ "positions" : waypts [i ],
120+ "velocities" : [0 ] * 6 ,
121+ "accelerations" : [0 ] * 6 ,
122+ "time_from_start" : time_vec [i ],
123+ }
124+ for i in range (len (waypts ))
125+ ]
126+ # (time_vec[i], waypts[i]) for i in range(len(waypts))]
127+
99128 self ._action_client = ActionClient (self , FollowJointTrajectory , controller_name )
100129 self .get_logger ().info (f"Waiting for action server on { controller_name } " )
101130 self ._action_client .wait_for_server ()
@@ -116,15 +145,17 @@ def parse_trajectories(self):
116145 point = JointTrajectoryPoint ()
117146 point .positions = pt ["positions" ]
118147 point .velocities = pt ["velocities" ]
148+ point .accelerations = pt ["accelerations" ]
119149 point .time_from_start = pt ["time_from_start" ]
120150 goal .points .append (point )
121151
122152 self .goals [traj_name ] = goal
123153
124154 def execute_next_trajectory (self ):
125155 if self .i >= len (self .goals ):
126- self .get_logger ().info ("Done with all trajectories" )
127- raise SystemExit
156+ self .i = 0
157+ # self.get_logger().info("Done with all trajectories")
158+ # raise SystemExit
128159 traj_name = list (self .goals )[self .i ]
129160 self .i = self .i + 1
130161 if traj_name :
@@ -159,7 +190,6 @@ def get_result_callback(self, future):
159190 status = future .result ().status
160191 self .get_logger ().info (f"Done with result: { self .status_to_str (status )} " )
161192 if status == GoalStatus .STATUS_SUCCEEDED :
162- time .sleep (2 )
163193 self .execute_next_trajectory ()
164194 else :
165195 if result .error_code != FollowJointTrajectory .Result .SUCCESSFUL :
0 commit comments