ReduxLib C++ 2024.3.2
|
#include <Canandgyro.h>
Public Member Functions | |
Canandgyro (int canID) | |
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) |
bool | SetPoseR3D (frc::Rotation3d newPose, units::second_t timeout=20_ms) |
bool | SetPose (frc::Quaternion newPose, units::second_t timeout=20_ms) |
bool | SetYaw (units::turn_t yaw, units::second_t timeout=20_ms) |
CanandgyroFaults | GetStickyFaults () |
CanandgyroFaults | GetActiveFaults () |
units::celsius_t | GetTemperature () |
CanandgyroStatus | GetStatus () |
void | ClearStickyFaults () |
void | SetPartyMode (uint8_t level) |
Public Member Functions inherited from redux::canand::CanandDevice | |
virtual void | HandleMessage (CanandMessage &msg)=0 |
virtual CanandAddress & | GetAddress ()=0 |
bool | IsConnected (units::second_t timeout=2_s) |
virtual std::string | GetDeviceClassName () |
std::string | GetDeviceName () |
virtual void | PreHandleMessage (CanandMessage &msg) |
virtual void | CheckReceivedFirmwareVersion () |
virtual CanandFirmwareVersion | GetMinimumFirmwareVersion () |
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 | ) |
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 |
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 |
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.
|
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.
|
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 |
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 |
Get the contents of the previous status packet, which includes active faults, sticky faults, and temperature.
|
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 |
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 if the Canandgyro is known to be currently calibrating.
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 |
||
) |
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.) |
|
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.) |
|
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.) |
bool redux::sensors::canandgyro::Canandgyro::SetYaw | ( | units::turn_t | yaw, |
units::second_t | timeout = 20_ms |
||
) |
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) |
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 |
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