Python rospy.ServiceProxy() Examples
The following are 30
code examples of rospy.ServiceProxy().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rospy
, or try the search function
.
Example #1
Source File: training_helper.py From RoboND-Perception-Exercises with MIT License | 7 votes |
def spawn_model(model_name): """ Spawns a model in front of the RGBD camera. Args: None Returns: None """ initial_pose = Pose() initial_pose.position.x = 0 initial_pose.position.y = 1 initial_pose.position.z = 1 # Spawn the new model # model_path = rospkg.RosPack().get_path('sensor_stick')+'/models/' model_xml = '' with open (model_path + model_name + '/model.sdf', 'r') as xml_file: model_xml = xml_file.read().replace('\n', '') spawn_model_prox = rospy.ServiceProxy('gazebo/spawn_sdf_model', SpawnModel) spawn_model_prox('training_model', model_xml, '', initial_pose, 'world')
Example #2
Source File: tool_ros_command_interface.py From niryo_one_ros with GNU General Public License v3.0 | 7 votes |
def __init__(self): rospy.wait_for_service('niryo_one/tools/ping_and_set_dxl_tool') rospy.wait_for_service('niryo_one/tools/open_gripper') rospy.wait_for_service('niryo_one/tools/close_gripper') rospy.wait_for_service('niryo_one/tools/pull_air_vacuum_pump') rospy.wait_for_service('niryo_one/tools/push_air_vacuum_pump') self.service_ping_dxl_tool = rospy.ServiceProxy('niryo_one/tools/ping_and_set_dxl_tool', PingDxlTool) self.service_open_gripper = rospy.ServiceProxy('niryo_one/tools/open_gripper', OpenGripper) self.service_close_gripper = rospy.ServiceProxy('niryo_one/tools/close_gripper', CloseGripper) self.service_pull_air_vacuum_pump = rospy.ServiceProxy('niryo_one/tools/pull_air_vacuum_pump', PullAirVacuumPump) self.service_push_air_vacuum_pump = rospy.ServiceProxy('niryo_one/tools/push_air_vacuum_pump', PushAirVacuumPump) self.service_setup_digital_output_tool = rospy.ServiceProxy('niryo_one/rpi/set_digital_io_mode', SetDigitalIO) self.service_activate_digital_output_tool = rospy.ServiceProxy('niryo_one/rpi/set_digital_io_state', SetDigitalIO) rospy.loginfo("Interface between Tools Controller and Ros Control has been started.")
Example #3
Source File: fk_service_client.py From intera_sdk with Apache License 2.0 | 7 votes |
def fk_service_client(limb = "right"): ns = "ExternalTools/" + limb + "/PositionKinematicsNode/FKService" fksvc = rospy.ServiceProxy(ns, SolvePositionFK) fkreq = SolvePositionFKRequest() joints = JointState() joints.name = ['right_j0', 'right_j1', 'right_j2', 'right_j3', 'right_j4', 'right_j5', 'right_j6'] joints.position = [0.763331, 0.415979, -1.728629, 1.482985, -1.135621, -1.674347, -0.496337] # Add desired pose for forward kinematics fkreq.configuration.append(joints) # Request forward kinematics from base to "right_hand" link fkreq.tip_names.append('right_hand') try: rospy.wait_for_service(ns, 5.0) resp = fksvc(fkreq) except (rospy.ServiceException, rospy.ROSException), e: rospy.logerr("Service call failed: %s" % (e,)) return False # Check if result valid
Example #4
Source File: gazebo_models.py From AI-Robot-Challenge-Lab with MIT License | 6 votes |
def spawn_urdf(name, description_xml, pose, reference_frame): rospy.wait_for_service('/gazebo/spawn_urdf_model') try: spawn_urdf = rospy.ServiceProxy('/gazebo/spawn_urdf_model', SpawnModel) resp_urdf = spawn_urdf(name, description_xml, "/", pose, reference_frame) except rospy.ServiceException as e: rospy.logerr("Spawn URDF service call failed: {0}".format(e))
Example #5
Source File: dmp_utils.py From costar_plan with Apache License 2.0 | 6 votes |
def RequestDMP(u,dt,k_gain,d_gain,num_basis_functions): ndims = len(u[0]) k_gains = [k_gain]*ndims d_gains = [d_gain]*ndims ex = DMPTraj() for i in range(len(u)): pt = DMPPoint() pt.positions = u[i] # always sends positions regardless of actual content ex.points.append(pt) ex.times.append(dt * i) # make sure times are reasonable rospy.wait_for_service('learn_dmp_from_demo') try: lfd = rospy.ServiceProxy('learn_dmp_from_demo', LearnDMPFromDemo) resp = lfd(ex, k_gains, d_gains, num_basis_functions) except rospy.ServiceException, e: print "Service call failed: %s"%e
Example #6
Source File: vncc.py From prpy with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _GetDetection(self, obj_name): """ Calls the service to get a detection of a particular object. @param obj_name The name of the object to detect @return A 4x4 transformation matrix describing the pose of the object in world frame, None if the object is not detected """ #Call detection service for a particular object detect_vncc = rospy.ServiceProxy(self.service_namespace+'/get_vncc_detections', vncc_msgs.srv.GetDetections) detect_resp = detect_vncc(object_name=obj_name) if detect_resp.ok == False: return None #Assumes one instance of object result = self._MsgToPose(detect_resp.detections[0]) if (self.detection_frame is not None and self.world_frame is not None): result = self._LocalToWorld(result) result[:3,:3] = numpy.eye(3) return result
Example #7
Source File: base_control_utils.py From pyrobot with MIT License | 6 votes |
def __init__(self, configs): self.configs = configs self.ROT_VEL = self.configs.BASE.MAX_ABS_TURN_SPEED self.LIN_VEL = self.configs.BASE.MAX_ABS_FWD_SPEED self.MAP_FRAME = self.configs.BASE.MAP_FRAME self.BASE_FRAME = self.configs.BASE.VSLAM.VSLAM_BASE_FRAME self.point_idx = self.configs.BASE.TRACKED_POINT rospy.wait_for_service(self.configs.BASE.PLAN_TOPIC, timeout=3) try: self.plan_srv = rospy.ServiceProxy(self.configs.BASE.PLAN_TOPIC, GetPlan) except rospy.ServiceException: rospy.logerr( "Timed out waiting for the planning service. \ Make sure build_map in script and \ use_map in roslauch are set to the same value" ) self.start_state = build_pose_msg(0, 0, 0, self.BASE_FRAME) self.tolerance = self.configs.BASE.PLAN_TOL self._transform_listener = tf.TransformListener()
Example #8
Source File: ros_client.py From strands_qsr_lib with MIT License | 6 votes |
def call_service(self, req): """Calling the appropriate service depending on the given request type. Requests have to inherit from 'HMMRepRequestAbstractclass'. :param req: The request class instance for the request you want to make :return: The qsr_type and resulting data tuple. The data is in the data type produced by the response. """ assert(issubclass(req.__class__, RepRequestAbstractclass)) s = rospy.ServiceProxy(self.services[req.__class__],QSRProbRep) try: s.wait_for_service(timeout=10.) res = s(QSRProbRepRequest(data=json.dumps(req.kwargs))) except (rospy.ROSException, rospy.ROSInterruptException, rospy.ServiceException) as e: rospy.logerr(e) return None try: data = json.loads(res.data) except ValueError: data = str(res.data) return data
Example #9
Source File: mavros_control2.py From vision_to_mavros with GNU General Public License v3.0 | 6 votes |
def __init__(self): rospy.init_node("mav_control_node") rospy.Subscriber("/mavros/local_position/pose", PoseStamped, self.pose_callback) rospy.Subscriber("/mavros/rc/in", RCIn, self.rc_callback) self.cmd_pos_pub = rospy.Publisher("/mavros/setpoint_position/local", PoseStamped, queue_size=1) self.cmd_vel_pub = rospy.Publisher("/mavros/setpoint_velocity/cmd_vel_unstamped", Twist, queue_size=1) self.rc_override = rospy.Publisher("/mavros/rc/override", OverrideRCIn, queue_size=1) # mode 0 = STABILIZE # mode 4 = GUIDED # mode 9 = LAND self.mode_service = rospy.ServiceProxy('/mavros/set_mode', SetMode) self.arm_service = rospy.ServiceProxy('/mavros/cmd/arming', CommandBool) self.takeoff_service = rospy.ServiceProxy('/mavros/cmd/takeoff', CommandTOL) self.rc = RCIn() self.pose = Pose() self.timestamp = rospy.Time()
Example #10
Source File: mavros_control1.py From vision_to_mavros with GNU General Public License v3.0 | 6 votes |
def __init__(self): rospy.init_node("mav_control_node") rospy.Subscriber("/mavros/local_position/pose", PoseStamped, self.pose_callback) rospy.Subscriber("/mavros/rc/in", RCIn, self.rc_callback) self.cmd_pos_pub = rospy.Publisher("/mavros/setpoint_position/local", PoseStamped, queue_size=1) self.cmd_vel_pub = rospy.Publisher("/mavros/setpoint_velocity/cmd_vel_unstamped", Twist, queue_size=1) self.rc_override = rospy.Publisher("/mavros/rc/override", OverrideRCIn, queue_size=1) # mode 0 = STABILIZE # mode 4 = GUIDED # mode 9 = LAND self.mode_service = rospy.ServiceProxy('/mavros/set_mode', SetMode) self.arm_service = rospy.ServiceProxy('/mavros/cmd/arming', CommandBool) self.takeoff_service = rospy.ServiceProxy('/mavros/cmd/takeoff', CommandTOL) self.rc = RCIn() self.pose = Pose() self.timestamp = rospy.Time()
Example #11
Source File: script.py From RAFCON with Eclipse Public License 1.0 | 6 votes |
def execute(self, inputs, outputs, gvm): turtle_name = inputs["turtle_name"] x = inputs["x_pos"] y = inputs["y_pos"] phi = inputs["phi"] service = "/spawn" rospy.wait_for_service(service) spawn_turtle_service = rospy.ServiceProxy(service, Spawn) resp1 = spawn_turtle_service(x, y, phi, turtle_name) self.logger.info("ROS external module: executed the {} service".format(service)) turtle_pos_subscriber = rospy.Subscriber("/" + turtle_name + "/pose", Pose, check_turtle_pose) r = rospy.Rate(10) global pose_received # wait until the first pose message was received while not pose_received: r.sleep() return 0
Example #12
Source File: kinematics_interfaces.py From gym-sawyer with MIT License | 5 votes |
def __init__(self): """Interface to MoveIt! forward kinematics service.""" self._srv = rospy.ServiceProxy('/compute_fk', moveit_msgs.srv.GetPositionFK) self._srv.wait_for_service()
Example #13
Source File: mln_client.py From pracmln with BSD 2-Clause "Simplified" License | 5 votes |
def mln_interface_client(query, config=None): rospy.wait_for_service('mln_interface') try: mln_interface = rospy.ServiceProxy('mln_interface', MLNInterface) resp1 = mln_interface(query, config) return resp1.response except rospy.ServiceException, e: print('Service call failed: %s'%e)
Example #14
Source File: mln_client.py From pracmln with BSD 2-Clause "Simplified" License | 5 votes |
def mln_interface_client(query, config=None): rospy.wait_for_service('mln_interface') try: mln_interface = rospy.ServiceProxy('mln_interface', MLNInterface) resp1 = mln_interface(query, config) return resp1.response.results except rospy.ServiceException, e: print "Service call failed: %s"%e
Example #15
Source File: kinematics_interfaces.py From gym-sawyer with MIT License | 5 votes |
def __init__(self): """Interface to MoveIt! inverse kinematics service.""" self._srv = rospy.ServiceProxy('/compute_ik', moveit_msgs.srv.GetPositionIK) self._srv.wait_for_service()
Example #16
Source File: ik_command.py From baxter_demos with Apache License 2.0 | 5 votes |
def connect_service(side): ns = "ExternalTools/"+side+"/PositionKinematicsNode/IKService" iksvc = rospy.ServiceProxy(ns, SolvePositionIK) return iksvc, ns
Example #17
Source File: dmp_utils.py From costar_plan with Apache License 2.0 | 5 votes |
def PlanDMP(x_0, x_dot_0, t_0, goal, goal_thresh, seg_length, tau, dt, integrate_iter): rospy.wait_for_service('get_dmp_plan') try: gdp = rospy.ServiceProxy('get_dmp_plan', GetDMPPlan) resp = gdp(x_0, x_dot_0, t_0, goal, goal_thresh, seg_length, tau, dt, integrate_iter) except rospy.ServiceException, e: print "Service call failed: %s"%e
Example #18
Source File: dmp_utils.py From costar_plan with Apache License 2.0 | 5 votes |
def RequestActiveDMP(dmps): try: sad = rospy.ServiceProxy('set_active_dmp', SetActiveDMP) sad(dmps) except rospy.ServiceException, e: print "Service call failed: %s"%e
Example #19
Source File: panda_open_loop_grasp.py From mvp_grasp with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self): ggcnn_service_name = '/ggcnn_service' rospy.wait_for_service(ggcnn_service_name + '/predict') self.ggcnn_srv = rospy.ServiceProxy(ggcnn_service_name + '/predict', GraspPrediction) self.curr_velocity_publish_rate = 100.0 # Hz self.curr_velo_pub = rospy.Publisher('/cartesian_velocity_node_controller/cartesian_velocity', Twist, queue_size=1) self.max_velo = 0.10 self.curr_velo = Twist() self.best_grasp = Grasp() self.cs = ControlSwitcher({'moveit': 'position_joint_trajectory_controller', 'velocity': 'cartesian_velocity_node_controller'}) self.cs.switch_controller('moveit') self.pc = PandaCommander(group_name='panda_arm_hand') self.robot_state = None self.ROBOT_ERROR_DETECTED = False self.BAD_UPDATE = False rospy.Subscriber('/franka_state_controller/franka_states', FrankaState, self.__robot_state_callback, queue_size=1) # Centre and above the bin self.pregrasp_pose = [(rospy.get_param('/grasp_entropy_node/histogram/bounds/x2') + rospy.get_param('/grasp_entropy_node/histogram/bounds/x1'))/2 - 0.03, (rospy.get_param('/grasp_entropy_node/histogram/bounds/y2') + rospy.get_param('/grasp_entropy_node/histogram/bounds/y1'))/2 + 0.10, rospy.get_param('/grasp_entropy_node/height/z1') + 0.05, 2**0.5/2, -2**0.5/2, 0, 0] self.last_weight = 0 self.__weight_increase_check() self.experiment = Experiment()
Example #20
Source File: real_robobo_server.py From robotics-rl-srl with MIT License | 5 votes |
def __init__(self): super(Robobo, self).__init__() # Duration of the "FORWARD" action self.time_forward = 1.7 self.speed = 10 # Angle that robobo achieve in one second # at a given speed self.angle_offset = 38 # Degree per s when turning after the 1st second # at a given speed # From calibration self.angle_coeff = 50 # Robobo's position on the grid self.position = [0, 0] # Initialize the different for moving the robot self.directions = {'left': 90, 'right': -90} self.faces = ['west', 'north', 'east'] self.current_face_idx = 1 self.yaw_error = 0 self.yaw_target = 0 self.yaw_north = 0 self.yaw = 0 self.left_encoder_pos = 0 self.right_encoder_pos = 0 self.angles = {} # Attempt connection to Robobo's service try: self.robobo_command = rospy.ServiceProxy('/command', Command) except rospy.ServiceException as e: print("Service exception", str(e)) exit(1) self.status_sub = rospy.Subscriber("/status", Status, self.statusCallback)
Example #21
Source File: ros_control.py From mvp_grasp with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, controllers, controller_manager_node='/controller_manager'): """ :param controllers: Dictionary of controllers to manager/switch: {nick_name: controller_full_name} :param controller_manager_node: name of controller manager node. """ self.controllers = controllers rospy.wait_for_service(controller_manager_node + '/switch_controller') rospy.wait_for_service(controller_manager_node + '/list_controllers') self.switcher_srv = rospy.ServiceProxy(controller_manager_node + '/switch_controller', cm_srv.SwitchController) self.lister_srv = rospy.ServiceProxy(controller_manager_node + '/list_controllers', cm_srv.ListControllers)
Example #22
Source File: script.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def execute(self, inputs, outputs, gvm): turtle_name = inputs["turtle_name"] service = "/kill" rospy.wait_for_service(service) kill_turtle_service = rospy.ServiceProxy(service, Kill) resp1 = kill_turtle_service(turtle_name) self.logger.info("ROS external module: executed the {} service".format(service)) return 0
Example #23
Source File: script.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def execute(self, inputs, outputs, gvm): service = "/clear" rospy.wait_for_service(service) clear_turtle_area_service = rospy.ServiceProxy(service, Empty) resp1 = clear_turtle_area_service() self.logger.info("ROS external module: executed the {} service".format(service)) return 0
Example #24
Source File: script.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def execute(self, inputs, outputs, gvm): turtle_name = inputs["turtle_name"] x = inputs["x_pos"] y = inputs["y_pos"] phi = inputs["phi"] service = "/" + turtle_name + "/teleport_absolute" rospy.wait_for_service(service) move_turtle = rospy.ServiceProxy(service, TeleportAbsolute) resp1 = move_turtle(x, y, phi) self.logger.info("ROS external module: executed the {} service".format(service)) return 0
Example #25
Source File: condition.py From costar_plan with Apache License 2.0 | 5 votes |
def __init__(self): rospy.wait_for_service('check_state_validity', 5.0) self.srv = rospy.ServiceProxy('check_state_validity', GetStateValidity)
Example #26
Source File: dmp_policy.py From costar_plan with Apache License 2.0 | 5 votes |
def __init__(self, skill, goal, dmp, kinematics): self.skill = skill self.dmp = dmp self.kinematics = kinematics self.goal = goal self.activate = rospy.ServiceProxy('set_active_dmp', SetActiveDMP) self.plan = rospy.ServiceProxy('get_dmp_plan', GetDMPPlan)
Example #27
Source File: capture_features.py From RoboND-Perception-Exercises with MIT License | 5 votes |
def get_normals(cloud): get_normals_prox = rospy.ServiceProxy('/feature_extractor/get_normals', GetNormals) return get_normals_prox(cloud).cluster
Example #28
Source File: training_helper.py From RoboND-Perception-Exercises with MIT License | 5 votes |
def delete_model(): # Delete the old model if it's stil around delete_model_prox = rospy.ServiceProxy('gazebo/delete_model', DeleteModel) delete_model_prox('training_model')
Example #29
Source File: synthesizer.py From tts-ros1 with Apache License 2.0 | 5 votes |
def __call__(self, **kwargs): rospy.loginfo('will call service {}'.format(self.service_name)) from tts.srv import Polly rospy.wait_for_service(self.service_name) polly = rospy.ServiceProxy(self.service_name, Polly) return polly(polly_action='SynthesizeSpeech', **kwargs)
Example #30
Source File: rigid_transformations.py From autolab_core with Apache License 2.0 | 5 votes |
def publish_to_ros(self, mode='transform', service_name='rigid_transforms/rigid_transform_publisher', namespace=None): """Publishes RigidTransform to ROS If a transform referencing the same frames already exists in the ROS publisher, it is updated instead. This checking is not order sensitive Requires ROS rigid_transform_publisher service to be running. Assuming autolab_core is installed as a catkin package, this can be done with: roslaunch autolab_core rigid_transforms.launch Parameters ---------- mode : :obj:`str` Mode in which to publish. In {'transform', 'frame'} Defaults to 'transform' service_name : string, optional RigidTransformPublisher service to interface with. If the RigidTransformPublisher services are started through rigid_transforms.launch it will be called rigid_transform_publisher namespace : string, optional Namespace to prepend to transform_listener_service. If None, current namespace is prepended. Raises ------ rospy.ServiceException If service call to rigid_transform_publisher fails """ if namespace == None: service_name = rospy.get_namespace() + service_name else: service_name = namespace + service_name rospy.wait_for_service(service_name, timeout = 10) publisher = rospy.ServiceProxy(service_name, RigidTransformPublisher) trans = self.translation rot = self.quaternion publisher(trans[0], trans[1], trans[2], rot[0], rot[1], rot[2], rot[3], self.from_frame, self.to_frame, mode)