ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Problem with str in service client

asked 2020-02-25 15:21:06 -0500

MichaelDUEE gravatar image

I am writing a service and this is the message :

std_msgs/String pose
---
sensor_msgs/JointState finalpos

This is the client :

#!/usr/bin/env python

import rospy 
from interbotix_moveit.srv import pickitstr,pickitstringResponse
from std_msgs.msg import String
rospy.init_node('service_arm_client')
word=String()
rospy.wait_for_service('/widowxl/arm_service')

pose = rospy.ServiceProxy('/widowxl/arm_service',pickitstr)
word = pickitstringResponse()
word= 'Upright'
finalpose = pose(word)
print(finalpose.finalpose)

And I get this error :

Traceback (most recent call last):
File "/home/michael/catkin_ws/src/interbotix_ros/interbotix_moveit/src/service_client_test.py", line 13, in <module> finalpose = pose(word) File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 435, in __call__ return self.call(args, *kwds) File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 512, in call transport.send_message(request, self.seq) File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/impl/tcpros_base.py", line 665, in send_message serialize_message(self.write_buff, seq, msg) File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/msg.py", line 152, in serialize_message msg.serialize(b) File "/home/michael/catkin_ws/devel/lib/python2.7/dist-packages/interbotix_moveit/srv/_pickitstr.py", line 58, in serialize _x = self.pose.data AttributeError: 'str' object has no attribute 'data'

What Is the problem ?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2020-02-26 02:56:15 -0500

pavel92 gravatar image

Well in your case pose is a server proxy, not an actual pose or a string pose request as defined in your srv. Also you are not creating your srv request for the call properly. Check the documentation for the std_msg/Sring.
You can try the following:

word=String()
word.data= 'Upright'
srv_proxy = rospy.ServiceProxy(step.context.set_navigation_config_service_name, String)
response = srv_proxy(word)

The response should be of type sensor_msgs/JointState and you should be able to access its data with response.specific_field (for example response.name[0] to get the name of the first joint).

edit flag offensive delete link more
0

answered 2020-02-26 03:03:33 -0500

MichaelDUEE gravatar image

I found the problem. I just needed to write it like this :

rospy.wait_for_service('/widowxl/arm_service')

pose = rospy.ServiceProxy('/widowxl/arm_service',pickitstr)
word = pickitstringResponse()
word.pose.data = 'Upright'
finalpose = pose(word)

also I changed this

print(finalpose.finalpose)

to this

print(finalpose.finalpos)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-02-25 15:21:06 -0500

Seen: 1,120 times

Last updated: Feb 26 '20