Inertial Sensor reading showing "inf"

I am using ARMS’s odometry to get the position of my robot, it works fine when I work with no sensor but when I plugged in the inertial sensor, the x became “-nan” and the y became “nan” and the heading became “inf”
I thought this could be a inertial problem so I try printing out the inertial sensor heading value as well, and it printed “inf”

What could be the problem?

Where are you seeing this printed? On the brain itself, or through your own code? If it’s your code, can you show the code you’re using to print out the values?

To debug I printed it out on both the brain screen and in the terminal, here’s the code:

void odom_debug() {
    pros::lcd::set_text(0, "X: " + std::to_string(arms::odom::getPosition().x));
    pros::lcd::set_text(1, "Y: " + std::to_string(arms::odom::getPosition().y));
    pros::lcd::set_text(2, "H: " + std::to_string(arms::odom::getHeading()));
    pros::lcd::set_text(
        3, "Left: " + std::to_string(arms::odom::getLeftEncoder()));
    pros::lcd::set_text(
        4, "Right: " + std::to_string(arms::odom::getRightEncoder()));
    pros::lcd::set_text(
        5, "Middle: " + std::to_string(arms::odom::getMiddleEncoder()));
    pros::lcd::set_text(
        6, "Inertial: " + std::to_string(drive::inertial.get_rotation()));
    std::cout << "Inertial: " << drive::inertial.get_heading() << std::endl;
}

I’m using ARMS library btw

So, up front, I have zero experience with any of the odometry code, and very little with pros, so I’m going off just basic programming knowledge here and digging into source and APIs. The below also assumes that you’ve pasted the code directly here from your source, and not re-typed it and left something off.

Looking at the pros API reference here for set_text, it calls out 3 parameters: row, col, and then the text. Your functions above are only calling a single digit and then giving the text. I would expect that you’re needing to put in the column value as well, and then you’ll get to the next step. I’m honestly a little surprised it’s compiling properly without you getting at least a warning, considering the minimum number of parameters are not met, and even more surprised that you’re not getting crashing behavior because of an overflow or some other condition.

Now, forecasting a little due to what I see on the API page, row has an expected value per the page of [0-2], so I’m not sure if your values above 2 are actually going to function. Maybe they do, and the API is not up-to-date/reflective of available usage.

Try adding the column value first and see if that doesn’t fix things.

1 Like

They are working, the code works fine when I set it up as no sensor, but prints nan and inf when I plug the inertial sensor in. I suppose it is a inertial problem rather than a printing problem, since the printing in the terminal is “inf” as well. Thanks for the help anyway :slight_smile:

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.