ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

request for member ‘__getMD5Sum’ in ‘m’, which is of non-class type ‘const float’ return m.__getMD5Sum().c_str();

asked 2019-11-12 07:44:37 -0500

mohamed19977 gravatar image

updated 2019-11-12 07:58:05 -0500

gvdhoorn gravatar image

my code :

#include "ros/ros.h"
#include "sensor_msgs/LaserScan.h"
#include "geometry_msgs/Twist.h"
#include <nav_msgs/GetMap.h>
#include <vector>
#include <nav_msgs/OccupancyGrid.h>
#include <nav_msgs/MapMetaData.h>
#include <std_msgs/Header.h>
#include <map>
#include <std_msgs/String.h>

//some global variables to "perceive" the world around the robot:
double front;
double right;
double left; 
bool robot_stopped;

// grid map

int rows;
int cols;
double mapResolution;
int currCell = 0;
std::vector<std::vector<float> > grid;    //vector of vectors 
ros::Publisher map_pub;


void laserCallback(const sensor_msgs::LaserScan::ConstPtr& msg)
    ROS_INFO("Received a LaserScan with %i samples", (int) msg->ranges.size() );

    //For simplicity, let's save the distance of the closer obstacle to the robot:
    front = *std::min_element (msg->ranges.begin()+80, msg->ranges.begin()+159);
    left = *std::min_element (msg->ranges.begin(), msg->ranges.begin()+79);
    right = *std::min_element (msg->ranges.begin()+160, msg->ranges.end());
    ROS_INFO("minimum front distance to obstacle: %f", front);
    ROS_INFO("minimum left distance to obstacle: %f", left);
    ROS_INFO("minimum right distance to obstacle: %f", right);

void mapCallback(const nav_msgs::OccupancyGrid::ConstPtr& msg)

// set Header that belong to std_msgs to header that exists in the supllied reference msg
  std_msgs::Header header = msg->header;

// set MapMeta Data that belong to std_msgs to information that exists in the supllied reference msg
  nav_msgs::MapMetaData info = msg->info;

  ROS_INFO("Received a %d X %d map @ %.3f m/px\n",info.width,info.height,info.resolution);

//assigning data to varibles 
 // nav_msgs::OccupancyGrid* new_grid = new nav_msgs::OccupancyGrid();

// Dynamically resize the grid from vector class it is resizing it accourding to laser range to make it rows = to cols

   for(int i = 0; i < rows; i++) 

//loop on all elements in the grid in order to allocate values due to data conversion   

    for(int i=0; i<info.width ; i++)
      for(int j=0; i<info.height ; j++)

       if(msg->data[currCell] == 0)

      // unoccupied cell
        grid[i][j] = 0;


      //occupied or unknown  
        grid[i][j] = 1; 


       // grid[i][j]=new_grid;




int main(int argc, char **argv){

  ros::init(argc, argv, "karina"); 

  ros::NodeHandle n;

  //Publisher for /cmd_vel and /map topics 
  ros::Publisher cmd_vel_pub = n.advertise<geometry_msgs::Twist>("cmd_vel", 100);
  ros::Publisher map_pub = n.advertise<nav_msgs::OccupancyGrid>("map",100);

  //Subscriber for /basescan which contains laserdata to drive robot and publish map
  ros::Subscriber laser_sub = n.subscribe("base_scan", 100, laserCallback);
  ros::Subscriber map_sub = n.subscribe("base_scan",100,mapCallback);

  ros::Rate loop_rate(10); //10 Hz

  geometry_msgs::Twist cmd_vel_msg;
  robot_stopped = false;
  front = 0.1;
  right =0.1;
  left = 0.1;
  int count = 0;
  while (ros::ok())

    //fill the "cmd_vel_msg" data according to some conditions (depending on laser data)
      ROS_INFO("Read: %f", front);

    //publish velocity commands:



  return 0;
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2019-11-12 07:59:23 -0500

gvdhoorn gravatar image

updated 2019-11-12 10:21:37 -0500

We see this:

std::vector<std::vector<float> > grid;    //vector of vectors 


void mapCallback(...)



int main(int argc, char **argv){

  ros::Publisher map_pub = n.advertise<nav_msgs::OccupancyGrid>("map",100);


you cannot publish(..) floats directly. That's what the error message is telling you.

edit flag offensive delete link more


so how can i fix it please

mohamed19977 gravatar image mohamed19977  ( 2019-11-12 08:04:36 -0500 )edit

map_pub is a Publisher of nav_msgs::OccupancyGrid. So you'll have to publish(..)nav_msgs::OccupancyGrid instances, not single floats.

gvdhoorn gravatar image gvdhoorn  ( 2019-11-12 10:22:13 -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


Asked: 2019-11-12 07:44:37 -0500

Seen: 2,806 times

Last updated: Nov 12 '19