request for member ‘__getMD5Sum’ in ‘m’, which is of non-class type ‘const float’ return m.__getMD5Sum().c_str();
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<geometry_msgs/Pose.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
rows=info.width;
cols=info.height;
mapResolution=info.resolution;
// 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
grid.resize(rows);
for(int i = 0; i < rows; i++)
{
grid[i].resize(cols);
}
//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;
else
//occupied or unknown
grid[i][j] = 1;
currCell++;
// grid[i][j]=new_grid;
map_pub.publish(grid[i][j]);
}
}
}
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
//initializations:
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:
cmd_vel_pub.publish(cmd_vel_msg);
ros::spinOnce();
loop_rate.sleep();
}
return 0;
}