Skip to content

Instantly share code, notes, and snippets.

@rethink-imcmahon
Last active August 29, 2015 14:24
Show Gist options
  • Save rethink-imcmahon/90e5ed37c47db85f1002 to your computer and use it in GitHub Desktop.
Save rethink-imcmahon/90e5ed37c47db85f1002 to your computer and use it in GitHub Desktop.
Baxter's Left and Right Arm Torque readings
#! /usr/bin/python
import rospy
import baxter_interface
import numpy as np
rospy.init_node("torque_tester")
baxter_interface.robot_enable.RobotEnable().enable()
l = baxter_interface.Limb("left")
r = baxter_interface.Limb("right")
print "Moving the left arm to a neutral pose..."
l.move_to_neutral()
print "Moving the right arm to a neutral pose..."
r.move_to_neutral()
print "Sleeping for 2.0 seconds to let the springs settle..."
rospy.sleep(2.0)
left_samples = list()
right_samples = list()
rate = rospy.Rate(100)
print "Grab torque samples for every joint on both arms at 100Hz for 5 seconds..."
for sample in range(1,500):
left_samples.append([v for k, v in sorted(l.joint_efforts().items())])
right_samples.append([v for k, v in sorted(r.joint_efforts().items())])
rate.sleep()
# average the readings
left_avg = np.mean(np.array(left_samples), axis=0, dtype=np.float64)
left_keys = [k for k, v in sorted(l.joint_efforts().items())]
print "Left arm effort: ", dict(zip(left_keys, left_avg))
right_avg = np.mean(np.array(right_samples), axis=0, dtype=np.float64)
right_keys = [k for k, v in sorted(r.joint_efforts().items())]
print "Right arm effort: ", dict(zip(right_keys, right_avg))
# determine the difference in torques between left and right arms
delta = left_avg - right_avg
print "Delta effort (left-right): ", dict(zip([s.partition('_')[-1] for s in left_keys], delta))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment