Joint Position Recorder - Code Walkthrough

From sdk-wiki
Jump to: navigation, search


This example demonstrates the usage of the Joint Recorder interface to record the joint positions traversed by the robot. It records the timestamped joint and gripper positions to a file.
Interface - JointRecorder.record()

Code Walkthrough

Now, let's break down the code.

  1. import argparse
  3. import rospy
  5. import baxter_interface
  6. from baxter_examples import JointRecorder
  8. from baxter_interface import CHECK_VERSION

This imports the baxter interface for accessing the limb and the gripper class. The baxter_interface is imported to use its JointRecorder class. The CHECK_VERSION is imported to check if the software running on the robot would be compatible with this local version. It is not necessary to check the version in custom programs.

  1. def main():
  2.     """RSDK Joint Recorder Example
  4.    Record timestamped joint and gripper positions to a file for
  5.    later play back.
  7.    Run this example while moving the robot's arms and grippers
  8.    to record a time series of joint and gripper positions to a
  9.    new csv file with the provided *filename*. This example can
  10.    be run in parallel with any other example or standalone
  11.    (moving the arms in zero-g mode while pressing the cuff
  12.    buttons to open/close grippers).
  14.    You can later play the movements back using one of the
  15.    *_file_playback examples.
  16.    """
  17.     epilog = """
  18. Related examples:
  20.    """
  21.     arg_fmt = argparse.RawDescriptionHelpFormatter
  22.     parser = argparse.ArgumentParser(formatter_class=arg_fmt,
  23.                                      description=main.__doc__,
  24.                                      epilog=epilog)
  25.     required = parser.add_argument_group('required arguments')
  26.     required.add_argument(
  27.         '-f', '--file', dest='filename', required=True,
  28.         help='the file name to record to'
  29.     )
  30.     parser.add_argument(
  31.         '-r', '--record-rate', type=int, default=100, metavar='RECORDRATE',
  32.         help='rate at which to record (default: 100)'
  33.     )
  34.     args = parser.parse_args(rospy.myargv()[1:])

The destination file to store the joint positions along with its path is captured by the parser. The rate at which the positions are to be captured and stored is also captured.

  1.     print("Initializing node... ")
  2.     rospy.init_node("rsdk_joint_recorder")
  3.     print("Getting robot state... ")
  4.     rs = baxter_interface.RobotEnable(CHECK_VERSION)
  5.     print("Enabling robot... ")
  6.     rs.enable()
  8.     recorder = JointRecorder(args.filename, args.record_rate)
  9.     rospy.on_shutdown(recorder.stop)
  11.     print("Recording. Press Ctrl-C to stop.")
  12.     recorder.record()
  14.     print("\nDone.")
  16. if __name__ == '__main__':
  17.     main()

The node is initialized and the robot is enabled. The record() method captures the joint and gripper positions at a specified rate and stores them to the destination file.