Skip to content

Commit 3acdb7a

Browse files
Updates Limb.py for Joint Trajectory Mode
Updates the Limb interface to utilize the new TRAJECTORY_MODE in intera_core_msgs. This new mode is a reworked RAW_POSITION_MODE but requires Position, Velocity, and Acceleration commands to execute a Trajectory. The other modes (Position, Velocity, Torque) now require commands to be populated in their respective fields within the JointCommand msg. Additionally, slight optimization in the JTAS to execute commands strictly in the mode commanded. Depends on RethinkRobotics/intera_common#7
1 parent 6600bad commit 3acdb7a

File tree

2 files changed

+53
-27
lines changed

2 files changed

+53
-27
lines changed

intera_interface/src/intera_interface/limb.py

+32-8
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,31 @@ def set_joint_position_speed(self, speed):
336336
"""
337337
self._pub_speed_ratio.publish(Float64(speed))
338338

339-
def set_joint_positions(self, positions, raw=False):
339+
def set_joint_trajectory(self, names, positions, velocities, accelerations):
340+
"""
341+
Commands the joints of this limb to the specified positions.
342+
343+
B{IMPORTANT:} 'raw' joint position control mode allows for commanding
344+
joint positions, without modification, directly to the JCBs
345+
(Joint Controller Boards). While this results in more unaffected
346+
motions, 'raw' joint position control mode bypasses the safety system
347+
modifications (e.g. collision avoidance).
348+
Please use with caution.
349+
350+
@type positions: dict({str:float})
351+
@param positions: joint_name:angle command
352+
@type raw: bool
353+
@param raw: advanced, direct position control mode
354+
"""
355+
self._command_msg.names = names
356+
self._command_msg.position = positions
357+
self._command_msg.velocity = velocities
358+
self._command_msg.acceleration = accelerations
359+
self._command_msg.mode = JointCommand.TRAJECTORY_MODE
360+
self._command_msg.header.stamp = rospy.Time.now()
361+
self._pub_joint_cmd.publish(self._command_msg)
362+
363+
def set_joint_positions(self, positions):
340364
"""
341365
Commands the joints of this limb to the specified positions.
342366
@@ -353,11 +377,9 @@ def set_joint_positions(self, positions, raw=False):
353377
@param raw: advanced, direct position control mode
354378
"""
355379
self._command_msg.names = positions.keys()
356-
self._command_msg.command = positions.values()
357-
if raw:
358-
self._command_msg.mode = JointCommand.RAW_POSITION_MODE
359-
else:
360-
self._command_msg.mode = JointCommand.POSITION_MODE
380+
self._command_msg.position = positions.values()
381+
self._command_msg.mode = JointCommand.POSITION_MODE
382+
self._command_msg.header.stamp = rospy.Time.now()
361383
self._pub_joint_cmd.publish(self._command_msg)
362384

363385
def set_joint_velocities(self, velocities):
@@ -373,8 +395,9 @@ def set_joint_velocities(self, velocities):
373395
@param velocities: joint_name:velocity command
374396
"""
375397
self._command_msg.names = velocities.keys()
376-
self._command_msg.command = velocities.values()
398+
self._command_msg.velocity = velocities.values()
377399
self._command_msg.mode = JointCommand.VELOCITY_MODE
400+
self._command_msg.header.stamp = rospy.Time.now()
378401
self._pub_joint_cmd.publish(self._command_msg)
379402

380403
def set_joint_torques(self, torques):
@@ -390,8 +413,9 @@ def set_joint_torques(self, torques):
390413
@param torques: joint_name:torque command
391414
"""
392415
self._command_msg.names = torques.keys()
393-
self._command_msg.command = torques.values()
416+
self._command_msg.effort = torques.values()
394417
self._command_msg.mode = JointCommand.TORQUE_MODE
418+
self._command_msg.header.stamp = rospy.Time.now()
395419
self._pub_joint_cmd.publish(self._command_msg)
396420

397421
def move_to_neutral(self, timeout=15.0):

intera_interface/src/joint_trajectory_action/joint_trajectory_action.py

+21-19
Original file line numberDiff line numberDiff line change
@@ -237,22 +237,25 @@ def _command_stop(self, joint_names, joint_angles, start_time, dimensions_dict):
237237
break
238238
rospy.sleep(1.0 / self._control_rate)
239239
elif self._mode == 'position' or self._mode == 'position_w_id':
240-
raw_pos_mode = (self._mode == 'position_w_id')
241-
if raw_pos_mode:
242-
pnt = JointTrajectoryPoint()
243-
pnt.positions = self._get_current_position(joint_names)
240+
pnt = JointTrajectoryPoint()
241+
pnt.positions = self._get_current_position(joint_names)
242+
if self._mode == 'position_w_id':
244243
if dimensions_dict['velocities']:
245244
pnt.velocities = [0.0] * len(joint_names)
246245
if dimensions_dict['accelerations']:
247246
pnt.accelerations = [0.0] * len(joint_names)
247+
ff_pnt = self._reorder_joints_ff_cmd(joint_names, pnt)
248248
while (not self._server.is_new_goal_available() and self._alive
249249
and self.robot_is_enabled()):
250-
self._limb.set_joint_positions(joint_angles, raw=raw_pos_mode)
251250
# zero inverse dynamics feedforward command
252-
if self._mode == 'position_w_id':
253-
pnt.time_from_start = rospy.Duration(rospy.get_time() - start_time)
254-
ff_pnt = self._reorder_joints_ff_cmd(joint_names, pnt)
255-
self._pub_ff_cmd.publish(ff_pnt)
251+
if self._mode == 'position' and self._alive:
252+
self._limb.set_joint_positions(dict(zip(joint_names, point.positions)))
253+
if self._mode == 'position_w_id' and self._alive:
254+
self._limb.set_joint_trajectory(joint_names,
255+
ff_pnt.positions,
256+
ff_pnt.velocities,
257+
ff_pnt.accelerations)
258+
256259
if self._cuff_state:
257260
self._limb.exit_control_mode()
258261
break
@@ -277,17 +280,16 @@ def _command_joints(self, joint_names, point, start_time, dimensions_dict):
277280
return False
278281
if self._mode == 'velocity':
279282
velocities.append(self._pid[delta[0]].compute_output(delta[1]))
280-
if ((self._mode == 'position' or self._mode == 'position_w_id')
281-
and self._alive):
282-
cmd = dict(zip(joint_names, point.positions))
283-
raw_pos_mode = (self._mode == 'position_w_id')
284-
self._limb.set_joint_positions(cmd, raw=raw_pos_mode)
285-
if raw_pos_mode:
286-
ff_pnt = self._reorder_joints_ff_cmd(joint_names, point)
287-
self._pub_ff_cmd.publish(ff_pnt)
283+
284+
if self._mode == 'position' and self._alive:
285+
self._limb.set_joint_positions(dict(zip(joint_names, point.positions)))
286+
if self._mode == 'position_w_id' and self._alive:
287+
self._limb.set_joint_trajectory(joint_names,
288+
point.positions,
289+
point.velocities,
290+
point.accelerations)
288291
elif self._alive:
289-
cmd = dict(zip(joint_names, velocities))
290-
self._limb.set_joint_velocities(cmd)
292+
self._limb.set_joint_velocities(dict(zip(joint_names, velocities)))
291293
return True
292294

293295
def _get_bezier_point(self, b_matrix, idx, t, cmd_time, dimensions_dict):

0 commit comments

Comments
 (0)