@@ -42,8 +42,8 @@ def reset_cb(self, req):
42
42
return TriggerResponse (
43
43
success = True ,
44
44
message = "Succesfully reset joint states"
45
- )
46
-
45
+ )
46
+
47
47
def fjta_cb (self , goal ):
48
48
joint_names = copy .deepcopy (self .joint_names )
49
49
joint_names .sort ()
@@ -62,16 +62,21 @@ def fjta_cb(self, goal):
62
62
# This is used to compute the interpolation weight as a function of current and goal time point
63
63
time_since_start_of_previous_point = rospy .Duration (0 )
64
64
65
+ nr_points_dof = len (self .joint_names )
66
+
65
67
# for all points in the desired trajectory
66
68
for point in goal_sorted .trajectory .points :
67
69
70
+ if len (point .positions ) != nr_points_dof :
71
+ self .as_fjta .set_aborted ()
72
+ return
73
+
68
74
# we need to resort the positions array because moveit sorts alphabetically but all other ROS components sort in the URDF order
69
75
positions_sorted = []
70
76
for joint_name in self .joint_names :
71
77
idx = goal .trajectory .joint_names .index (joint_name )
72
78
positions_sorted .append (point .positions [idx ])
73
79
point .positions = positions_sorted
74
- pos_length = len (point .positions )
75
80
76
81
joint_states_prev = copy .deepcopy (self .joint_states )
77
82
@@ -88,8 +93,8 @@ def fjta_cb(self, goal):
88
93
t1 = point .time_from_start - time_since_start_of_previous_point
89
94
# compute velocity as the fraction of distance from prev point to next point in trajectory
90
95
# and the corresponding time t1
91
- velocities = [0 ] * pos_length
92
- for i in range (pos_length ):
96
+ velocities = [0 ] * nr_points_dof
97
+ for i in range (nr_points_dof ):
93
98
if t1 .to_sec () != 0.0 :
94
99
velocities [i ] = (point .positions [i ] - joint_states_prev .position [i ]) / float (t1 .to_sec ())
95
100
else :
@@ -113,8 +118,8 @@ def fjta_cb(self, goal):
113
118
alpha = 0.0
114
119
115
120
# interpolate linearly (lerp) each component
116
- interpolated_positions = [0 ] * pos_length
117
- for i in range (pos_length ):
121
+ interpolated_positions = [0 ] * nr_points_dof
122
+ for i in range (nr_points_dof ):
118
123
interpolated_positions [i ] = (1.0 - alpha ) * joint_states_prev .position [i ] + alpha * point .positions [i ]
119
124
self .joint_states .position = interpolated_positions
120
125
@@ -128,11 +133,11 @@ def fjta_cb(self, goal):
128
133
self .joint_states .position = point .positions
129
134
# set lower time bound for the next point
130
135
time_since_start_of_previous_point = latest_time_from_start
131
-
136
+
132
137
# set joint velocities to zero after the robot stopped moving (reaching final point of trajectory)
133
- self .joint_states .velocity = [0.0 ] * len ( self . joint_states . velocity )
134
- self .joint_states .effort = [0.0 ] * len ( self . joint_states . effort )
135
-
138
+ self .joint_states .velocity = [0.0 ] * nr_points_dof
139
+ self .joint_states .effort = [0.0 ] * nr_points_dof
140
+
136
141
self .as_fjta .set_succeeded (FollowJointTrajectoryResult ())
137
142
else :
138
143
rospy .logerr ("received unexpected joint names in goal" )
0 commit comments