-
Notifications
You must be signed in to change notification settings - Fork 0
Helpers
The helper classes are a collection of generic utilities designed to perform specific tasks, such as managing a rotational sensor. They do not relate to each other. Currently, there is only one such helper class included in the library, although we consider adding more in the future.
RotationalSensorHelper is a helper class designed to help you manage rotational sensors such as encoders and gyros in a simplified way, and provides
functionality such as velocity calculation, angle wrapping, offsets, and more.
Although some hardware vendor sensors provide some of this functionality through configurations, we think it is better not to rely on them for 3 main reasons:
- Different vendors' configurations may work in different ways.
- Some vendors lack functionality in their configurations.
- Having configurations outside the IO layer allows more control in replay.
The
RotationalSensorHelperalso providesTunablesupport
You can create a RotationalSensorHelper as follows:
RotationalSensorHelper sensorHelper = new RotationalSensorHelper(double initialMeasuredAngle, double initialOffset)Providing an initial offset is optional, with a default of 0
You then need to update the RotationalSensorHelper periodically with the new value from the sensor, for example:
sensorHelper.update(gyroIO.angle.getAsDouble());You can get the angle by using:
rotationalSensor.getAngle()You can also use
getMeasuredAngle()in order to get the "raw" angle from the sensor
To get the velocity, use:
rotationalSensor.getVelocity();Angle wrapping normalizes an angle to stay within a fixed range, for example, -180° to 180°. This is useful when sensor values grow beyond a single rotation, but you want to treat them as within one cycle for logic or control. For example, wrapping 380° to the range of [0°, 360°] will give 20°, and -20° will result in 340°. This can also be useful when working with sensors that already have a specific range, such as absolute encoders, where you might want to move the range. For example, if you have an arm with an absolute encoder of range [0°, 360°], but you don't want that moving the arm below 0° will jump back to 360°, and you know the arm will never go below -140° you can set a new range such as [-150°, 230°], allowing the arm to move freely without worrying about the value suddenly jumping.
To enable angle wrapping, enable continuous wrap by providing the lower and upper bounds:
rotationalSensor.enableContinuousWrap(double lowerBound, double upperBound);You can change the offset by calling:
rotationalSensor.setOffset(double offset);You can also reset the current angle, which effectively changes the current offset to a new value such that the angle will be identical to the new angle:
rotationalSensor.resetAngle(double newAngle);Do you have an idea for a helper class you would like us to add to the library? Would you like us to include other helpers?
We welcome you to contact us