0
$\begingroup$

Rosanswers logo

Hi, I am trying to write a code, which uses nav_msgs's OccupancyGrid, to visualize the grid map like a potential field.

I'm inserting the probability of where an obstacle might move next into OccupancyGrid.data[]. data[] was declared as Int8 so I am inserting numbers from 0 to 100. I'm pretty sure that rviz should show each sell white or gray or black, but in my code some parts become red.

I want to add up the inserted data each time so that when multiple objects collide, the data[] becomes 100 and shows a black area. At the end of the program, I wrote a for loop so that when the value of data[] is over 100, that value becomes exactly 100.

Here's the part of the code where I'm having trouble with...

map.data[p + q_] += (int)(100 * (1 - sqrt((x-X)*(x-X) + (y-Y)*(y-Y))/R_d));

And to finalize the map.data[] I defined a global variable _LETHAL 100 and inserted it like below

if(map.data[i]>_LETHAL) map.data[i] = _LETHAL;

I apologize for making this confusing, it seems that I'm not able to upload my program or any image because I just registered today...

But will very appreciate for any help...! Thank you.


Originally posted by Shu on ROS Answers with karma: 36 on 2017-11-14

Post score: 0


Original comments

Comment by jayess on 2017-11-14:
Welcome! Code you please copy and paste your code here? It's actually better to do that vs. attaching it as a file.

Comment by jayess on 2017-11-14:
Also, no need to use <br> tags, you can just hit Enter to move to a new line. To enable syntax highlighting just copy & paste the code, highlight it, then click the 101010 (Preformatted Text) button.

Comment by Shu on 2017-11-14:
Hi jayess. Thank you so much for the advice! I'll keep them in mind when I ask another question here. I apparently figured it out! It seems that nav_msgs::OccupancyGrid's data value only receives up to 100. If it goes over that amount, it pushes out an error and I get weird visualized points.

Comment by Shu on 2017-11-14:
Thanks again for the support!

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

I apparently figured it out! It seems that nav_msgs::OccupancyGrid's data value only receives up to 100. If it goes over that amount, it pushes out an error and I get weird visualized points.


Originally posted by Shu with karma: 36 on 2017-11-14

This answer was ACCEPTED on the original site

Post score: 0

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.