0
$\begingroup$

Rosanswers logo

Hello folks,

I am making an odometry node for an omnidirectional robot using mechanum wheels. I've followed the tutorial on the ROS wiki, making changes as needed for my particular robot. The problem is that while I get values for the twist values, I get NaN for the pose. You can find the code here. I've tried debugging my code, and I get values up to the delta_th line. When I look at x, y, and th though that is where I get NaN. The variable types match, so that shouldn't be a problem. When I try adding a constant (1 and 1.0) instead of the delta then I do get a value returned. I am unsure why this is. Can anyone see what I am doing wrong?

Thanks,


Originally posted by Icehawk101 on ROS Answers with karma: 955 on 2014-08-11

Post score: 1


Original comments

Comment by bvbdort on 2014-08-11:
did you if dt_front, dt_rear are getting zero ?

Comment by Icehawk101 on 2014-08-11:
I checked that, they are getting values.

Comment by Tom Moore on 2014-08-11:
Why not just add a lot of ROS_INFO_STREAM statements before and after every calculation until you find the culprit? Also, just from a "good practices" standpoint, you really should initialize the variables in lines 6 - 11 in your main function (before you subscribe to any callbacks).

Comment by Icehawk101 on 2014-08-11:
dt_front: 0.999999 dt_rear: 0.999926 v_w1: 0.122492 v_w2: -0.119761 v_w3: 0.119651 v_w4: -0.117248 avg_dt: 0.999963 vx before: 0.000160434 vx after: 0.000160434 vy before: -0.0149735 vy after: -0.0149735 vth before: -2.32918e-05 vth after: -2.32918e-05

Comment by Icehawk101 on 2014-08-11:
delta_x: 0.000160428 delta_y: -0.0149729 delta_th: -2.32909e-05 x before: -nan x after: -nan y before: -nan y after: -nan th before: nan th after: nan

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

Well, your x and y "before" values are -nan. Adding anything to nan will still yield nan. If I had to guess, you are going through one loop iteration before your callbacks actually receive any data.

Also, consider this bit of code:

while(n.ok())
    {
        ros::spinOnce();               // check for incoming messages
        fr_enc = n.subscribe("front_encoders", 1, feCallBack);
        rr_enc = n.subscribe("rear_encoders", 1, reCallBack);

You are repeatedly subscribing to the topics for every loop iteration. Move lines 56 and 57 out of the while loop:

fr_enc = n.subscribe("front_encoders", 1, feCallBack);
rr_enc = n.subscribe("rear_encoders", 1, reCallBack);

while(n.ok())
    {
        ros::spinOnce();               // check for incoming messages

Originally posted by Tom Moore with karma: 13689 on 2014-08-11

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by Icehawk101 on 2014-08-11:
More or less what the guy in my lab did :P

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.