def main(): rospy.init_node('exercise_4_3_client') rospy.wait_for_service('/move_bb8_in_circle_custom') service = rospy.ServiceProxy('/move_bb8_in_circle_custom', MyCustomServiceMessage) req = MyCustomServiceMessageRequest() req.duration = 5 service(req)
#! /usr/bin/env python import rospkg import rospy from my_custom_srv_msg_pkg.srv import MyCustomServiceMessage, MyCustomServiceMessageRequest rospy.init_node('service_move_bb8_in_circle_custom_client') # Initialise a ROS node with the name service_client rospy.wait_for_service('/move_bb8_in_circle_custom') # Wait for the service client /move_bb8_in_circle_custom to be running move_bb8_in_circle_service_client = rospy.ServiceProxy('/move_bb8_in_circle_custom', MyCustomServiceMessage) # Create the connection to the service move_bb8_in_circle_request_object = MyCustomServiceMessageRequest() # Create an object of type EmptyRequest """ # BB8CustomServiceMessage float64 side # The distance of each side of the circle int32 repetitions # The number of times BB-8 has to execute the circle movement when the service is called --- bool success # Did it achieve it? """ move_bb8_in_circle_request_object.duration = 4 rospy.loginfo("Doing Service Call...") result = move_bb8_in_circle_service_client(move_bb8_in_circle_request_object) # Send through the connection the path to the trajectory file to be executed rospy.loginfo(str(result)) # Print the result given by the service called rospy.loginfo("END of Service call...")
#! /usr/bin/env python import rospy import rospkg import sys from my_custom_srv_msg_pkg.srv import MyCustomServiceMessage, MyCustomServiceMessageRequest rospy.init_node('service_client') rospy.wait_for_service('/move_bb8_in_circle_custom') start_bb8_service = rospy.ServiceProxy('/move_bb8_in_circle_custom', MyCustomServiceMessage) start_bb8_object = MyCustomServiceMessageRequest() start_bb8_object.duration = 5 result = start_bb8_service(start_bb8_object) # Print the result given by the service called print result
#! /usr/bin/env python import rospy import sys from my_custom_srv_msg_pkg.srv import MyCustomServiceMessage, MyCustomServiceMessageRequest rospy.init_node('service_client') rospy.wait_for_service('/move_bb8_in_circle_custom') s = rospy.ServiceProxy('/move_bb8_in_circle_custom', MyCustomServiceMessage) s_object = MyCustomServiceMessageRequest() s_object.duration = 5.0 result = s(s_object) print result
#! /usr/bin/env python """ This node is launched by the call_bb8_move_custom_service_server.launch file. This node will start the /move_bb8_in_circle_custom service by passing a MyCustomServiceMessageRequest object into a /move_bb8_in_circle_custom proxy. """ import rospy from my_custom_srv_msg_pkg.srv import MyCustomServiceMessage, MyCustomServiceMessageRequest # initialise a ROS node with the name move_custom_circle rospy.init_node('move_custom_circle') # wait for the service client /move_bb8_in_circle_custom to be running rospy.wait_for_service('/move_bb8_in_circle_custom') # create the connection to the service move_circle_service = rospy.ServiceProxy('/move_bb8_in_circle_custom', MyCustomServiceMessage) # set variable with move custom circle request request_object = MyCustomServiceMessageRequest() # set custom circle request duration to 10 seconds request_object.duration = 10 # pass service the request object result = move_circle_service(request_object) # print the result given by the service called print(result)
import rospy from my_custom_srv_msg_pkg.srv import MyCustomServiceMessage, MyCustomServiceMessageRequest rospy.init_node('my_service_class_node_client') rospy.wait_for_service('/move_bb8_in_circle') my_service_object = rospy.ServiceProxy('/move_bb8_in_circle', MyCustomServiceMessage) my_request_object = MyCustomServiceMessageRequest() my_request_object.duration = 4 my_service_object(my_request_object)
#!/usr/bin/env python import rospy from my_custom_srv_msg_pkg.srv import MyCustomServiceMessage, MyCustomServiceMessageRequest rospy.init_node('call_my_server') rospy.wait_for_service('/move_bb8_in_circle_custom') my_connector=rospy.ServiceProxy('/move_bb8_in_circle_custom', MyCustomServiceMessage) my_duration=MyCustomServiceMessageRequest() my_duration.duration=10 ITyped=my_connector(my_duration) print(ITyped)