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

how to convert from probabilty to occupancy grid message

asked 2020-10-11 06:18:52 -0500

MjdKassem gravatar image

updated 2020-10-11 06:20:20 -0500

Dears i am trying to create an occupancy grid message, so for that i have some float data represent the probability, I used std_msgs::Float32MultiArray with data[] field =

[1.0, 10.0, 0.10000000149011612, 3.0, 9.0, 0.20000000298023224, 3.0, 10.0, 0.1666666716337204, 4.0, 9.0, 0.23333333432674408, 6.0, 8.0, 0.2666666805744171, 6.0, 9.0, 0.03333333507180214]

as an example to represent that probability,where the first value "1.0" represent the height, the second value "10" represent the width and the third value represent the probability at that (1.0,10) cell, and so on for other values, i publish this message and in another node i create nav_msgs::OccupancyGrid grid_message with these info

    grid_message.info.height = 20;
    grid_message.info.width = 20;
    grid_message.info.resolution = 0.2;

and i use msg->data[y]*width + msg->data[x] to fill the data field of the occupancyGrid message, for example, at cell(1,10) the corresponding nav_msgs::OccupancyGrid.data index is (10*20+1) and in this index i store 0.10000000149011612 when i listen to the occupancyGrid message the data in nav_msgs::OccupancyGrid.data look like

data: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 11, 0, 17, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ...
(more)
edit retag flag offensive close merge delete

Comments

Without the code it might be hard to say.

JackB gravatar image JackB  ( 2020-10-11 08:50:18 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2020-10-11 09:23:22 -0500

miura gravatar image

Because the data of OccupancyGrid is of type int8, even if you assign a float32 type, it does not store the value as it should.

The solution is different depending on the purpose of using OccupancyGrid, but for example, the following can be used. Multiply the data in std_msgs::Float32MultiArray by 100, cast it to int8, and store it in the OccupancyGrid. Then divide it by 100 at the destination where it will be used.

ref: http://docs.ros.org/melodic/api/nav_m...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-10-11 06:18:52 -0500

Seen: 491 times

Last updated: Oct 11 '20