Skip to content

Commit f2614f8

Browse files
authored
Merge pull request #12 from fmrico/occupancy_works
Occupancy works
2 parents 503f7d0 + cc84254 commit f2614f8

3 files changed

Lines changed: 27 additions & 7 deletions

File tree

navmap_ros/include/navmap_ros/conversions.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@
5757
namespace navmap_ros
5858
{
5959

60+
/**
61+
* @name Costmap value semantics
62+
* @brief Standardized occupancy/cost values used when projecting NavMap layers
63+
* onto a 2D grid (compatible with `costmap_2d` conventions).
64+
*
65+
* These constants follow the same meaning as in `costmap_2d`:
66+
* - `NO_INFORMATION` (255): Unknown or unobserved area.
67+
* - `LETHAL_OBSTACLE` (254): Non-traversable obstacle.
68+
* - `INSCRIBED_INFLATED_OBSTACLE` (253): Inside the robot’s inscribed radius.
69+
* - `MAX_NON_OBSTACLE` (252): Highest cost still considered traversable.
70+
* - `FREE_SPACE` (0): Known free space.
71+
* @{
72+
*/
73+
constexpr uint8_t NO_INFORMATION = 255;
74+
constexpr uint8_t LETHAL_OBSTACLE = 254;
75+
constexpr uint8_t INSCRIBED_INFLATED_OBSTACLE = 253;
76+
constexpr uint8_t MAX_NON_OBSTACLE = 252;
77+
constexpr uint8_t FREE_SPACE = 0;
78+
/** @} */ // end of Costmap value semantics group
79+
6080
// --------- NavMap <-> ROS message ---------
6181

6282
/**

navmap_ros/src/navmap_ros/conversions.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ using navmap_ros_interfaces::msg::NavMapSurface;
5353

5454
static inline uint8_t occ_to_u8(int8_t v)
5555
{
56-
if (v < 0) {return 255u;}
57-
if (v >= 100) {return 254u;}
58-
return static_cast<uint8_t>(std::lround((v / 100.0) * 254.0));
56+
if (v < 0) {return NO_INFORMATION;}
57+
if (v >= 100) {return LETHAL_OBSTACLE;}
58+
return static_cast<uint8_t>(std::lround((v / 100.0) * static_cast<double>(LETHAL_OBSTACLE)));
5959
}
6060

6161
static inline int8_t u8_to_occ(uint8_t u)
6262
{
63-
if (u == 255u) {return -1;}
64-
return static_cast<int8_t>(std::lround((u / 254.0) * 100.0));
63+
if (u == NO_INFORMATION) {return -1;}
64+
return static_cast<int8_t>(std::lround((u / static_cast<double>(LETHAL_OBSTACLE)) * 100.0));
6565
}
6666

6767
static inline navmap::NavCelId tri_index_for_cell(uint32_t i, uint32_t j, uint32_t W)

navmap_rviz_plugin/src/NavMapDisplay.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ inline Ogre::ColourValue colorFromRainbow(float value, float max_value, float al
7676

7777
inline Ogre::ColourValue colorFromU8(uint8_t v, float alpha)
7878
{
79-
if (v == 0) {return Ogre::ColourValue(0.5f, 0.5f, 0.5f, alpha);}
80-
if (v == 255) {return Ogre::ColourValue(0.0f, 0.39f, 0.0f, alpha);}
79+
if (v == 0) {return Ogre::ColourValue(1.0f, 1.0f, 1.0f, alpha);}
80+
if (v == 255) {return Ogre::ColourValue(0.25f, 0.25f, 0.25f, alpha);}
8181
if (v == 254) {return Ogre::ColourValue(0.0f, 0.0f, 0.0f, alpha);}
8282
float occ = static_cast<float>(v) / 253.0f;
8383
float c = 1.0f - occ;

0 commit comments

Comments
 (0)