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

Messages with an element that may not be present in the scene

asked 2022-07-26 09:42:38 -0500

thibd gravatar image

Hi,

I'm creating a message that describes a vision result, where an element to grasp that may or may not be present in the scene.

# The timestamp of the capture
int timestamp 0
# Scene elements
Solid object_to_grasp
bool found_an_object_to_grasp
Solid[] obstacles
# Current pose
geometry_msgs/Pose current_tcp_pose
float64[] current_joints_pose

The solid is a complex type:

geometry_msgs/Pose center
geometry_msgs/Pose grasp_pose
Voxel[] voxels
float64 confidence

The issue with my message is that the "object_to_grasp" parameter cannot be filled if no object was found.

I'm not sure of what will happen if I feed None in the python interface of the client:

self.request:Scene.Request = Scene.Request()
request.object_to_grasp = None

And then send that to the server...

Will the code crash? Will the server find it and return None ?

Can I use this design, or shall I use a design with 2 distinct messages, with and without the object to grasp?

Thanks

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-07-26 14:08:46 -0500

ChuiV gravatar image

First off, rclpy will throw an exception if you try to send an object who's type does not match the type expected in the message definition.

Regarding the "optional" field, the msg syntax allows specifying size constraints on array types. Using that, I could do something like:

int32 timestamp
Solid[<=1] object_to_grasp
Solid[] obstacles
geometry_msgs/Pose current_tcp_pose
float64[] current_joints_pose

This way 'object_to_grasp' can have either 0 or 1 elements in it. If it's present, you can use it, if not, then there's nothing there anyways.

See https://docs.ros.org/en/humble/Concep... for more on the array types.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2022-07-26 09:42:38 -0500

Seen: 37 times

Last updated: Jul 26 '22