本文整理汇总了Python中rospy.ServiceException方法的典型用法代码示例。如果您正苦于以下问题:Python rospy.ServiceException方法的具体用法?Python rospy.ServiceException怎么用?Python rospy.ServiceException使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rospy
的用法示例。
在下文中一共展示了rospy.ServiceException方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fk_service_client
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceException [as 别名]
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
示例2: fk_request
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceException [as 别名]
def fk_request(self, joint_angles,
end_point='right_hand'):
"""
Forward Kinematics request sent to FK Service
@type joint_angles: dict({str:float})
@param joint_angles: the arm's joint positions
@type end_point: string
@param end_point: name of the end point (should be in URDF)
@return: Forward Kinematics response from FK service
"""
fkreq = SolvePositionFKRequest()
# Add desired pose for forward kinematics
joints = JointState()
joints.name = joint_angles.keys()
joints.position = joint_angles.values()
fkreq.configuration.append(joints)
# Request forward kinematics from base to end_point
fkreq.tip_names.append(end_point)
try:
resp = self._fksvc(fkreq)
except (rospy.ServiceException, rospy.ROSException), e:
rospy.logerr("FK Service call failed: %s" % (e,))
return False
示例3: get_object_relative_pose
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceException [as 别名]
def get_object_relative_pose(self, obj_type="SQUARE", obj_color="BLUE", ret_image=True):
service_name = self.__services_name['object_pose_service']
rospy.wait_for_service(service_name)
try:
detection_service = rospy.ServiceProxy(service_name, ObjDetection)
response = detection_service(obj_type=obj_type, obj_color=obj_color,
workspace_ratio=25. / 16, ret_image=ret_image)
ret_status = self.__status_interpreter_obj_detection[response.status]
if ret_status != "SUCCESSFUL":
print "Object not detected: " + ret_status
msg_res = response.obj_pose
obj_type = response.obj_type
obj_color = response.obj_color
if ret_image:
im_ret = extract_img_from_ros_msg(response.img)
else:
im_ret = None
return ret_status, msg_res, obj_type, obj_color, im_ret
except rospy.ServiceException, e:
print "Service call failed: %s" % e
示例4: _arm
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceException [as 别名]
def _arm(self):
print(self.namespace, 'arming')
service_name = '%s/mavros/cmd/arming' % self.namespace
rospy.wait_for_service(service_name)
try:
service = rospy.ServiceProxy(service_name, CommandBool)
resp = service(True)
except rospy.ServiceException as e:
print(self.namespace, 'service call to arm failed:', str(e),
file=sys.stderr)
return False
if not resp.success:
print(self.namespace, 'failed to arm', file=sys.stderr)
return False
print(self.namespace, 'armed')
return True
示例5: _return_home
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceException [as 别名]
def _return_home(self):
print(self.namespace, 'land')
req = CommandTOLRequest()
req.min_pitch = 0.0
req.yaw = -math.pi if self.color == 'blue' else 0.0
req.latitude = self.start_position.latitude
req.longitude = self.start_position.longitude
req.altitude = self.start_position.altitude
service_name = '%s/mavros/cmd/land' % self.namespace
rospy.wait_for_service(service_name)
try:
service = rospy.ServiceProxy(service_name, CommandTOL)
resp = service.call(req)
except rospy.ServiceException as e:
print(self.namespace, 'service call to land failed:', str(e),
file=sys.stderr)
return False
if not resp.success:
print(self.namespace, 'failed to land', file=sys.stderr)
return False
print(self.namespace, 'landing')
self._set_state(STATE_LANDING)
return True
示例6: get_endeffector_pos
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceException [as 别名]
def get_endeffector_pos(self):
fkreq = SolvePositionFKRequest()
joints = JointState()
joints.name = self._limb_right.joint_names()
joints.position = [self._limb_right.joint_angle(j)
for j in joints.name]
# Add desired pose for forward kinematics
fkreq.configuration.append(joints)
fkreq.tip_names.append('right_hand')
try:
rospy.wait_for_service(self.name_of_service, 5)
resp = self.fksvc(fkreq)
except (rospy.ServiceException, rospy.ROSException), e:
rospy.logerr("Service call failed: %s" % (e,))
return False
示例7: call_service
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceException [as 别名]
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
示例8: __init__
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceException [as 别名]
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()
示例9: RequestDMP
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceException [as 别名]
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
示例10: manage_controller
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceException [as 别名]
def manage_controller(controller_name, port_namespace, controller_type, command, deps, start, stop, restart):
try:
controller = rospy.get_param(controller_name + '/controller')
package_path = controller['package']
module_name = controller['module']
class_name = controller['type']
except KeyError as ke:
rospy.logerr('[%s] configuration error: could not find controller parameters on parameter server' % controller_name)
sys.exit(1)
except Exception as e:
rospy.logerr('[%s]: %s' % (controller_name, e))
sys.exit(1)
if command.lower() == 'start':
try:
response = start(port_namespace, package_path, module_name, class_name, controller_name, deps)
if response.success: rospy.loginfo(response.reason)
else: rospy.logerr(response.reason)
except rospy.ServiceException, e:
rospy.logerr('Service call failed: %s' % e)
示例11: _connect_to_sensor
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceException [as 别名]
def _connect_to_sensor(self):
"""Connect to the sensor.
"""
name = self._device_name
try:
# Check if device is actively in list
rospy.wait_for_service('phoxi_camera/get_device_list')
device_list = rospy.ServiceProxy('phoxi_camera/get_device_list', GetDeviceList)().out
if not str(name) in device_list:
logging.error('PhoXi sensor {} not in list of active devices'.format(name))
return False
success = rospy.ServiceProxy('phoxi_camera/connect_camera', ConnectCamera)(name).success
if not success:
logging.error('Could not connect to PhoXi sensor {}'.format(name))
return False
logging.debug('Connected to PhoXi Sensor {}'.format(name))
return True
except rospy.ServiceException as e:
logging.error('Service call failed: {}'.format(e))
return False
示例12: on_button_reset_pressed
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceException [as 别名]
def on_button_reset_pressed(self):
self._num_pattern_detections = 0
self._calibration_output = ""
self._update_required = True
self.button_start.setEnabled( False )
try:
rospy.wait_for_service('dvs_calibration/reset', 1)
try:
reset_service = rospy.ServiceProxy('dvs_calibration/reset', Empty)
resp = reset_service()
except rospy.ServiceException, e:
print "Service call failed: %s"%e
except:
print "service not available..."
pass
示例13: reset
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceException [as 别名]
def reset(self):
rospy.wait_for_service('gazebo/reset_simulation')
try:
self.reset_proxy()
except (rospy.ServiceException) as e:
print("gazebo/reset_simulation service call failed")
data = None
while data is None:
try:
data = rospy.wait_for_message('scan', LaserScan, timeout=5)
except:
pass
if self.initGoal:
self.goal_x, self.goal_y = self.respawn_goal.getPosition()
self.initGoal = False
self.goal_distance = self.getGoalDistace()
state, done = self.getState(data)
return np.asarray(state)
示例14: spawn_urdf
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceException [as 别名]
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))
示例15: spawn_sdf
# 需要导入模块: import rospy [as 别名]
# 或者: from rospy import ServiceException [as 别名]
def spawn_sdf(name, description_xml, pose, reference_frame):
rospy.wait_for_service('/gazebo/spawn_sdf_model')
try:
spawn_sdf = rospy.ServiceProxy('/gazebo/spawn_sdf_model', SpawnModel)
resp_sdf = spawn_sdf(name, description_xml, "/", pose, reference_frame)
except rospy.ServiceException as e:
rospy.logerr("Spawn SDF service call failed: {0}".format(e))