I'd like to publish a subscriber code.
I get this kind of error.I don't know. Please help me.
/home/jo/catkin_ws/src/rplidar_ros/src/client.cpp: In constructor ‘SubscribeAndPublish::SubscribeAndPublish()’:
/home/jo/catkin_ws/src/rplidar_ros/src/client.cpp:12:62: error: ‘callback’ is not a member of ‘SubscribeAndPublish’
sub_ = n_.subscribe("/scan",1, &SubscribeAndPublish::callback, this);
^~~~~~~~
/home/jo/catkin_ws/src/rplidar_ros/src/client.cpp: In member function ‘void SubscribeAndPublish::scanCallback(const ConstPtr&)’:
/home/jo/catkin_ws/src/rplidar_ros/src/client.cpp:21:17: error: ‘scan’ was not declared in this scope
int count = scan->scan_time / scan->time_increment;
^~~~
/home/jo/catkin_ws/src/rplidar_ros/src/client.cpp:21:17: note: suggested alternative: ‘scanf’
int count = scan->scan_time / scan->time_increment;
^~~~
scanf
/home/jo/catkin_ws/src/rplidar_ros/src/client.cpp: In function ‘int main(int, char**)’:
/home/jo/catkin_ws/src/rplidar_ros/src/client.cpp:43:78: error: ‘scanCallback’ was not declared in this scope
Subscriber sub = n.subscribe<sensor_msgs::LaserScan>("/scan", 1000, scanCallback);
^~~~~~~~~~~~
rplidar_ros/CMakeFiles/rplidarNodeClient.dir/build.make:62: recipe for target 'rplidar_ros/CMakeFiles/rplidarNodeClient.dir/src/client.cpp.o' failed
make[2]: *** [rplidar_ros/CMakeFiles/rplidarNodeClient.dir/src/client.cpp.o] Error 1
CMakeFiles/Makefile2:507: recipe for target 'rplidar_ros/CMakeFiles/rplidarNodeClient.dir/all' failed
make[1]: *** [rplidar_ros/CMakeFiles/rplidarNodeClient.dir/all] Error 2
Makefile:140: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j4 -l4" failed
This is the code I wrote.
#include "ros/ros.h"
#include "sensor_msgs/LaserScan.h"
class SubscribeAndPublish
{
public:
SubscribeAndPublish()
{
pub_ = n_.advertise<sensor_msgs::LaserScan>("/scan",1);
sub_ = n_.subscribe("/scan",1, &SubscribeAndPublish::callback, this);
}
#define RAD2DEG(x) ((x)*180./M_PI)
void scanCallback(const sensor_msgs::LaserScan::ConstPtr& input)
{
sensor_msgs::LaserScan output;
int count = scan->scan_time / scan->time_increment;
ROS_INFO("I heard a laser scan %s[%d]:", scan->header.frame_id.c_str(), count);
ROS_INFO("angle_range, %f, %f", RAD2DEG(scan->angle_min), RAD2DEG(scan->angle_max));
for(int i = 0; i < count; i++) {
float degree = RAD2DEG(scan->angle_min + scan->angle_increment * i);
ROS_INFO(": [%f, %f]", degree, scan->ranges[i]);
}
pub_.publish(output);
}
private:
ros::NodeHandle n_;
ros::Publisher pub_;
ros::Subscriber sub_;
};
int main(int argc, char **argv)
{
ros::init(argc, argv, "rplidar_node_client");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe<sensor_msgs::LaserScan>("/scan", 1000, scanCallback);
SubscribeAndPublish SAPObject;
ros::spin();
return 0;
}