|
ReduxLib C++ 2026.1.2
|
#include <Canandgyro.h>


Public Member Functions | |
| Canandgyro (int canID, std::string bus="halcan") | |
| frc::Quaternion | GetQuaternion () |
| frc::Rotation3d | GetRotation3d () |
| frc::Rotation2d | GetRotation2d () |
| void | UseDedicatedYawAngleFrame (bool use) |
| units::turn_t | GetYaw () |
| units::turn_t | GetMultiturnYaw () |
| units::turn_t | GetPitch () |
| units::turn_t | GetRoll () |
| units::turns_per_second_t | GetAngularVelocityRoll () |
| units::turns_per_second_t | GetAngularVelocityPitch () |
| units::turns_per_second_t | GetAngularVelocityYaw () |
| units::standard_gravity_t | GetAccelerationX () |
| units::standard_gravity_t | GetAccelerationY () |
| units::standard_gravity_t | GetAccelerationZ () |
| void | StartCalibration () |
| bool | IsCalibrating () |
| bool | WaitForCalibrationToFinish (units::second_t timeout) |
| bool | SetPoseRPY (units::turn_t newRoll, units::turn_t newPitch, units::turn_t newYaw, units::second_t timeout=20_ms, uint32_t retries=5) |
| bool | SetPoseR3D (frc::Rotation3d newPose, units::second_t timeout=20_ms, uint32_t retries=5) |
| bool | SetPose (frc::Quaternion newPose, units::second_t timeout=20_ms, uint32_t retries=5) |
| bool | SetYaw (units::turn_t yaw, units::second_t timeout=20_ms, uint32_t retries=5) |
| CanandgyroFaults | GetStickyFaults () |
| CanandgyroFaults | GetActiveFaults () |
| units::celsius_t | GetTemperature () |
| CanandgyroStatus | GetStatus () |
| void | ClearStickyFaults () |
| void | SetPartyMode (uint8_t level) |
| CanandgyroSettings | GetSettings (units::second_t timeout=350_ms, units::second_t missingTimeout=20_ms, uint32_t attempts=3) |
| void | StartFetchSettings () |
| CanandgyroSettings | GetSettingsAsync () |
| CanandgyroSettings | SetSettings (CanandgyroSettings &settings, units::second_t timeout=20_ms, uint32_t attempts=3) |
| CanandgyroSettings | ResetFactoryDefaults (units::second_t timeout=350_ms) |
| redux::canand::CanandSettingsManager< CanandgyroSettings > & | GetInternalSettingsManager () |
| redux::frames::Frame< units::turn_t > & | GetYawFrame () |
| redux::frames::Frame< units::turn_t > & | GetMultiturnYawFrame () |
| redux::frames::Frame< frc::Quaternion > & | GetAngularPositionFrame () |
| redux::frames::Frame< AngularVelocity > & | GetVelocityFrame () |
| redux::frames::Frame< Acceleration > & | GetAccelerationFrame () |
| redux::frames::Frame< CanandgyroStatus > & | GetStatusFrame () |
| void | HandleMessage (redux::canand::CanandMessage &msg) override |
| redux::canand::CanandAddress & | GetAddress () override |
| std::string | GetDeviceClassName () override |
| redux::canand::CanandFirmwareVersion | GetMinimumFirmwareVersion () override |
Public Member Functions inherited from redux::canand::CanandDevice | |
| bool | IsConnected (units::second_t timeout=2_s) |
| std::string | GetDeviceName () |
| virtual void | PreHandleMessage (CanandMessage &msg) |
| virtual void | CheckReceivedFirmwareVersion () |
| bool | SendCANMessage (uint8_t apiIndex, uint8_t *data, uint8_t length) |
| template<std::size_t len> requires (len < 8U) | |
| void | SendCANMessage (uint8_t msgId, std::span< std::byte, len > data) |
Protected Attributes | |
| redux::frames::Frame< bool > | calibrating {false, 0_ms} |
| redux::frames::Frame< units::turn_t > | singleYaw {0.0_tr, 0_ms} |
| redux::frames::Frame< units::turn_t > | multiYaw {0.0_tr, 0_ms} |
| redux::frames::Frame< frc::Quaternion > | quat {frc::Quaternion(), 0_ms} |
| redux::frames::Frame< AngularVelocity > | vel {AngularVelocity{0_tps, 0_tps, 0_tps}, 0_ms} |
| redux::frames::Frame< Acceleration > | accel {Acceleration{0_SG, 0_SG, 0_SG}, 0_ms} |
| redux::frames::Frame< CanandgyroStatus > | status {CanandgyroStatus{0, 0, false, 30_degC}, 0_ms} |
| redux::canand::CanandSettingsManager< CanandgyroSettings > | stg {*this} |
Class for the CAN interface of the canandgyro.
The C++ vendordep uses the units library for all dimensioned values, including settings.
Operations that receive data from the device (position, velocity, faults, temperature) generally do not block. The object receives data asynchronously from the CAN packet receive thread and reads thus return the last data received.
Operations that set settings or change offsets will generally wait for up to 20ms by default as they will usually wait for a confirmation packet to be received in response – unless the blocking timeout is set to zero, in which case the operation swill not block.
Example code:
| redux::sensors::canandgyro::Canandgyro::Canandgyro | ( | int | canID, |
| std::string | bus = "halcan" |
||
| ) |
Constructor with the device's id. This object will be constant with respect to whatever CAN id assigned to it, so if a device changes id it may change which device this object reads from.
| canID | the device id to use |
| bus | the message bus to use. Defaults to "halcan". |
| void redux::sensors::canandgyro::Canandgyro::ClearStickyFaults | ( | ) |
Clears sticky faults.
It is recommended to clear this during initialization, so one can check if the encoder loses power during operation later.
This call does not block, so it may take up to the next status frame (default every 1000 ms) for the sticky faults to be updated.
|
inline |
Returns the current acceleration frame, which includes CAN timestamp data.
|
inline |
Gets the linear acceleration along the X axis.
|
inline |
Gets the linear acceleration along the Y axis.
|
inline |
Gets the linear acceleration along the Z axis.
|
inline |
Fetches active faults. Active faults are only active for as long as the error state exists.
|
overridevirtual |
Returns the reference to the CanandAddress representing the combination of CAN bus and CAN device ID that this CanandDevice refers to.
Implementing device subclasses should likely construct a new CanandAddress in their constructor and return it here.
Implements redux::canand::CanandDevice.
|
inline |
Returns the current angular position frame, which includes CAN timestamp data.
|
inline |
Gets the angular velocity along the pitch (Y) axis.
|
inline |
Gets the angular velocity along the roll (X) axis.
|
inline |
Gets the angular velocity along the yaw (Z) axis.
|
inlineoverridevirtual |
Returns a canonical class-wide device name.
Reimplemented from redux::canand::CanandDevice.
|
inline |
Returns the CanandSettingsManager associated with this device.
The CanandSettingsManager is an internal helper object. Teams are typically not expected to use it except for advanced cases (e.g. custom settings wrappers)
|
inlineoverridevirtual |
Returns the minimum firmware version this vendordep requires.
Reimplemented from redux::canand::CanandDevice.
|
inline |
Gets a multi-turn yaw (Z-axis) rotation that tracks to multiple continuous rotations.
Note that this relies on the dedicated multi-turn yaw packet so if it is disabled via setYawFramePeriod it will not return fresh data.
|
inline |
Returns the current multi-turn yaw frame, which includes CAN timestamp data. redux::canand::FrameData objects are immutable.
|
inline |
Gets the pitch (Y-axis) rotation from [-0.5 rotations inclusive..0.5 exclusive).
|
inline |
Gets a quaternion object of the gyro's 3d rotation from the zero point
|
inline |
Gets the roll (X-axis) rotation from [-0.5 rotations inclusive..0.5 exclusive).
|
inline |
Gets an frc::Rotation2d object representing the rotation around the yaw axis from the zero point If you just want Z-axis rotation use GetYaw().
|
inline |
Gets an frc::Rotation3d object of the gyro's 3d rotation from the zero point If you just want Z-axis rotation use GetYaw().
|
inline |
Fetches the device's current configuration in a blocking manner.
This method works by requesting the device first send back all settings, and then waiting for up to a specified timeout for all settings to be received by the robot controller. If the timeout is zero, this step is skipped.
If there are settings that were not received by the timeout, then this function will attempt to individually fetched each setting for up to a specified number of attempts. If the fresh argument is true and the timeout argument is 0, then only this latter step runs, which can be used to only fetch settings that are missing from the known settings cache returned by GetSettingsAsync.
The resulting set of known (received) settings is then returned, complete or not.
This function blocks, so it is best to put this in init routines rather than a main loop.
Advanced users can use this function to retry settings missed from StartFetchSettings:
| timeout | maximum number of seconds to wait for a settings operation before timing out (default 350_ms) |
| missingTimeout | maximum number of seconds to wait for each settings retry before giving up |
| attempts | number of attempts to try and fetch values missing from the first pass |
|
inline |
Non-blockingly returns a CanandgyroSettings object of the most recent known settings values received from the encoder.
Most users will probably want to use canandgyro::GetSettings() instead.
One can call this after a Canandgyro::StartFetchSettings() call, and use CanandgyroSettings::AllSettingsReceived() to check if/when all values have been seen. As an example:
If this is called after Canandgyro::SetSettings(), this method will return a settings object where only the fields where the device has echoed the new values back will be populated. To illustrate this, consider the following:
|
inline |
Get the contents of the previous status packet, which includes active faults, sticky faults, and temperature.
|
inline |
Returns a handle to the current status frame, which includes CAN timestamp data.
|
inline |
Fetches sticky faults. Sticky faults are the active faults, except once set they do not become unset until ClearStickyFaults() is called.
|
inline |
Get onboard encoder temperature readings in degrees Celsius.
|
inline |
Returns the current angular velocity frame, which includes CAN timestamp data.
|
inline |
Gets the yaw (Z-axis) rotation from [-0.5 rotations inclusive..0.5 exclusive).
This is probably the function you want to use for applications like field-centric control.
|
inline |
Returns the current single-turn yaw frame, which includes CAN timestamp data. redux::canand::FrameData objects are immutable.
|
overridevirtual |
A callback called when a Redux CAN message is received and should be parsed. Subclasses of CanandDevice should override this to update their internal state accordingly.
HandleMessage will be called on all Redux CAN packets received by the vendordep that match the CanandAddress returned by CanandDevice::GetAddress().
| msg | a reference to a CanandMessage representing the received message. The message may not have lifetime outside the function call. |
Implements redux::canand::CanandDevice.
|
inline |
Returns if the Canandgyro is known to be currently calibrating.
|
inline |
Resets the encoder to factory defaults, and then wait for all settings to be broadcasted back.
| timeout | how long to wait for the new settings to be confirmed by the encoder in seconds (suggested at least 0.35 seconds) |
| void redux::sensors::canandgyro::Canandgyro::SetPartyMode | ( | uint8_t | level | ) |
Controls "party mode" – an encoder identification tool that blinks the onboard LED various colors if level != 0.
This function does not block.
| level | the party level value to set. |
| bool redux::sensors::canandgyro::Canandgyro::SetPose | ( | frc::Quaternion | newPose, |
| units::second_t | timeout = 20_ms, |
||
| uint32_t | retries = 5 |
||
| ) |
Sets a new pose without recalibrating with an frc::Quaternion.
| newPose | new quaternion pose |
| timeout | the timeout in seconds to wait for a pose set confirmation. Set to 0 to not check (always return true.) |
| retries | the number of retries for the set pose operation. |
|
inline |
Sets a new angular position without recalibrating with an frc::Rotation3d.
| newPose | new rotation3d pose |
| timeout | the timeout in seconds to wait for a pose set confirmation. Set to 0 to not check (always return true.) |
| retries | the number of retries for the set pose operation. |
|
inline |
Sets a new angular position pose without recalibrating with a given roll/pitch/yaw. If you just want to set yaw, use SetYaw.
| newRoll | new roll (x) pose |
| newPitch | new pitch (y) pose |
| newYaw | new yaw (z) pose |
| timeout | the timeout in seconds to wait for a pose set confirmation. Set to 0 to not check (always return true.) |
| retries | the number of retries for the set pose operation. |
|
inline |
Applies the settings from a CanandgyroSettings object to the Canandgyro. For more information, see the CanandgyroSettings class documentation.
Example:
| settings | the CanandgyroSettings to update the encoder with |
| timeout | maximum time in seconds to wait for each setting to be confirmed. (default 0.020s, set to 0 to not check and not block). |
| attempts | the maxinum number of attempts to write each individual settings |
| bool redux::sensors::canandgyro::Canandgyro::SetYaw | ( | units::turn_t | yaw, |
| units::second_t | timeout = 20_ms, |
||
| uint32_t | retries = 5 |
||
| ) |
Sets a new yaw without recalibrating the Canandgyro. Blocks for up to 50 milliseconds by default to confirm the transaction.
| yaw | new yaw angle in rotations |
| timeout | the timeout in seconds to block to confirm the transaction (set 0 to not block) |
| retries | the number of retries for the set pose operation. |
| void redux::sensors::canandgyro::Canandgyro::StartCalibration | ( | ) |
Begins calibration on the Canandgyro.
This takes several seconds. To check the state of calibration, use IsCalibrating or WaitForCalibrationToFinish.
|
inline |
Tells the Canandgyro to begin transmitting its settings; once they are all transmitted (after ~200-300ms), the values can be retrieved through the Canandgyro::GetSettingsAsync() function call
|
inline |
Sets whether this object should use the dedicated yaw message for yaw angle instead of deriving it from the pose quaternion frame.
By default this is true, as the yaw angle frame is more precise and by default more frequent.
| use | use the yaw angle |
| bool redux::sensors::canandgyro::Canandgyro::WaitForCalibrationToFinish | ( | units::second_t | timeout | ) |
Blocks the current thread until the Canandgyro has finished calibrating or until a timeout is reached.
| timeout | the timeout in seconds to wait for a calibration confirmation. |
|
protected |
internal Frame variable holding current acceleration state
|
protected |
internal Frame variable used to track if the device is calibrating
|
protected |
internal Frame variable holding current yaw position state
|
protected |
internal Frame variable holding current angular position state
|
protected |
internal Frame variable holding current yaw position state
|
protected |
internal Frame variable holding current status value state
|
protected |
internal settings manager
|
protected |
internal Frame variable holding current angular velocity state