Skip to content

Class 3: Custom python program using uber controller

Caris Moses edited this page Feb 28, 2017 · 4 revisions

Class 2 recap:

  • How did using the robot go? Any problems? Did people accomplish these tasks? Why or why not?
  1. How to use RVIZ
  2. How to launch Kinect
  3. How to launch telop keyboard
  4. Recording a video

Class three: Custom python program using uber controller

  • assignment
  • sensors
  • echo.py
  • guided tutorial for making a rospy subscriber

Last week you used open-loop control to program the robot. The robot implemented actions based on a predetermined program.

This week you are going to create a reactive controller: __ based on some sensory input, the robot should take some action __

The lis_pr2_pkg has an interface for using the gripper_sensor_action package. Write a program using the interface or try to make your own using a rospy subscriber.

Available Sensors

  • kinect point cloud
  • any camera stream
  • gripper_sensor action package
    • wrist accelerometer
    • finger pad sensors
  • raw accelerometer data
  • raw force pad data

Echo.py -- look at and explain

Guided tutorial -- rospy subscriber for /accelerometer/l_gripper_motor

See lis_pr2_pkg/scripts/acceldemo.py for an example of using information from a topic in a python node

Sanity check: Look at the topic you want to use to make sure the values makes sense.

For this demo check the current values being output by the left gripper accelerometer topic by running rostopic echo /accelerometer/l_gripper_motor

In a new python file:

  1. import rospy

  2. import the relevant message type

    To get the relevant message type run rostopic info topic_name

    For this demo: To subscribe to messages on the accelerometer/l_gripper_motor topic run rostopic info accelerometer/l_gripper_motor and see that the message type is AccelerometerState, therefore we add from pr2_msgs.msg import AccelerometerState to the file

  3. rospy.init_node("node_name")

  4. Make a class with a subscriber member and a callback method

    The class and subscriber for this demo:

    class Accel():
       def __init__(self):
           self.sub= rospy.Subscriber("accelerometer/l_gripper_motor", AS, self.cb, queue_size=1)'`

    In callback put code that you want to run whenever a message is published to your topic.

    For this demo:

    def cb (self, data):
        self.sub.unregister()
        #pdb.set_trace()
        points = []
        for sample in data.samples:
            pt = sample.x, sample.y, sample.z
            points.append(pt)
    
        print points
        raw_input("next")
        self.sub= rospy.Subscriber("accelerometer/l_gripper_motor", AS, self.cb, queue_size=1)
  5. Start the node

    ac = Accel()
    rospy.spin()

** See ROS Tutorial (only Section 2 is relevant) for more guidance on writing a subscriber node in ROS

Debugging:

  1. import pdb
  2. by putting self.sub.unregister() in the first line of the callback, the callback will only run once for the first message published on the topic
  3. pdb.set_trace() to start the python debugger

Suggested programs:

  • robot starts with arm in front, if you bump the wrist it moves the arm to a new position
  • robot starts with hand open, once you place object in its hand it closes it (gently)
  • robot starts dancing whenever it sees a large amount of red and stops when it sees blue
  • visual servoing! robots head tracks a colored blob

Open ended assignment

Gripper sensor action provides a suite for detecting if an object slipped and has a grasping action to prevent it. It also provides information about different events - finding contact, force being applied, accelerometer toggled.

The gripper sensor action suite subscribes to 2 topics for sensory input: /pressure/r_gripper_motor /accelerometer/r_gripper_motor

Your task is to write a simple subscriber to learn more about the sensor day. Try to create your own event detector and use it in a reactive program.