Joint Position Waypoint Example

Jump to: navigation , search

The example demonstrates basic joint position control. A joint position waypoint is a configuration of the arm in joint space (ie. simultaneous joint angles for the arm's seven degrees of freedom). In this example, we enable the robot moving the limb in zero-g mode. Interacting with the arm's navigator buttons, we can record a sequence of joint position waypoints. Upon completion of recording, we will continuously command the limb loop through the recorded joint sequence.


This example demonstrates the usage of the position controller for simple joint position moves. The main() function calls the record() method which records the waypoints as desired by the user. Then, the playback() method is invoked which demonstrates a smooth motion playback through the recorded joint positions.
Interfaces -

  • Limb.move_to_joint_positions()
  • Limb.set_joint_position_speed()
  • Limb.joint_angles()
  • Navigator.wheel()
  • Navigator.button_state()

If you would like to follow along with the actual source code for the example on GitHub, it can be found through this link for joint position waypoints example.


Verify that the robot is enabled from an SDK terminal session, ex:

$ rosrun intera_interface

Start the joint position waypoints example program, you can specify the joint position motion speed ratio -s or joint position accuracy(rad) -a on which we will run the example.

For example, run the example with 0.1 speed ratio and 0.1 accuracy:

$ rosrun intera_examples -s 0.1 -a 0.1

Moving the arm in zero-g mode, when we reach a joint position configuration we would like to record, press that navigator wheel.

You will then be prompted with instructions for recording joint position waypoints.

Press Navigator 'OK/Wheel' button to record a new joint joint position waypoint.
Press Navigator 'Rethink' button when finished recording waypoints to begin playback.

Moving the arm in zero-g mode, when we reach a joint position configuration we would like to record, press that navigator wheel.

You will get the feedback that the joint position waypoint has been recorded:

Waypoint Recorded

When done recording waypoints, pressing the navigator's 'Rethink' button will begin playback.

[INFO] [WallTime: 1399571721.540300] Waypoint Playback Started
  Press Ctrl-C to stop...

The program will begin looping through the recorded joint positions. When the previous joint position command is fully achieved (within the accuracy threshold), the next recorded joint position will be commanded.

Waypoint playback loop #1
Waypoint playback loop #2

Pressing Control-C at any time will stop playback and exit the example.


Important Arguments:

-s or --speed : The joint position motion speed ratio [0.0-1.0] (default:= 0.3)

-a or --accuracy : The threshold in Radians at which the current joint position command is considered successful before sending the next following joint position command. (default:= 0.008726646)

See the joint position waypoint's available arguments on the command line by passing the -h, help argument:

$ rosrun intera_examples -h
usage: [-h] [-s SPEED] [-a ACCURACY]

RSDK Joint Position Waypoints Example

    Records joint positions each time the navigator 'OK/wheel'
    button is pressed.
    Upon pressing the navigator 'Rethink' button, the recorded joint positions
    will begin playing back in a loop.

optional arguments:
  -h, --help            show this help message and exit
  -s SPEED, --speed SPEED
                        joint position motion speed ratio [0.0-1.0] (default:=
  -a ACCURACY, --accuracy ACCURACY
                        joint position accuracy (rad) at which waypoints must

Code Walkthrough

Now, let's break down the code.

33 import argparse
34 import sys
36 import rospy
38 import intera_interface

This imports the intera interface for accessing the limb and the gripper class.

41 class Waypoints(object):
42     def __init__(self, speed, accuracy, limb="right"):
43         # Create intera_interface limb instance
44         self._arm = limb
45         self._limb = intera_interface.Limb(self._arm)
47         # Parameters which will describe joint position moves
48         self._speed = speed
49         self._accuracy = accuracy
51         # Recorded waypoints
52         self._waypoints = list()
54         # Recording state
55         self._is_recording = False
57         # Verify robot is enabled
58         print("Getting robot state... ")
59         self._rs = intera_interface.RobotEnable()
60         self._init_state = self._rs.state().enabled
61         print("Enabling robot... ")
62         self._rs.enable()
64         # Create Navigator I/O
65         self._navigator_io = intera_interface.Navigator(self._arm)

An instance of the limb interface for the side under interest is created. An instance of the interface for the corresponding navigator, _navigator_io, is also created. The robot is then enabled. It is important to note that the robot should be enabled in order to control the limb's movement.

67     def _record_waypoint(self, value):
68         """
69         Stores joint position waypoints
71         Navigator 'OK/Wheel' button callback
72         """
73         if value != 'OFF':
74             print("Waypoint Recorded")
75             self._waypoints.append(self._limb.joint_angles())

The joint_angles() method retrieves the current joint angles and they are then appended to the _waypoints list.

77     def _stop_recording(self, value):
78         """
79         Sets is_recording to false
81         Navigator 'Rethink' button callback
82         """
83         # On navigator Rethink button press, stop recording
84         if value != 'OFF':
85             print("Recording Stopped")
86             self._is_recording = False

This Rethink button's press event is captured.

 88     def record(self):
 89         """
 90         Records joint position waypoints upon each Navigator 'OK/Wheel' button
 91         press.
 92         """
 93         rospy.loginfo("Waypoint Recording Started")
 94         print("Press Navigator 'OK/Wheel' button to record a new joint "
 95         "joint position waypoint.")
 96         print("Press Navigator 'Rethink' button when finished recording "
 97               "waypoints to begin playback")
 98         # Connect Navigator callbacks
 99         # Navigator scroll wheel button press
100         ok_id = self._navigator.register_callback(self._record_waypoint, 'right_button_ok')
101         # Navigator Rethink button press
102         show_id = self._navigator.register_callback(self._stop_recording, 'right_button_show')
104         # Set recording flag
105         self._is_recording = True
107         # Loop until waypoints are done being recorded ('Rethink' Button Press)
108         while not rospy.is_shutdown() and self._is_recording:
109             rospy.sleep(1.0)
111         # We are now done with the navigator callbacks, disconnecting them
112         self._navigator.deregister_callback(ok_id)
113         self._navigator.deregister_callback(show_id)

The navigator 'OK/Wheel' button invokes the _record_waypoint() method on a press event, which records the current joint positions as explained above. Similarly, the navigator 'Rethink' button invokes the _stop_recording method on a press event, which sets the is_recording variable to false.

115     def playback(self):
116         """
117         Loops playback of recorded joint position waypoints until program is
118         exited
119         """
120         rospy.sleep(1.0)
122         rospy.loginfo("Waypoint Playback Started")
123         print("  Press Ctrl-C to stop...")
125         # Set joint position speed ratio for execution
126         self._limb.set_joint_position_speed(self._speed)
128         # Loop until program is exited
129         loop = 0
130         while not rospy.is_shutdown():
131             loop += 1
132             print("Waypoint playback loop #%d " % (loop,))
133             for waypoint in self._waypoints:
134                 if rospy.is_shutdown():
135                     break
136                 self._limb.move_to_joint_positions(waypoint, timeout=20.0,
137                                                    threshold=self._accuracy)
138             # Sleep for a few seconds between playback loops
139             rospy.sleep(3.0)
141         # Set joint position speed back to default
142         self._limb.set_joint_position_speed(0.3)

The set_joint_position_speed() method sets the ratio of max joint speed to use during joint position moves. The method move_to_joint_positions(), moves the joints to the commanded position. It is important to note that there is not trajectory planning involved here. Instead, this is passed onto a low pass filter and the intermediate positions between the start and goal positions are obtained. They are then published as a joint command message using the set_joint_positions() method. Thus, all the waypoints that were stored are visited along a smooth trajectory.

144     def clean_shutdown(self):
145         print("\nExiting example...")
146         if not self._init_state:
147             print("Disabling robot...")
148             self._rs.disable()
149         return True

On shutdown, the robot is sent to its initial state that was captured.

152 def main():
153     """RSDK Joint Position Waypoints Example
155     Records joint positions each time the navigator 'OK/wheel'
156     button is pressed.
157     Upon pressing the navigator 'Rethink' button, the recorded joint positions
158     will begin playing back in a loop.
159     """
160     arg_fmt = argparse.RawDescriptionHelpFormatter
161     parser = argparse.ArgumentParser(formatter_class=arg_fmt,
162                                      description=main.__doc__)
163     parser.add_argument(
164         '-s', '--speed', default=0.3, type=float,
165         help='joint position motion speed ratio [0.0-1.0] (default:= 0.3)'
166     )
167     parser.add_argument(
168         '-a', '--accuracy',
169         default=intera_interface.settings.JOINT_ANGLE_TOLERANCE, type=float,
170         help='joint position accuracy (rad) at which waypoints must achieve'
171     )
172     args = parser.parse_args(rospy.myargv()[1:])

The speed and accuracy on which the example is to be demonstrated is captured from the command line arguments.

178     print("Initializing node... ")
179     rospy.init_node("rsdk_joint_position_waypoints")
181     waypoints = Waypoints(args.speed, args.accuracy)
183     # Register clean shutdown
184     rospy.on_shutdown(waypoints.clean_shutdown)
186     # Begin example program
187     waypoints.record()
188     waypoints.playback()
190 if __name__ == '__main__':
191     main()

The node is initialized and an instance of the Waypoints class is created. The user defined waypoints are recorded using the record() method and are played back using the playback() method as explained above.