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

Error calling Service in rospy

asked 2021-04-10 17:35:30 -0500

HatchEm27998 gravatar image

Been trying to call this Service implemented in the following code as such:

# instantiate a service server to modify the robots in gazebo
two_wheel_robot_service = rospy.Service("/morph_sim/two_wheel_robot_update", two_wheel_robot_update, twoWheelRobotUpdateCallback, (add_model_client, delete_model_client, two_wheel_robot_urdf))

The call to the service is over here:

# instantiate a service client
two_wheel_robot_update_client = rospy.ServiceProxy("/morph_sim/two_wheel_robot_update", two_wheel_robot_update)
two_wheel_robot_update_srv_msg = two_wheel_robot_updateRequest()
[...]
# prepare the service message
two_wheel_robot_update_srv_msg.update_code = 1
two_wheel_robot_update_srv_msg.add_mode = two_wheel_robot_updateRequest.ADD_MODE_RANDOM
two_wheel_robot_update_srv_msg.half_range = half_range
two_wheel_robot_update_srv_msg.position_2d = []

# THE SERVICE CALL
call_service = two_wheel_robot_update_client(two_wheel_robot_update_srv_msg)
[...]

The two_wheel_robot_update.srv file:

int32 CODE_DELETE = -1
int32 CODE_DELETE_ALL = 0
int32 CODE_ADD = 1
bool ADD_MODE_RANDOM = False
bool ADD_MODE_SPECIFIED = True
int32 update_code
bool add_mode
float64 half_range
float64[] position_2d
---
uint8 SUCCESS = 1
uint8 ADD_FAIL_NO_RESPONSE = 2
uint8 ADD_FAIL_TOO_CROWDED = 3
uint8 ADD_FAIL_OCCUPIED = 4
uint8 DELETE_FAIL_NO_RESPONSE = 5
uint8 DELETE_FAIL_EXCEED_QUANTITY = 6
uint8 FAIL_OTHER_REASONS = 7
uint8 response_code

However, I keep getting this error because of the call, no matter what I try:

Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 667, in handle
    requests = transport.receive_once()
  File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/impl/tcpros_base.py", line 758, in receive_once
    raise TransportException("receive_once[%s]: unexpected error %s"%(self.name, str(e)))
TransportException: receive_once[/morph_sim/two_wheel_robot_update]: unexpected error an integer is required

Please help me solve this, I have no idea what to do, I have tried everything.

edit retag flag offensive close merge delete

Comments

Does it help if two_wheel_robot_update_srv_msg.update_code is assigned a 1 that has been type-casted to type int32?

abhishek47 gravatar image abhishek47  ( 2021-04-10 23:05:00 -0500 )edit

It did not work. Even when I'm giving it a value directly from the .srv file, it is still throwing me that error. I made the following change:

two_wheel_robot_update_srv_msg.update_code = two_wheel_robot_updateRequest.CODE_ADD
HatchEm27998 gravatar image HatchEm27998  ( 2021-04-11 01:24:33 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-04-11 08:07:46 -0500

miura gravatar image

updated 2021-04-11 09:16:24 -0500

Perhaps spaces are not allowed between the constant name and the constant value. Try the following and it may work.

int32 CODE_DELETE=-1
int32 CODE_DELETE_ALL=0
int32 CODE_ADD=1
bool ADD_MODE_RANDOM=False
bool ADD_MODE_SPECIFIED=True
int32 update_code
bool add_mode
float64 half_range
float64[] position_2d
---
uint8 SUCCESS=1
uint8 ADD_FAIL_NO_RESPONSE=2
uint8 ADD_FAIL_TOO_CROWDED=3
uint8 ADD_FAIL_OCCUPIED=4
uint8 DELETE_FAIL_NO_RESPONSE=5
uint8 DELETE_FAIL_EXCEED_QUANTITY=6
uint8 FAIL_OTHER_REASONS=7
uint8 response_code

ref: http://wiki.ros.org/srv#Service_Descr...

Update

Two_wheel_robot_service = rospy.Service("/morph_sim/two_wheel_robot_update", two_wheel_robot_update, twoWheelRobotUpdateCallback, (add_ model_client, delete_model_client, two_wheel_robot_urdf))

The last argument is the buffer size, which seems to take an integer type instead of a list. If it is not specified, the default value is 65536. Thus

Two_wheel_robot_service = rospy.Service("/morph_sim/two_wheel_robot_update", two_wheel_robot_update, twoWheelRobotUpdateCallback)

If you haven't tried it, could you please try

ref: http://wiki.ros.org/rospy/Overview/Se...

edit flag offensive delete link more

Comments

1

This did not work, it is still giving me the same error, even if I pass an empty two_wheel_robot_updateRequest message to the ServiceProxy it still throws the same error..

HatchEm27998 gravatar image HatchEm27998  ( 2021-04-11 09:07:32 -0500 )edit

Thank you for trying it. I've added a new idea.

miura gravatar image miura  ( 2021-04-11 09:17:13 -0500 )edit

But then how am I supposed to pass the additional parameters to the service callback function?

HatchEm27998 gravatar image HatchEm27998  ( 2021-04-11 09:23:43 -0500 )edit
1

The quickest way to do this is to make add_model_client, delete_model_client, and two_wheel_robot_urdf global variables and access them from the twoWheelRobotUpdateCallback.

I'm sure there are other ways to do this, but it is case by case.

miura gravatar image miura  ( 2021-04-11 09:29:00 -0500 )edit
1

Yes, I did this just before I got your reply, and it solved the problem THANK YOU SO MUCH!

HatchEm27998 gravatar image HatchEm27998  ( 2021-04-11 09:53:02 -0500 )edit
1

Congratulations.

miura gravatar image miura  ( 2021-04-11 09:57:31 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2021-04-10 17:35:30 -0500

Seen: 376 times

Last updated: Apr 11 '21