Odometry causing a segmentation error
Good afternoon, I have to control a differential drive robot. I had not to use the differential controller plugin, so i just implemented two velocity controllers and a joint state. I now have to compute odometry for my robot and I want to use my joint state as a velocity sensor for each wheel. So i would subscribe /joint_state, take the two velocities and the compute odometry from them and publish all on a /odom topic. The building works, but once i run this script in my ros network I have just some loops and then a core dump error when the callback is called. Could you help me, please? Here is my header file:
#include <ros/ros.h>
#include <tf/transform_broadcaster.h>
#include <nav_msgs/Odometry.h>
#include <sensor_msgs/JointState.h>
#include <math.h>
#include "boost/thread.hpp"
#include "tf/tf.h"
using namespace std;
class ODOM{
public:
ODOM();
void run();
void encoders_sub_callback (sensor_msgs::JointState msg);
void compute_odom ();
private:
ros::NodeHandle _nh;
float _wl;
float _wr;
long double _x;
long double _y;
long double _th;
bool _first_odom;
ros::Subscriber _encoders_sub;
ros::Publisher _odom_pub;
};
and here my cpp file:
#include "odom.h"
ODOM::ODOM(){
_encoders_sub = _nh.subscribe("joint_states", 1, &ODOM::encoders_sub_callback, this);
_odom_pub = _nh.advertise<nav_msgs::Odometry>("/odom",1);
_wl=0.0;
_wr=0.0;
_x=0.0;
_y=0.0;
_th=0.0;
_first_odom=false;
}
//here it happens the segmentation fault
void ODOM::encoders_sub_callback(sensor_msgs::JointState msg){
cout<<"callback"<<endl;
_wl= msg.velocity[0];
cout<<_wl<<endl;
_wr=msg.velocity[1];
cout<<_wr<<endl;
}
//the computing odom function//...
... and then...
void ODOM::run(){
boost::thread odom_t( &ODOM::compute_odom, this);
ros::spin();
}
int main(int argc, char** argv){
ros::init(argc,argv, "odom_node");
ODOM odom;
odom.run();
return 0;
}
please!! It's very important
@iopoi97 Please don't make noise to try to get responses. It's considered bad etiquette. Please see our support guidelines: http://wiki.ros.org/Support
The more help you can provide the easier it is to help you. Have you tried to get a backtrace from the crash? Have you tried attaching a debugger? Have you tried disabling parts of your system to isolate which line is causing the problem? The more you can isolate the problem the easier it is for someone to understand what your mistake is. Right now you've dumped a lot of code here without enough information to fully reproduce your problem so if someone is going to try to help you they need to read through all the code, and then guess at what assumptions your making and how your setting up your environment. Then take an educated guess at the problem.
The ...(more)
I'm very sorry. I debugged just printing messages between code lines. As said the segmentation fault happens when the encoders_sub_callback is called. I edited my post suppressing the compute odometry part. it's a simple Runge Kutta integration on the heading and steering velocities retrieved from the left and right wheels velocities.