string_slow_node.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 from __future__ import absolute_import
3 
4 import sys
5 
6 """
7  A very simple echo ROS node, with delay.
8  - echo from topic to echo_topic
9  - echo service
10 """
11 import functools
12 
13 import common
14 import rospy
15 import std_msgs.msg as std_msgs
16 import std_srvs.srv as std_srvs
17 
18 # TODO : get rid of this somehow ( dynamic generation or integration of more basic services in ROS )
19 from pyros_test.srv import StringEchoService
20 
21 def service_callback(data):
22  # extract data
23  print "==> sleeping {delay} seconds ".format(delay=30)
24  rospy.rostime.wallsleep(30)
25  print "==> finally replying to {d} ".format(d=data)
26  return "response"
27  # TODO : generic way to forward any msgtype safely
28 
29 if __name__ == '__main__':
30  try:
31  args = rospy.myargv(argv=sys.argv)
32  node_name = args[1] if len(args) > 1 else 'string_slow_node'
33 
34  rospy.init_node(node_name)
35  rospy.loginfo('String Slow node started. [' + rospy.get_name() + ']')
36 
37  slow_service_name = rospy.get_param("~slow_service_name", "slow_service")
38  print 'Parameter {0!s} has value {1!s}'.format(rospy.resolve_name('~slow_service_name'), slow_service_name)
39  if slow_service_name == "":
40  print "{0} parameter not found".format(rospy.resolve_name('~slow_service_name'))
42 
43  srv = rospy.Service(slow_service_name, StringEchoService, service_callback)
44 
45  rospy.spin()
46 
47  except rospy.ROSInterruptException:
48  pass
49 
50 # TO RUN :
51 # roscore &
52 # rosrun pyros string_echo_node.py
def service_callback(data)


pyros_test
Author(s): AlexV
autogenerated on Mon Jun 10 2019 14:20:23