ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Can you point out the mistake for me?
Services have a Request
and a Reply
type. SetJointStates
is most likely a module containing both the Request
and Reply
types, but isn't a service request itself.
If you'd do a print (dir(SetJointStates))
we should be able to verify that.
In any case: you'll probably want to use the SetJointStatesRequest
.
2 | No.2 Revision |
Can you point out the mistake for me?
Services have a Request
and a Reply
type. SetJointStates
is most likely a module containing both the Request
and Reply
types, but isn't a service request itself.
If you'd do a print (dir(SetJointStates))
we should be able to verify that.
In any case: you'll probably want to use the SetJointStatesRequest
.
Another problem with the code is that you've named your ServiceProxy
variable set_joint_states
, while you already have a method called set_joint_states
. That is not going to work.
3 | No.3 Revision |
Can you point out the mistake for me?
Services have a Request
and a Reply
type. SetJointStates
is most likely a module containing both the Request
and Reply
types, but isn't a service request itself.
If you'd do a print (dir(SetJointStates))
we should be able to verify that.
In any case: you'll probably want to use the SetJointStatesRequest
., or just use the ServiceProxy
directly.
Another problem with the code is that you've named your ServiceProxy
variable set_joint_states
, while you already have a method called set_joint_states
. That is not going to work.
4 | No.4 Revision |
[..] from robotic_arm_algorithms.srv import SetJointStates def set_joint_states(joint_states): rospy.wait_for_service('set_joint_states') try: set_joint_states = rospy.ServiceProxy('set_joint_states', SetJointStates) msg = SetJointStates() [..]
Can you point out the mistake for me?
Services have a Request
and a Reply
type. SetJointStates
is most likely a module containing both the Request
and Reply
types, but isn't a service request itself.itself (note how the tutorial you link to imports *
, not AddTwoInts
).
If you'd do a print (dir(SetJointStates))
we should be able to verify that.
In any case: you'll probably want to use the SetJointStatesRequest
, or just use the ServiceProxy
directly.
Another problem with the code is that you've named your ServiceProxy
variable set_joint_states
, while you already have a method called set_joint_states
. That is not going to work.
5 | No.5 Revision |
[..] from robotic_arm_algorithms.srv import SetJointStates def set_joint_states(joint_states): rospy.wait_for_service('set_joint_states') try: set_joint_states = rospy.ServiceProxy('set_joint_states', SetJointStates) msg = SetJointStates() [..]
Can you point out the mistake for me?
Services have a Request
and a Reply
type. SetJointStates
is most likely a module containing both the Request
and Reply
types, but isn't a service request itself (note how the tutorial you link to imports *
, not AddTwoInts
).
If you'd do a print (dir(SetJointStates))
we should be able to verify that.
In any case: you'll probably want to use the SetJointStatesRequest
, or just use the ServiceProxy
directly.
Another problem with the code is that you've named your ServiceProxy
variable set_joint_states
, while you already have a method called set_joint_states
. That is not going to work.
Edit:
When I put
print (dir(SetJointStates))
intoset_joint_states
method of the client source code, following strings prints on terminal:['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_md5sum', '_request_class', '_response_class', '_type']
As you see, there is a _request_class
and a _response_class
field present.
That would seem to confirm what I wrote above (ie: SetJointStates
is not a request or a response class itself, but the composite one encapsulating both.
As I wrote in my earlier answer, you'll want to use the SetJointStatesRequest
class instead. Be sure to import
that.
6 | No.6 Revision |
[..] from robotic_arm_algorithms.srv import SetJointStates def set_joint_states(joint_states): rospy.wait_for_service('set_joint_states') try: set_joint_states = rospy.ServiceProxy('set_joint_states', SetJointStates) msg = SetJointStates() [..]
Can you point out the mistake for me?
Services have a Request
and a Reply
type. SetJointStates
is most likely a module containing both the Request
and Reply
types, but isn't a service request itself (note how the tutorial you link to imports *
, not AddTwoInts
).
If you'd do a print (dir(SetJointStates))
we should be able to verify that.
In any case: you'll probably want to use the SetJointStatesRequest
, or just use the ServiceProxy
directly.
Another problem with the code is that you've named your ServiceProxy
variable set_joint_states
, while you already have a method called set_joint_states
. That is not going to work.
Edit:
When I put
print (dir(SetJointStates))
intoset_joint_states
method of the client source code, following strings prints on terminal:['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_md5sum', '_request_class', '_response_class', '_type']
As you see, there is a _request_class
and a _response_class
field present.
That would seem to confirm what I wrote above (ie: SetJointStates
is not a request or a response class itself, but the composite one encapsulating both.
As I wrote in my earlier answer, you'll want to use the SetJointStatesRequest
class instead. Be sure to import
that.
Edit 2: we should try to avoid duplicating these Q&As but I can't find one quickly, so here is an example of some code that will probably work:
[..]
from robotic_arm_algorithms.srv import SetJointStates, SetJointStatesRequest
def set_joint_states(joint_states):
rospy.wait_for_service('set_joint_states')
try:
# bind our local service proxy
svc_set_joint_states = rospy.ServiceProxy('set_joint_states', SetJointStates)
# create the service request
req = SetJointStatesRequest()
# populate the fields of the request
req.forearm_0 = joint_states[0]
req.forearm_1 = joint_states[1]
req.arm_0 = joint_states[2]
req.arm_1 = joint_states[3]
# invoke the service, passing it the request
resp = scv_set_joint_states(req)
# 'resp' is here of type 'SetJointStatesReponse'
# perhaps do something with the response
except rospy.ServiceException, e:
print "Service call failed: %s"%e
[..]
7 | No.7 Revision |
[..] from robotic_arm_algorithms.srv import SetJointStates def set_joint_states(joint_states): rospy.wait_for_service('set_joint_states') try: set_joint_states = rospy.ServiceProxy('set_joint_states', SetJointStates) msg = SetJointStates() [..]
Can you point out the mistake for me?
Services have a Request
and a
type. ReplyResponseSetJointStates
is most likely a module containing both the Request
and
types, but isn't a service request or response itself (note how the tutorial you link to imports ReplyResponse*
, not AddTwoInts
).
If you'd do a print (dir(SetJointStates))
we should be able to verify that.
In any case: you'll probably want to use the SetJointStatesRequest
, or just use the ServiceProxy
directly.
Another problem with the code is that you've named your ServiceProxy
variable set_joint_states
, while you already have a method called set_joint_states
. That is not going to work.
Edit:
When I put
print (dir(SetJointStates))
intoset_joint_states
method of the client source code, following strings prints on terminal:['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_md5sum', '_request_class', '_response_class', '_type']
As you see, there is a _request_class
and a _response_class
field present.
That would seem to confirm what I wrote above (ie: SetJointStates
is not a request or a response class itself, but the composite one encapsulating both.
As I wrote in my earlier answer, you'll want to use the SetJointStatesRequest
class instead. Be sure to import
that.
Edit 2: we should try to avoid duplicating these Q&As but I can't find one quickly, so here is an example of some code that will probably work:
[..]
from robotic_arm_algorithms.srv import SetJointStates, SetJointStatesRequest
def set_joint_states(joint_states):
rospy.wait_for_service('set_joint_states')
try:
# bind our local service proxy
svc_set_joint_states = rospy.ServiceProxy('set_joint_states', SetJointStates)
# create the service request
req = SetJointStatesRequest()
# populate the fields of the request
req.forearm_0 = joint_states[0]
req.forearm_1 = joint_states[1]
req.arm_0 = joint_states[2]
req.arm_1 = joint_states[3]
# invoke the service, passing it the request
resp = scv_set_joint_states(req)
# 'resp' is here of type 'SetJointStatesReponse'
# perhaps do something with the response
except rospy.ServiceException, e:
print "Service call failed: %s"%e
[..]
Note that in addition to using the Request
class, I've also renamed the service proxy variable to svc_set_joint_states
to avoid shadowing your set_joint_states(..)
method.
8 | No.8 Revision |
[..] from robotic_arm_algorithms.srv import SetJointStates def set_joint_states(joint_states): rospy.wait_for_service('set_joint_states') try: set_joint_states = rospy.ServiceProxy('set_joint_states', SetJointStates) msg = SetJointStates() [..]
Can you point out the mistake for me?
Services have a Request
and a Response
type. SetJointStates
is most likely a module containing both the Request
and Response
types, but isn't a service request or response itself (note how the tutorial you link to imports *
, not AddTwoInts
).
If you'd do a print (dir(SetJointStates))
we should be able to verify that.
In any case: you'll probably want to use the SetJointStatesRequest
, or just use the ServiceProxy
directly.
Another problem with the code is that you've named your ServiceProxy
variable set_joint_states
, while you already have a method called set_joint_states
. That is not going to work.
Edit:
When I put
print (dir(SetJointStates))
intoset_joint_states
method of the client source code, following strings prints on terminal:['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_md5sum', '_request_class', '_response_class', '_type']
As you see, there is a _request_class
and a _response_class
field present.
That would seem to confirm what I wrote above (ie: SetJointStates
is not a request or a response class itself, but the composite one encapsulating both.
As I wrote in my earlier answer, you'll want to use the SetJointStatesRequest
class instead. Be sure to import
that.
Edit 2: we should try to avoid duplicating these Q&As but I can't find one quickly, so here is an example of some code that will probably work:
[..]
from robotic_arm_algorithms.srv import SetJointStates, SetJointStatesRequest
*
def set_joint_states(joint_states):
rospy.wait_for_service('set_joint_states')
try:
# bind our local service proxy
svc_set_joint_states = rospy.ServiceProxy('set_joint_states', SetJointStates)
# create the service request
req = SetJointStatesRequest()
# populate the fields of the request
req.forearm_0 = joint_states[0]
req.forearm_1 = joint_states[1]
req.arm_0 = joint_states[2]
req.arm_1 = joint_states[3]
# invoke the service, passing it the request
resp = scv_set_joint_states(req)
# 'resp' is here of type 'SetJointStatesReponse'
# perhaps do something with the response
except rospy.ServiceException, e:
print "Service call failed: %s"%e
[..]
Note that in addition to using the Request
class, I've also renamed the service proxy variable to svc_set_joint_states
to avoid shadowing your set_joint_states(..)
method.