示例#1
0
#! /usr/bin/env python

import rospy
import rospkg
from iri_wam_reproduce_trajectory.srv import ExecTraj, ExecTrajRequest
import sys

rospy.init_node('service_client')
rospy.wait_for_service('/execute_trajectory')

exec_traj_service = rospy.ServiceProxy('/execute_trajectory', ExecTraj)
exec_traj_object = ExecTrajRequest()

rospack = rospkg.RosPack()
traj_path = rospack.get_path('iri_wam_reproduce_trajectory') + "/config/get_food.txt"
exec_traj_object.file = traj_path

result = exec_traj_service(exec_traj_object)
# Print the result given by the service called
print result
示例#2
0
 
</launch>
# -----------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------
# Dans le dossier src
# DANS excercice_4_1.py
# -------------------------------------------------
#! /usr/bin/env python
import rospkg
import rospy
from iri_wam_reproduce_trajectory.srv import ExecTraj, ExecTrajRequest # Import the service message used by the service /execute_trajectory

rospy.init_node('service_execute_trajectory_client') # Initialise a ROS node with the name service_client
rospy.wait_for_service('/execute_trajectory') # Wait for the service client /execute_trajectory to be running
execute_trajectory_service_client = rospy.ServiceProxy('/execute_trajectory', ExecTraj) # Create the connection to the service
execute_trajectory_request_object = ExecTrajRequest() # Create an object of type ExecTrajRequest

"""
user:~/catkin_ws$ rossrv show iri_wam_reproduce_trajectory/ExecTraj
string file
---
"""
rospack = rospkg.RosPack()
# This rospack.get_path() works in the same way as $(find name_of_package) in the launch files.
trajectory_file_path = rospack.get_path('iri_wam_reproduce_trajectory') + "/config/get_food.txt"
execute_trajectory_request_object.file = trajectory_file_path # Fill the variable file of this object with the desired file path
result = execute_trajectory_service_client(execute_trajectory_request_object) # Send through the connection the path to the trajectory file to be executed
print result # Print the result type ExecTrajResponse
# -----------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------
示例#3
0
#! /usr/bin/env python

import rospy
import rospkg
from iri_wam_reproduce_trajectory.srv import ExecTraj, ExecTrajRequest

rospack = rospkg.RosPack()
rospy.init_node('manipulator_control')
rospy.wait_for_service('/execute_trajectory')

srv_proxy = rospy.ServiceProxy('/execute_trajectory', ExecTraj)
traj = ExecTrajRequest()
def get_path(pos):
    return rospack.get_path('iri_wam_reproduce_trajectory')+'/config/' + pos + '.txt'
traj.file = get_path('get_food')
# print traj
print "Getting Food"
res = srv_proxy(traj)
print "Releasing Food"
traj.file = get_path('release_food')
res = srv_proxy(traj)
示例#4
0
#! /usr/bin/env python

# Import Needed Packages
import rospy
import rospkg
from iri_wam_reproduce_trajectory.srv import ExecTraj, ExecTrajRequest

# Init ROS Node
rospy.init_node('service_execute_trajectory_client')

# Wait For Service And Connect To Client
rospy.wait_for_service('/execute_trajectory')
execute_trajectory_service_client = rospy.ServiceProxy('/execute_trajectory',
                                                       ExecTraj)

# Instantiate ExecTraj Object
execute_trajectory_request_object = ExecTrajRequest()

# Instantiate ROSPack Object, Define Trajectory Filepath
rospack = rospkg.RosPack()
trajectory_file_path = rospack.get_path(
    'iri_wam_reproduce_trajectory') + "/config/get_food.txt"

# Define Request File
execute_trajectory_request_object.file = trajectory_file_path
result = execute_trajectory_service_client(execute_trajectory_request_object)

print result
示例#5
0
#! /usr/bin/env python

import rospy
from std_msgs.msg import String
import rospkg
from iri_wam_reproduce_trajectory.srv import ExecTraj, ExecTrajRequest

rospack = rospkg.RosPack()
# This rospack.get_path() works in the same way as $(find name_of_package) in the launch files.
traj = rospack.get_path(
    'iri_wam_reproduce_trajectory') + "/config/get_food.txt"
req = ExecTrajRequest()
req.file = traj
print(traj)

rospy.init_node(
    'service_client')  # Initialise a ROS node with the name service_client
print("Waiting for service to start")
rospy.wait_for_service(
    '/execute_trajectory'
)  # Wait for the service client /iri_wam_reproduce_trajectory/ExecTraj to be running
print("Create service proxy")
exec_traj_service = rospy.ServiceProxy(
    '/execute_trajectory', ExecTraj)  # Create the connection to the service
print("Execute trajectory")
result = exec_traj_service(
    req
)  # Send through the connection the filename of the file containing the trajectory
print result  # Print the result given by the service called
print("Finished exercise_3_1.py")
示例#6
0
#! /usr/bin/env python

import rospy
# Import the service message used by the service /trajectory_by_name
from iri_wam_reproduce_trajectory.srv import ExecTraj, ExecTrajRequest
import sys
import rospkg


# Initialise a ROS node with the name service_client
rospy.init_node('service_client')
# Wait for the service client /trajectory_by_name to be running
rospy.wait_for_service('/execute_trajectory')
# Create the connection to the service
traj_by_name_service = rospy.ServiceProxy('/execute_trajectory', ExecTraj)
# Create an object of type TrajByNameRequest
traj_by_name_object = ExecTrajRequest()
# Fill the variable traj_name of this object with the desired value
rospack = rospkg.RosPack()
# This rospack.get_path() works in the same way as $(find name_of_package) in the launch files.
traj = rospack.get_path('iri_wam_reproduce_trajectory') + "/config/get_food.txt"
traj_by_name_object = ExecTrajRequest()
traj_by_name_object.file = traj
# Send through the connection the name of the trajectory to be executed by the robot
result = traj_by_name_service(traj_by_name_object)
# Print the result given by the service called
print result
示例#7
0
#! /usr/bin/env python

import rospy
from iri_wam_reproduce_trajectory.srv import ExecTraj, ExecTrajRequest
import rospkg

rospack = rospkg.RosPack()

rospy.init_node('service_client')
rospy.wait_for_service('/execute_trajectory')
execute_trajectory_service = rospy.ServiceProxy('/execute_trajectory',
                                                ExecTraj)
kk = ExecTrajRequest()
kk.file = rospack.get_path(
    'iri_wam_reproduce_trajectory') + "/config/get_food.txt"
result = execute_trajectory_service(kk)
print result
示例#8
0
#! /usr/bin/env python

import rospy
import rospkg

# Import the service message used by the service /execute_trajectory
from iri_wam_reproduce_trajectory.srv import ExecTraj, ExecTrajRequest
import sys

# Initialise a ROS node with the name service_client
rospy.init_node('service_client')
# Wait for the service client /execute_trajectory to be running
rospy.wait_for_service('/execute_trajectory')
exec_by_file_service = rospy.ServiceProxy('execute_trajectory', ExecTraj)
rospack = rospkg.RosPack()
exec_by_file_object = ExecTrajRequest()
traj = rospack.get_path('iri_wam_reproduce_trajectory') + "/config/get_food.txt"
exec_by_file_object.file = traj
# Create the connection to the service

#traj_by_name_service = rospy.ServiceProxy('/execute_trajectory', ExecTraj)
# Create an object of type TrajByNameRequest
#traj_by_name_object = TrajByNameRequest()
# Fill the variable traj_name of this object with the desired value
#traj_by_name_object.traj_name = "release_food"
# Send through the connection the name of the trajectory to be executed by the robot
result = exec_by_file_service(exec_by_file_object)
#traj_by_name_service(traj_by_name_object)
# Print the result given by the service called
print result
示例#9
0
#! /usr/bin/env python

import rospy
import rospkg
from iri_wam_reproduce_trajectory.srv import ExecTraj, ExecTrajRequest

# Initialise a ROS node with the name service_client
rospy.init_node('service_client')
# Wait for the service client to be running
rospy.wait_for_service('/execute_trajectory')
execute_service_client = rospy.ServiceProxy('/execute_trajectory', ExecTraj)
execute_request_obj = ExecTrajRequest()
rospack = rospkg.RosPack()
# This rospack.get_path() works in the same way as $(find name_of_package) in the launch files.
traj_file_path = rospack.get_path(
    'iri_wam_reproduce_trajectory') + "/config/get_food.txt"

execute_request_obj.file = traj_file_path
result = execute_service_client(execute_request_obj)
print result
示例#10
0
import rospkg
rospack = rospkg.RosPack()
# This rospack.get_path() works in the same way as $(find name_of_package) in the launch files.
traj = rospack.get_path(
    'iri_wam_reproduce_trajectory') + "/config/get_food.txt"

# Initialise a ROS node with the name service_client
rospy.init_node('service_client')
# Wait for the service client /execute_trajectory to be running
rospy.wait_for_service('/execute_trajectory')
# Create the connection to the service
trajectory_service = rospy.ServiceProxy('/execute_trajectory', ExecTraj)
# Create an object of type ExecTrajRequest()
trajectory_object = ExecTrajRequest()
# Fill the variable model_name of this object with the desired value
trajectory_object.file = traj
result = trajectory_service(trajectory_object)
print result

# LAUNCH FILE
#<launch>

#  <include file="$(find iri_wam_reproduce_trajectory)/launch/start_service.launch"/>

#  <node pkg ="unit_3_services"
#        type="exercise_3_1.py"
#        name="service_client"
#        output="screen">
#  </node>

#</launch>
示例#11
0
#! /usr/bin/env python

import rospy
# Import the service message used by the service /trajectory_by_name
from iri_wam_reproduce_trajectory.srv import ExecTraj, ExecTrajRequest
import sys

import rospkg
rospack = rospkg.RosPack()
# This rospack.get_path() works in the same way as $(find name_of_package) in the launch files.
traj = rospack.get_path('iri_wam_reproduce_trajectory') + "/config/get_food.txt"

# Initialise a ROS node with the name service_client
rospy.init_node('service_client')
# Wait for the service client //execute_trajectory to be running
rospy.wait_for_service('/execute_trajectory')
# Create the connection to the service
execute_trajectory_service = rospy.ServiceProxy('/execute_trajectory', ExecTraj)
# Create an object of type TrajByNameRequest
execute_trajectory_object = ExecTrajRequest()
# Fill the variable traj_name of this object with the desired value
execute_trajectory_object.file = traj
# Send through the connection the name of the trajectory to be executed by the robot
result = execute_trajectory_service(execute_trajectory_object)
# Print the result given by the service called
print (result)
示例#12
0
 def main(self):
     req = ExecTrajRequest()
     req.file = self.trj_file_
     result = self.service_(req)
示例#13
0
#! /usr/bin/env python

import rospy
from iri_wam_reproduce_trajectory.srv import ExecTraj, ExecTrajRequest  # Import the service message used by the service /gazebo/delete_model
import sys
import rospkg
rospack = rospkg.RosPack()

# This rospack.get_path() works in the same way as $(find name_of_package) in the launch files.
traj = rospack.get_path(
    'iri_wam_reproduce_trajectory') + "/config/get_food.txt"

rospy.init_node(
    'unit_3_node')  # Initialise a ROS node with the name service_client
rospy.wait_for_service(
    '/execute_trajectory'
)  # Wait for the service client /gazebo/delete_model to be running
exec_traj = rospy.ServiceProxy(
    '/execute_trajectory', ExecTraj)  # Create the connection to the service
request = ExecTrajRequest()
request.file = traj
#kk.file = traj # Fill the variable model_name of this object with the desired value
result = exec_traj(
    request
)  # Send through the connection the name of the object to be deleted by the service
print result  # Print the result given by the service called
示例#14
0
#!/usr/bin/env python
import rospy
from iri_wam_reproduce_trajectory.srv import ExecTraj, ExecTrajRequest
import sys
import rospkg

rospy.init_node('service_client')
rospy.wait_for_service('/execute_trajectory')
exec_trj_serv =rospy.ServiceProxy('/execute_trajectory',ExecTraj)
rospack = rospkg.RosPack()
traj = rospack.get_path('iri_wam_reproduce_trajectory') + "/config/get_food.txt"
kk = ExecTrajRequest()
kk.file = traj
result = exec_trj_serv(kk)
print(result)
traj = rospack.get_path('iri_wam_reproduce_trajectory') + "/config/release_food.txt"
kk = ExecTrajRequest()
kk.file = traj
result = exec_trj_serv(kk)
print(result)
示例#15
0
#init the service server
service_path = rospy.ServiceProxy(
    '/execute_trajectory', ExecTraj)  # Create the connection to the service

#create a request object
execute_a_path = ExecTrajRequest()

#initialize a ros pkg directory handler
rospack = rospkg.RosPack()
# This rospack.get_path() works in the same way as $(find name_of_package) in the launch files.
#Its a sequence of joint values that the service execute_trajectory
#will read based on the path given in the call
traj = rospack.get_path(
    'iri_wam_reproduce_trajectory') + "/config/get_food.txt"

try:
    rospy.loginfo("Executing...")
    #like in msgs, we have to fill the correct file field inside the srv file in srv folder
    execute_a_path.file = traj

    #our filled object path insode the service
    service_path(execute_a_path)
    rospy.loginfo("SERVICE GET_FOOD PATH SUCCEEDED!")
except Exception as e:
    print("Failure to execute.")
    pass

finally:
    rospy.loginfo("Finished.")