Пример #1
0
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)
Пример #2
0
def main():
    rospy.init_node("call_move_square_custom_node")
    #waiting
    rospy.wait_for_service("/move_bb8_in_square_custom")

    try:
        rospy.loginfo("Executing client...")

        #open the service client
        moving_robot = rospy.ServiceProxy('/move_bb8_in_square_custom',
                                          MyCustomServiceMessage)

        #pack the request actions in the object
        actions = MyCustomServiceMessageRequest()
        actions.radius = 2.0
        actions.repetitions = 2

        #send the actions to the server
        result = moving_robot(actions)

        if result:
            rospy.loginfo("The mission is completed!")

        #pack the request actions in the object
        actions2 = MyCustomServiceMessageRequest()
        actions2.radius = 3.0
        actions2.repetitions = 1

        #send the actions to the server
        result2 = moving_robot(actions2)

        if result2:
            rospy.loginfo("The mission is completed!")

    except:
        rospy.loginfo("An error occured in client")
Пример #3
0
#! /usr/bin/env python

import rospy

from my_custom_srv_msg_pkg.srv import MyCustomServiceMessage, MyCustomServiceMessageRequest  # you import the service message python classes generated from Empty.srv.
import sys

# Initialise a ROS node with the name service_client
rospy.init_node('bb8_move_in_circle_service_client_custom')

rospy.wait_for_service('/move_bb8_in_circle_custom')

bb8_service = rospy.ServiceProxy('/move_bb8_in_circle_custom',
                                 MyCustomServiceMessage)

bb8_object = MyCustomServiceMessageRequest()

result = bb8_service(10)
print result
Пример #4
0
#! /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...")
Пример #5
0
#! /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
import rospkg
import rospy
from my_custom_srv_msg_pkg.srv import MyCustomServiceMessage, MyCustomServiceMessageRequest

# Initialise a ROS node with the name service_move_bb8_in_circle_client
rospy.init_node('service_move_bb8_in_circle_custom_client')
# Wait for the service client /move_bb8_in_circle to be running
rospy.wait_for_service('/move_bb8_in_circle_custom')
# Create the connection to the service
move_bb8_in_circle_service_client = rospy.ServiceProxy(
    '/move_bb8_in_circle_custom', MyCustomServiceMessage)
# Create an object of type EmptyRequest
move_bb8_in_circle_request_object = MyCustomServiceMessageRequest()
#Duration for which you would like to execute the service
move_bb8_in_circle_request_object.duration = 10
# Call the service by sending the request object to the server
result = move_bb8_in_circle_service_client(move_bb8_in_circle_request_object)
# Print the result given by the service called
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)
Пример #9
0
#! /usr/bin/env python

import rospy
from my_custom_srv_msg_pkg.srv import MyCustomServiceMessage, MyCustomServiceMessageRequest

rospy.init_node('start_bb8_square_move')
print("Waiting for /bb8service to start")
rospy.wait_for_service('/move_bb8_in_square_custom')

req = MyCustomServiceMessageRequest()
req.radius = 0.1
req.repetitions = 2
bb8_move_custom_square_service = rospy.ServiceProxy('/move_bb8_in_square_custom', MyCustomServiceMessage)
print("Requesting BB8 move in custom square")
result1 = bb8_move_custom_square_service(req)
req.radius = 0.3
req.repetitions = 1
result2 = bb8_move_custom_square_service(req)
if result1.success ==  False or result2.success == False:
  print("Move failed")
else:
  print("Successfully completed the move")

#!/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)