Skip to content

Odom::update_position() - orientation_delta_rad should be properly bounded #17

@NixRobotics

Description

@NixRobotics

There seems to be a bug in the orientation code at the start of the Odom::position_update() routine. If the robot is more or less heading straight at 0 degrees, the current code will swing backwards and forwards between 359.xxxx and 0.yyyy (where xxxx and yyyy are some fractional digits). The current code will therefore result in an erroneously large orientation_delta_rad value when there is a zero crossing (eg.
prev=359.5deg,
current=0.5deg,
delta = -359deg
Of course what you want in this case is 1deg. The result is that the local position calculation generates incorrect results.

Keeping as much of the current logic as is, one potential fix is to do this:

orientation_rad = to_rad(reduce_negative_180_to_180(orientation_deg));
prev_orientation_rad = to_rad(reduce_negative_180_to_180(this->orientation_deg));
orientation_delta_rad = reduce_negative_PI_to_PI(orientation_rad - prev_orientation_rad); // new function reduce_negative_PI_to_PI()

Doing the two reductions for orientation_rad and prev_orientation_rad may not be needed, but these are used to calculate the average orientation (global_polar_angle) later so I added these in for now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions