Canandgyro Settings¶
The CanandgyroSettings object is used to reconfigure the Canandgyro.
Creation¶
// Create with no values
// Only values that are changed will be updated on the device
Canandgyro.Settings settings = new Canandgyro.Settings();
// Make a copy of an existing CanandgyroSettings object.
Canandgyro.Settings copiedSettings = new Canandgyro.Settings(settings);
// Create with no values
// Only values that are changed will be updated on the device
CanandgyroSettings settings{}
// Make a copy of an existing CanandgyroSettings object.
CanandgyroSettings copiedSettings{settings};
Values are fetched and updated using the getters and setters of the object.
Important
Only values updated by the user are changed on the device. Values that are not changed will remain untouched.
Writing Settings To The Canandgyro¶
When you are ready to send and save the settings to the device, you can use Canandgyro.setSettings
to transmit the contents of a CanandgyroSettings object to the Canandgyro.
// A Canandgyro object with CAN ID 0
Canandgyro Canandgyro = new Canandgyro(0);
// Create a new settings object and add a value to set
Canandgyro.Settings settings = new Canandgyro.Settings();
// set frame period to 20ms
settings.setAngularPositionFramePeriod(0.02);
// Write the settings to the Canandcolor with a timeout of 50 milliseconds per setting.
// By default the settings will be written to flash -- they will persist on reboots.
// If this is not desired, one can use
//
// settings.setEphemeral(true);
//
// to flag the settings as ephemeral (and not persist in flash on reboot).
Canandgyro.setSettings(settings, 0.050);
// A Canandgyro object with CAN ID 0
Canandgyro canandgyro{0};
// Create a new settings object and add a value to set
CanandgyroSettings settings{};
// set frame period to 20ms
settings.SetAngularPositionFramePeriod(0.02_s);
// Write the settings to the Canandcolor with a timeout of 50 milliseconds per setting.
// By default the settings will be written to flash -- they will persist on reboots.
// If this is not desired, one can use
//
// settings.setEphemeral(true);
//
// to flag the settings as ephemeral (and not persist in flash on reboot).
canandgyro.SetSettings(settings, 0.050_s);
Fetching Settings From Device¶
Settings can be fetched from the end device in both a synchronous and asychronous manner. Due to the synchronous method blocking for 0.15-0.25 seconds, it is recommended to use it only in initialization routines for an autonomous or teleop program.
getSettings will return an empty Optional (in Java) or std::nullopt (in C++) if the fetch times out before the device responds.
The method allSettingsReceived in the CanandgyroSettings object can be used to determine if all settings have been fetched when working with async settings fetch.
In addition, if getSettingsAsync is called after updating a Canandgyro’s settings, it will be populated with the fields that have been echoed by the device in its settings confirmation messages. For example, if the status frame is changed from 1 second to 2 seconds, repeated calls to getSettingsAsync will first returns either -1 in Java or nullopt in c++ for the status frame time, until confirmation that the status frame time has been updated, at which point the field will change to 2 seconds (the value set before).
Synchronous (blocking)
// A Canandgyro object with CAN ID 0
Canandgyro canandgyro = new Canandgyro(0);
// Fetch this Canandgyro's settings.
// This runs with a default timeout of 0.35 seconds.
Canandgyro.Settings settings = canandgyro.getSettings();
// Fetch this Canandgyro's settings.
// This runs with a timeout of 0.5 seconds
Canandgyro.Settings settings = canandgyro.getSettings(0.5);
// Fetch the status frame period from the received settings
// This will be either a double (seconds) or null if the status frame period
// was not successully received.
if (settings.getStatusFramePeriod().isPresent()) {
System.out.printf("Status frame period: %d\n", settings.getStatusFramePeriod());
} else {
System.out.println("getStatusFramePeriod failed to fetch :/");
}
using namespace redux::sensors::canandcolor;
// A Canandgyro object with CAN ID 0
Canandgyro canandgyro{0};
// Fetch this Canandgyro's settings
// This runs with a default timeout of 0.35 seconds
CanandgyroSettings = canandgyro.GetSettings();
// Fetch this Canandgyro's settings
// This runs with a timeout of 0.5 seconds
CanandgyroSettings = canandgyro.GetSettings(0.5_s);
// Fetch the status frame period from the received settings
// This will be either a units::seconds_t or std::nullopt if the status frame period
// was not successully received.
if (settings.GetStatusFramePeriod()) {
fmt::print("Status frame period: {}\n", settings.GetStatusFramePeriod());
} else {
fmt::print("GetStatusFramePeriod failed to fetch :/");
}
Asynchronous (non-blocking)
// A Canandgyro object with CAN ID 0
Canandgyro canandgyro = new Canandgyro(0);
// Start the settings fetch
canandgyro.startFetchSettings();
// ...spend some period of time waiting for settings...
Canandgyro.Settings settings = canandgyro.getSettingsAsync();
if (settings.allSettingsReceived()) {
// We now know all settings have been received
// ...do things with the settings object here...
}
using namespace redux::sensors::Canandgyro;
// A Canandgyro object with CAN ID 0
Canandgyro canandgyro{0};
// Start the settings fetch
canandgyro.StartFetchSettings();
//...spend some period of time waiting for settings...
CanandgyroSettings settings = canandgyro.GetSettingsAsync();
if (settings.AllSettingsReceived()) {
// We now know all settings have been received
// ...do things with the settings object here...
}
Yaw Frame Period¶
The yaw frame period is the time between yaw pockets being sent by the Boron Canandgyro over the CAN Bus. By default, this value is 0.010 seconds, meaning a yaw packet is sent every 10 milliseconds (for a total of 100 times a second). Lower values will mean packets get sent more frequently, but will correspondingly increase CAN bus utilization. This value can be set to 0, which disables the yaw output. The maximum value of this value is 65.535 seconds (65535 milliseconds). This value is set with a resolution of 0.001 seconds (1 millisecond).
Default value: 0.010 seconds
Minimum value: 0 seconds (disables yaw output)
Maximum value: 65.535 seconds
FIRST® Robotics Competition
The CAN 2.0B bus in the FIRST® Robotics Competition operates at a rate of 1 Mbit/s, or 125000 bytes per second. To estimate CAN usage, you can multiply the size of the CAN packet by its send frequency in hertz, and divide that by 125000. CAN packets have 8 bytes of overhead. For example, a yaw packet is 6 bytes of data, so the full packet is 14 bytes. At 0.010 seconds, or 100 times a second, this takes up 1400 / 125000 or 1.12% of the CAN bus.
Angular Position Frame Period¶
The angular frame period is the time between angular pockets being sent by the Boron Canandgyro over the CAN Bus. This contains the quaternion of its orientation. By default, this value is 0.020 seconds, meaning a angular position packet is sent every 20 milliseconds (for a total of 50 times a second). Lower values will mean packets get sent more frequently, but will correspondingly increase CAN bus utilization. This value can be set to 0, which disables this frame. The maximum value of this value is 65.535 seconds (65535 milliseconds). This value is set with a resolution of 0.001 seconds (1 millisecond).
Default value: 0.020 seconds
Minimum value: 0 seconds (disables the frame)
Maximum value: 65.535 seconds
Angular Velocity Frame Period¶
The angular frame period is the time between angular velocity frames being sent by the Boron Canandgyro over the CAN Bus. By default, this value is 0.10 seconds, meaning a angular velocity packet is sent every 100 milliseconds (for a total of 10 times a second). Lower values will mean packets get sent more frequently, but will correspondingly increase CAN bus utilization. This value can be set to 0, which disables this frame. The maximum value of this value is 65.535 seconds (65535 milliseconds). This value is set with a resolution of 0.001 seconds (1 millisecond).
Default value: 0.10 seconds
Minimum value: 0 seconds (disables the frame)
Maximum value: 65.535 seconds
Acceleration Frame Period¶
The angular frame period is the time between acceleration frames being sent by the Boron Canandgyro over the CAN Bus. By default, this value is 0.10 seconds, meaning a acceleration packet is sent every 100 milliseconds (for a total of 10 times a second). Lower values will mean packets get sent more frequently, but will correspondingly increase CAN bus utilization. This value can be set to 0, which disables this frame. The maximum value of this value is 65.535 seconds (65535 milliseconds). This value is set with a resolution of 0.001 seconds (1 millisecond).
Default value: 0.10 seconds
Minimum value: 0 seconds (disables the frame)
Maximum value: 65.535 seconds
Status Frame Period¶
The status frame period is the time between status pockets being sent by the Boron Canandgyro over the CAN Bus. By default, this value is 0.1 seconds, meaning a status packet is sent every 100 milliseconds. Lower values will mean packets get sent more frequently, but will correspondingly increase CAN bus utilization. This value cannot be set to zero or disabled. The maximum value of this value is 16.383 seconds (16383 milliseconds). This value is set with a resolution of 0.001 seconds (1 millisecond).
Default value: 0.1 seconds
Minimum value: 0.001 seconds
Maximum value: 16.383 seconds