-
Notifications
You must be signed in to change notification settings - Fork 2
Class 3: Custom python program using uber controller
- How did using the robot go? Any problems? Did people accomplish these tasks? Why or why not?
- How to use RVIZ
- How to launch Kinect
- How to launch telop keyboard
- 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.
- kinect point cloud
- any camera stream
- gripper_sensor action package
- wrist accelerometer
- finger pad sensors
- raw accelerometer data
- raw force pad data
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:
-
import rospy
-
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 runrostopic info accelerometer/l_gripper_motor
and see that the message type is AccelerometerState, therefore we addfrom pr2_msgs.msg import AccelerometerState
to the file -
rospy.init_node("node_name")
-
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)
-
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:
import pdb
- 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 -
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
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.