Skip to content

Precision issue in Sensor.cpp (float precision issue) #83

@runger1101001

Description

@runger1101001

The way the velocity is updated in the Sensor base class, and the fact that we are using a single 32 bit float to represent total angle in the first place means that motors using MagneticSensor (Halls and Encoders currently unaffected due to the way they calculate velocity in interrupts) stop after a certain number of turns (total angle).

This happens when the delta-angle being added is relatively so small compared to the total angle it is being added to, that the limited precision of float results in no numeric increase in the resulting sum float.
When this happens depends on the speed (the delta-angle's size) but seems to be around 30000 rad.

We have discussed this extensively, and opted for a solution where we store total revolutions (an integer value) and shaft angle (a float value) seperately, to ensure we have high precision no matter what the total angle.

The price of this is a slightly more complex interface to Sensors - users will have to consider the context of their operation, and ask for the angle in different ways (total angle or shaft angle) depending on the precision they need and what they're trying to do.
However, the change can be contained largely to the sensor base class, and may simplify the implementation of new sensors.

Metadata

Metadata

Assignees

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