Skip to content

Commit b82e794

Browse files
authored
Merge pull request #244 from lindemeier/bugfix/length-bug
[melodic] bugfix/length-bug
2 parents 6ceb293 + e4e8bd9 commit b82e794

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

cob_hardware_emulation/scripts/emulation_follow_joint_trajectory.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def reset_cb(self, req):
4242
return TriggerResponse(
4343
success = True,
4444
message = "Succesfully reset joint states"
45-
)
46-
45+
)
46+
4747
def fjta_cb(self, goal):
4848
joint_names = copy.deepcopy(self.joint_names)
4949
joint_names.sort()
@@ -62,16 +62,21 @@ def fjta_cb(self, goal):
6262
# This is used to compute the interpolation weight as a function of current and goal time point
6363
time_since_start_of_previous_point = rospy.Duration(0)
6464

65+
nr_points_dof = len(self.joint_names)
66+
6567
# for all points in the desired trajectory
6668
for point in goal_sorted.trajectory.points:
6769

70+
if len(point.positions) != nr_points_dof:
71+
self.as_fjta.set_aborted()
72+
return
73+
6874
# we need to resort the positions array because moveit sorts alphabetically but all other ROS components sort in the URDF order
6975
positions_sorted = []
7076
for joint_name in self.joint_names:
7177
idx = goal.trajectory.joint_names.index(joint_name)
7278
positions_sorted.append(point.positions[idx])
7379
point.positions = positions_sorted
74-
pos_length = len(point.positions)
7580

7681
joint_states_prev = copy.deepcopy(self.joint_states)
7782

@@ -88,8 +93,8 @@ def fjta_cb(self, goal):
8893
t1 = point.time_from_start - time_since_start_of_previous_point
8994
# compute velocity as the fraction of distance from prev point to next point in trajectory
9095
# 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):
9398
if t1.to_sec() != 0.0:
9499
velocities[i] = (point.positions[i] - joint_states_prev.position[i]) / float(t1.to_sec())
95100
else:
@@ -113,8 +118,8 @@ def fjta_cb(self, goal):
113118
alpha = 0.0
114119

115120
# 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):
118123
interpolated_positions[i] = (1.0 - alpha) * joint_states_prev.position[i] + alpha * point.positions[i]
119124
self.joint_states.position = interpolated_positions
120125

@@ -128,11 +133,11 @@ def fjta_cb(self, goal):
128133
self.joint_states.position = point.positions
129134
# set lower time bound for the next point
130135
time_since_start_of_previous_point = latest_time_from_start
131-
136+
132137
# 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+
136141
self.as_fjta.set_succeeded(FollowJointTrajectoryResult())
137142
else:
138143
rospy.logerr("received unexpected joint names in goal")

0 commit comments

Comments
 (0)