I'm trying to assign a value in a callback function and I get error for undendifined reference.
I hava class UltrasonicSensors. I have my callback funtion as method and I try to assign the value of callback and then to use it in my method which has the subscriber. But I get this error:
/home/alex/catkin_ws/src/ros_ackerman_monster_truck/src/obstacle_avoidance/UltrasonicSensors.cpp:-1: error: undefined reference to `UltrasonicSensors::m_msg'
:-1: error: collect2: error: ld returned 1 exit status
Header file:
class UltrasonicSensors
{
public:
UltrasonicSensors() {}
~UltrasonicSensors(){}
static void u1_callback(const std_msgs::Int32& us_msg);
static void u2_callback(const std_msgs::Int32& us_msg);
static void u3_callback(const std_msgs::Int32& us_msg);
int ultrasonic(const char* topic_name);
static std_msgs::Int32 m_msg;
Cpp file::
#include "UltrasonicSensors.h"
#include <string.h>
void UltrasonicSensors::u1_callback(const std_msgs::Int32& us_msg)
{
ROS_INFO("[%i]efefefe" , us_msg.data );
m_msg = us_msg; // Here I want to assign the value of us_msg
}
void UltrasonicSensors::u2_callback(const std_msgs::Int32& us_msg)
{ROS_INFO("[%i]" , us_msg.data );}
void UltrasonicSensors::u3_callback(const std_msgs::Int32& us_msg)
{ROS_INFO("[%i]" , us_msg.data );}
int UltrasonicSensors::ultrasonic(const char* topic_name )
{
if(strcmp(topic_name,"ultrasonic_sensor_middle"))
m_sub->subscribe(m_subscriber, "ultrasonic_sensor_middle", m_nh, u1_callback);
else if(strcmp(topic_name,"ultrasonic_sensor_left"))
m_sub->subscribe(m_subscriber, "ultrasonic_sensor_left", m_nh, u2_callback);
else if(strcmp(topic_name,"ultrasonic_sensor_right"))
m_sub->subscribe(m_subscriber, "ultrasonic_sensor_right", m_nh, u3_callback);
else{ROS_ERROR("Invalid topic name for ultrasonic sensors!");}
return m_msg.data; //And return it here
}