Ask Your Question
0

Difference between Empty and None in Service messages

asked 2020-01-21 13:29:43 -0500

hrushi19 gravatar image

updated 2020-01-21 14:20:26 -0500

gvdhoorn gravatar image

I have created a client for the service /static_map. The static_map service uses the service message of type empty request and some response type.(by empty request,I mean no data type was mentioned in request) In the client that I created:

#!/usr/bin/env python
import rospy
from std_msgs.msg import Empty
from nav_msgs.srv import GetMap,GetMapRequest
rospy.init_node("my_caller")
rospy.wait_for_service("/static_map")
my_connector=rospy.ServiceProxy("/static_map",GetMap)
my_call=GetMapRequest()
result=my_connector(my_call)
print(result)

The above code works perfectly but when I replace the line my_call=GetMapRequest() to my_call=Empty(), I get an error. So is empty data type not equal to the blank data type of the service request?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2020-01-21 14:29:41 -0500

gvdhoorn gravatar image

updated 2020-01-24 05:22:45 -0500

This is the service definition of the service your are referring to (from nav_msgs/GetMap):

# Get the map as a nav_msgs/OccupancyGrid
---
nav_msgs/OccupancyGrid map

The part that gets transformed in the GetMapRequest type (the one you import from nav_msgs.srv) contains the fields in the upper part of the message definition (ie: above the ---).

The response would be the lower part (ie: below the ---).

The request part does indeed not contain any fields, just a single comment. So the request type is "empty", but only in the sense it does not contain any additional fields.

This is not the same as the std_msgs/Empty. This is an entirely different message type. It is called Empty, as it does not have any fields (from std_msgs/Empty):

 

Even though it does not contain any fields, this is a different message type, and it is not used for the request type of the GetMap service.

when I replace the line my_call=GetMapRequest() to my_call=Empty(), I get an error.

Yes. This is expected, as they are not the same types (GetMapRequest is the request type).

So is empty data type not equal to the blank data type of the service request?

Exactly.

But do note: "blank data type of the [GetMap] service request" is not a type. That would be GetMapRequest.

edit flag offensive delete link more

Comments

Thanks for your reply but I didn't use std_srvs/Empty, rather I used std_msgs/Empty which is not a service but a data type.

hrushi19 gravatar image hrushi19  ( 2020-01-24 05:12:54 -0500 )edit
1

That would not change my answer much. The underlying cause is that an empty service *Request is not the same type as any other message or service (so neither std_msgs/Empty nor std_srvs/EmptyRequest is the same type).

It's just how the typing system for topics and services (and actions) works.

gvdhoorn gravatar image gvdhoorn  ( 2020-01-24 05:19:23 -0500 )edit

Thanks a lot for ur help!!

hrushi19 gravatar image hrushi19  ( 2020-01-24 05:20:36 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2020-01-21 13:29:43 -0500

Seen: 91 times

Last updated: Jan 24