Skip to content

Helpers

Eyal2679 edited this page Jun 11, 2025 · 5 revisions

What are the 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.

Rotational Sensor Helper

What it is

RotationalSensorHelper is a helper class design to help you manage your rotational sensors in a simplified way, and it provides more functionality such as velocity calculation, angle wrapping, offsets, and more.

Although some hardware vendor sensors provide some of this functionality through configurations, we don't want to rely on them, for 3 reasons:

  1. Different vendors' configurations may work in different ways.

  2. Some vendors lack said functionality in their configurations.

  3. You cannot rely on said configurations when using IO separation.

The RotationalSensorHelper also provides Tunables support.

Creating a RotationalSensorHelper

You can create a RotationalSensorHelper, as following:

RotationalSensorHelper rotationalSensor = new RotationalSensorHelper(double initialMeasuredAngle, double initialOffset)

Providing an initial offset is optional, with the offset defaulting to 0

You then need to update the RotationalSensorHelper periodically with the newest value from the sensor, for example:

gyroAngleDegreesCW.update(gyroIO.angle.getAsDouble());

Tip: When using a RotationalSensorHelper, save the measurement unit in the variable's name, so you won't forget the units you are measuring in, as RotationalSensorHelper doesn't provide a unit's support, for example: "GyroAngleDegreesCW" (CW stands for clock-wise)

Getting the angle and the velocity

You can get the angle by using:

rotationalSensor.getAngle()

You can also use getMeasuredAngle() in order to get the "raw" angle from the sensor

In order to get calculated velocity, use:

rotationalSensor.getVelocity();

Setting an angle wrapping

Angle wrapping ensures sensor angles stay within a desired range, such as [-180°, 180°) or [0°, 360°), even if the sensor reports values beyond a full rotation. This is useful when sensor values accumulate over time (e.g., showing 900° after 2.5 rotations) but you want to interpret it within a single rotation range.

In order to enable angle wrapping, you need to enable continuous warp:

rotationalSensor.enableContinuousWrap(double lowerBound, double upperBound);

For example:

gyroAngleDegreesCW.enableContinousWrap(0, 360);

This ensures the angle stays within [0°, 360°).

Note: We use software wrapping instead of relying on the sensor, to support IO separation.

Changing the offset

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);

We would like to hear from you

Do you have an idea for a helper class you would like us to add to the library? Would you like that we will include other helpers?

We welcome you to contact us

TODO: add contact page link

Clone this wiki locally