API review

Proposer: KenConley

Present at review:

API updated per #503

API to be Reviewed

See Client API

API Examples:

A canonical rospy publisher:

   1 PKG = 'rospy_demo'
   2 NAME = 'talker'
   3 import rostools; rostools.update_path(PKG)
   4 
   5 import sys
   6 import time
   7 import rospy
   8 from std_msgs.msg import String
   9 
  10 def talker():
  11     pub = rospy.advertise_topic("chatter", String)
  12     rospy.init_node(NAME, anonymous=True)
  13     count = 0
  14     while not rospy.is_shutdown():
  15         pub.publish(String("hello world %d"%count))
  16         count += 1
  17         time.sleep(0.01)
  18         
  19 if __name__ == '__main__':
  20     try:
  21         talker()
  22     except KeyboardInterrupt, e:
  23         pass
  24     print "exiting"

A canonical rospy listener:

   1 PKG = 'rospy_demo'
   2 NAME = 'listener'
   3 import rostools; rostools.update_path(PKG)
   4 
   5 import sys
   6 import rospy
   7 from std_msgs.msg import String
   8 
   9 def callback(data):
  10     print rospy.get_caller_id(), "I heard %s"%data.data
  11     
  12 def listener():
  13     rospy.init_node(NAME)
  14     rospy.subscribe_topic("chatter", String, callback)
  15     rospy.spin()
  16         
  17 if __name__ == '__main__':
  18     listener()

A canonical rospy service

   1 PKG = 'rospy_tutorials'
   2 NAME = 'add_two_ints_server'
   3 import rostools; rostools.update_path(PKG)
   4 
   5 
   6 from rospy_tutorials.srv import *
   7 import rospy 
   8 
   9 def add_two_ints(req):
  10     return AddTwoIntsResponse(req.a + req.b)
  11 
  12 def add_two_ints_server():
  13     rospy.init_node(NAME)
  14     s = rospy.advertise_service('add_two_ints', AddTwoInts, add_two_ints)
  15     rospy.spin()
  16 
  17 if __name__ == "__main__":
  18     add_two_ints_server()

A canonical rospy service client:

   1 PKG = 'rospy_tutorials'
   2 import rostools; rostools.update_path(PKG)
   3 
   4 import sys
   5 import os
   6 import rospy
   7 from rospy_tutorials.srv import *
   8 
   9 def add_two_ints_client(x, y):
  10     rospy.wait_for_service('add_two_ints')
  11     try:
  12         add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts)
  13         # simplified style
  14         resp1 = add_two_ints(x, y)
  15         # formal style
  16         resp2 = add_two_ints.call(AddTwoIntsRequest(x, y))
  17         return resp1.sum
  18     except rospy.ServiceException, e:
  19         print "Service call failed: %s"%e
  20 
  21 if __name__ == "__main__":
  22     add_two_ints_client(random.randint(-50000, 50000), random.randint(-50000, Conclusion))

Question / concerns / comments

Enter your thoughts on the API and any questions / concerns you have here. Please sign your name. Anything you want to address in the API review should be marked down here before the start of the meeting.

Meeting agenda

To be filled out by proposer based on comments gathered during API review period

Conclusion

Package status change: Conditional Pass, pending these changes:

  • /!\ TopicPub -> Publisher, etc..

  • /!\ fix documentation on is_shutdown, get_caller_id

  • /!\ undo advertise_topic

  • /!\ Future: do a joint design on rospy and roscpp peer API to bring greater unification between the two. The roscpp node API is in effect a deprecated API so the unification effort should be based on future API designs. There has been good cross-pollination between the two, but the divergence between the two APIs makes communicating about ROS code more difficult.


Wiki: rospy/Reviews/2008-09-23_API_Review_Part_2 (last edited 2009-08-14 20:51:28 by localhost)