## page was renamed from rospy/2008-09-23 API Review Part 2 ## page was renamed from rospy/2008-09-23 API Review Part 2 API Review = API review = Proposer: '''KenConley''' Present at review: *TullyFoote *JeremyLeibs *EricBerger *BrianGerkey *RobWheeler API updated per [[https://prdev.willowgarage.com/trac/ros/ticket/503|#503]] == API to be Reviewed == See [[http://pr.willowgarage.com/pr-docs/ros-packages/rospy/html/group__clientapi.html|Client API]] API Examples: A canonical rospy publisher: {{{#!python PKG = 'rospy_demo' NAME = 'talker' import rostools; rostools.update_path(PKG) import sys import time import rospy from std_msgs.msg import String def talker(): pub = rospy.advertise_topic("chatter", String) rospy.init_node(NAME, anonymous=True) count = 0 while not rospy.is_shutdown(): pub.publish(String("hello world %d"%count)) count += 1 time.sleep(0.01) if __name__ == '__main__': try: talker() except KeyboardInterrupt, e: pass print "exiting" }}} A canonical rospy listener: {{{#!python PKG = 'rospy_demo' NAME = 'listener' import rostools; rostools.update_path(PKG) import sys import rospy from std_msgs.msg import String def callback(data): print rospy.get_caller_id(), "I heard %s"%data.data def listener(): rospy.init_node(NAME) rospy.subscribe_topic("chatter", String, callback) rospy.spin() if __name__ == '__main__': listener() }}} A canonical rospy service {{{#!python PKG = 'rospy_tutorials' NAME = 'add_two_ints_server' import rostools; rostools.update_path(PKG) from rospy_tutorials.srv import * import rospy def add_two_ints(req): return AddTwoIntsResponse(req.a + req.b) def add_two_ints_server(): rospy.init_node(NAME) s = rospy.advertise_service('add_two_ints', AddTwoInts, add_two_ints) rospy.spin() if __name__ == "__main__": add_two_ints_server() }}} A canonical rospy service client: {{{#!python PKG = 'rospy_tutorials' import rostools; rostools.update_path(PKG) import sys import os import rospy from rospy_tutorials.srv import * def add_two_ints_client(x, y): rospy.wait_for_service('add_two_ints') try: add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts) # simplified style resp1 = add_two_ints(x, y) # formal style resp2 = add_two_ints.call(AddTwoIntsRequest(x, y)) return resp1.sum except rospy.ServiceException, e: print "Service call failed: %s"%e if __name__ == "__main__": 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. ---- ## PackageReviewCategory