ADI (TriPort) C++ API¶
Note
Additional example code for this module can be found in its Tutorial.
pros::ADIAnalogIn¶
Constructor(s)¶
This function uses the following values of errno
when an error state is reached:
ENXIO
- The given port is not within the range of ADI Ports
pros::ADIAnalogIn::ADIAnalogIn ( std::uint8_t port )
1 2 3 4 5 6 7 8 | #define ANALOG_SENSOR_PORT 1 void opcontrol() { pros::ADIAnalogIn sensor (ANALOG_SENSOR_PORT); while (true) { // Use the sensor } } |
Parameters | |
---|---|
port | The ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’) for which to create an object |
pros::ADIAnalogIn::ADIAnalogIn ( pros::ext_adi_port_pair_t port_pair )
1 2 3 4 5 6 7 8 9 | #define EXT_ADI_SENSOR_PORT 1 #define ADI_PORT 'a' void opcontrol() { pros::ADIAnalogIn sensor ({{EXT_ADI_SMART_PORT, ADI_PORT}}); while (true) { // Use the sensor } } |
Parameters | |
---|---|
port_pair | 2 value pair in the form of {{smart_port , adi_port}} for which to create an object, where smart_port is an ADI expander’s smart port (1-22) and adi_port is ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’). |
Methods¶
calibrate¶
Calibrates the analog sensor on the specified channel.
This method assumes that the true sensor value is not actively changing at this time and computes an average from approximately 500 samples, 1 ms apart, for a 0.5 s period of calibration. The average value thus calculated is returned and stored for later calls to the adi_analog_read_calibrated and adi_analog_read_calibrated_HR functions. These functions will return the difference between this value and the current sensor value when called.
Do not use this function when the sensor value might be unstable (gyro rotation, accelerometer movement).
Note
The ADI currently returns data at 10ms intervals, in contrast to the calibrate function’s 1ms sample rate. This sample rate was kept for the sake of being similar to PROS 2, and increasing the sample rate would not have a tangible difference in the function’s performance.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as an analog input (e.g. the port has been reconfigured)
Analogous to adi_analog_calibrate.
std::int32_t pros::ADIAnalogIn::calibrate ( ) const
1 2 3 4 5 6 7 8 | #define ANALOG_SENSOR_PORT 1 void initialize() { pros::ADIAnalogIn sensor (ANALOG_SENSOR_PORT); sensor.calibrate(ANALOG_SENSOR_PORT); std::cout << "Calibrated Reading:" << sensor.get_value_calibrated(); // All readings from then on will be calibrated } |
Returns: The average sensor value computed by this function.
get_value¶
Reads an analog input channel and returns the 12-bit value.
The value returned is undefined if the analog pin has been switched to a different mode. The meaning of the returned value varies depending on the sensor attached.
Inherited from ADIPort::get_value.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as an analog input (e.g. the port has been reconfigured)
Analogous to adi_analog_read.
std::int32_t pros::ADIAnalogIn::get_value ( ) const
1 2 3 4 5 6 | #define ANALOG_SENSOR_PORT 1 void initialize() { pros::ADIAnalogIn sensor (ANALOG_SENSOR_PORT); std::cout << "Sensor Reading:" << sensor.get_value(); } |
Returns: The analog sensor value, where a value of 0 reflects an input voltage of nearly 0 V and a value of 4095 reflects an input voltage of nearly 5 V
get_value_calibrated¶
Reads the calibrated value of an analog input channel.
The adi_analog_calibrate function must be run first on that channel. This function is inappropriate for sensor values intended for integration, as round-off error can accumulate causing drift over time. Use adi_analog_read_calibrated_HR instead.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as an analog input (e.g. the port has been reconfigured)
Analogous to adi_analog_read_calibrated.
std::int32_t pros::ADIAnalogIn::get_value_calibrated ( ) const
1 2 3 4 5 6 7 8 | #define ANALOG_SENSOR_PORT 1 void initialize() { pros::ADIAnalogIn sensor (ANALOG_SENSOR_PORT); sensor.calibrate(ANALOG_SENSOR_PORT); std::cout << "Calibrated Reading:" << sensor.get_value_calibrated(); // All readings from then on will be calibrated } |
Returns: The difference of the sensor value from its calibrated default from -4095 to 4095.
get_value_calibrated_HR¶
Reads the calibrated value of an analog input channel 1-8 with enhanced precision.
The adi_analog_calibrate function must be run first. This is intended for integrated sensor values such as gyros and accelerometers to reduce drift due to round-off, and should not be used on a sensor such as a line tracker or potentiometer.
The value returned actually has 16 bits of “precision”, even though the ADC only reads 12 bits, so that errors induced by the average value being between two values come out in the wash when integrated over time. Think of the value as the true value times 16.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as an analog input (e.g. the port has been reconfigured)
Analogous to adi_analog_read_calibrated_HR.
std::int32_t pros::ADIAnalogIn::get_value_calibrated_HR ( ) const
1 2 3 4 5 6 7 8 | #define ANALOG_SENSOR_PORT 1 void initialize() { pros::ADIAnalogIn sensor (ANALOG_SENSOR_PORT); sensor.calibrate(ANALOG_SENSOR_PORT); std::cout << "High Res Calibrated Reading:" << sensor.get_value_calibrated_HR(); // All readings from then on will be calibrated } |
Returns: The difference of the sensor value from its calibrated default from -16384 to 16384.
pros::ADIAnalogOut¶
Constructor(s)¶
This function uses the following values of errno
when an error state is reached:
ENXIO
- The given port is not within the range of ADI Ports
pros::ADIAnalogOut::ADIAnalogOut ( std::uint8_t port )
1 2 3 4 5 6 | #define ANALOG_SENSOR_PORT 1 void opcontrol() { pros::ADIAnalogOut sensor (ANALOG_SENSOR_PORT); // Use the sensor } |
Parameters | |
---|---|
port | The ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’) for which to create an object |
pros::ADIAnalogOut::ADIAnalogOut ( pros::ext_adi_port_pair_t port_pair )
1 2 3 4 5 6 7 | #define EXT_ADI_SMART_PORT 1 #define ADI_PORT 'a' void opcontrol() { pros::ADIAnalogOut sensor ({{EXT_ADI_SMART_PORT, ADI_PORT}}); // Use the sensor } |
Parameters | |
---|---|
port_pair | 2 value pair in the form of {{smart_port , adi_port}} for which to create an object, where smart_port is an ADI expander’s smart port (1-22) and adi_port is ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’). |
Methods¶
set_value¶
Sets the output for the Analog Output from 0 (0V) to 4095 (5V).
Inherited from ADIPort::set_value.
This function uses the following values of errno
when an error state is reached:
EACCES
- Another resource is currently trying to access the ADI.
pros::ADIAnalogOut::set_value ( std::int32_t value ) const
1 2 3 4 5 6 | #define ANALOG_SENSOR_PORT 1 void opcontrol() { pros::ADIAnalogOut sensor (ANALOG_SENSOR_PORT); sensor.set_value(4095); // Set the port to 5V } |
Parameters | |
---|---|
value | The value to set the ADI port to from 0 (0V) to 4095 (5V) |
Returns: 1 if the operation was successful, PROS_ERR otherwise.
pros::ADIDigitalIn¶
Constructor(s)¶
This function uses the following values of errno
when an error state is reached:
ENXIO
- The given port is not within the range of ADI Ports
pros::ADIDigitalIn::ADIDigitalIn ( std::uint8_t port )
1 2 3 4 5 6 | #define DIGITAL_SENSOR_PORT 1 void opcontrol() { pros::ADIDigitalIn sensor (ANALOG_SENSOR_PORT); // Use the sensor } |
Parameters | |
---|---|
port | The ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’) for which to create an object |
pros::ADIDigitalIn::ADIDigitalIn ( pros::ext_adi_port_pair_t port_pair )
1 2 3 4 5 6 7 | #define EXT_ADI_SMART_PORT 1 #define ADI_PORT 'a' void opcontrol() { pros::ADIDigitalIn sensor ({{EXT_ADI_SMART_PORT, ADI_PORT}}); // Use the sensor } |
Parameters | |
---|---|
port_pair | 2 value pair in the form of {{smart_port , adi_port}} for which to create an object, where smart_port is an ADI expander’s smart port (1-22) and adi_port is ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’). |
Methods¶
get_new_press¶
Returns a rising-edge case for a digital button press.
This function is not thread-safe. Multiple tasks polling a single button may return different results under the same circumstances, so only one task should call this function for any given button. E.g., Task A calls this function for buttons 1 and 2. Task B may call this function for button 3, but should not for buttons 1 or 2. A typical use-case for this function is to call inside opcontrol to detect new button presses, and not in any other tasks.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as a digital input (e.g. the port has been reconfigured)
Analogous to adi_digital_get_new_press.
std::int32_t pros::ADIDigitalIn::get_new_press ( ) const
1 2 3 4 5 6 7 8 9 10 11 | #define DIGITAL_SENSOR_PORT 1 void opcontrol() { pros::ADIDigitalIn sensor (DIGITAL_SENSOR_PORT); while (true) { if (sensor.get_new_press()) { // Toggle pneumatics or other state operations } pros::delay(10); } } |
Returns: 1 if the button on the controller is pressed and had not been pressed the last time this function was called, 0 otherwise.
get_value¶
Gets the digital value (1 or 0) of a pin.
Inherited from ADIPort::get_value.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as a digital input (e.g. the port has been reconfigured)
Analogous to adi_digital_read.
std::int32_t pros::ADIDigitalIn::get_value ( ) const
1 2 3 4 5 6 7 8 9 | #define DIGITAL_SENSOR_PORT 1 void opcontrol() { pros::ADIDigitalIn sensor (DIGITAL_SENSOR_PORT); while (true) { std::cout << "Sensor Value:" << sensor.get_value(); pros::delay(10); } } |
pros::ADIDigitalOut¶
Constructor(s)¶
This function uses the following values of errno
when an error state is reached:
ENXIO
- The given port is not within the range of ADI Ports
pros::ADIDigitalOut::ADIDigitalOut ( std::uint8_t port
bool init_state = false )
1 2 3 4 5 6 7 8 9 10 11 | #define DIGITAL_SENSOR_PORT 1 void opcontrol() { bool state = LOW; pros::ADIDigitalOut sensor (DIGITAL_SENSOR_PORT, state); while (true) { state != state; sensor.set_value(state); pros::delay(10); // toggle the sensor value every 50ms } } |
Parameters | |
---|---|
port | The ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’) for which to create an object |
init_state | The initial state for the digital output. The default value is false. |
pros::ADIDigitalOut::ADIDigitalOut ( pros::ext_adi_port_pair_t port_pair
bool init_state = false )
1 2 3 4 5 6 7 8 9 10 11 12 | #define EXT_ADI_SMART_PORT 1 #define ADI_PORT 'a' void opcontrol() { bool state = LOW; pros::ADIDigitalOut sensor ( {{ EXT_ADI_SMART_PORT , ADI_PORT }}); while (true) { state != state; sensor.set_value(state); pros::delay(10); // toggle the sensor value every 50ms } } |
Parameters | |
---|---|
port_pair | 2 value pair in the form of {{smart_port , adi_port}} for which to create an object, where smart_port is an ADI expander’s smart port (1-22) and adi_port is ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’). |
init_state | The initial state for the digital output. The default value is false. |
Methods¶
set_value¶
Sets the digital value (1 or 0) of a pin.
Inherited from ADIPort::set_value.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as a digital output (e.g. the port has been reconfigured)
Analogous to adi_digital_write.
pros::ADIDigitalOut::set_value ( std::int32_t value ) const
1 2 3 4 5 6 7 8 9 10 11 | #define DIGITAL_SENSOR_PORT 1 void opcontrol() { bool state = LOW; pros::ADIDigitalOut sensor (DIGITAL_SENSOR_PORT); while (true) { state != state; sensor.set_value(state); pros::delay(10); // toggle the sensor value every 50ms } } |
Parameters | |
---|---|
value | an expression evaluating to “true” or “false” to set the output to HIGH or LOW respectively, or the constants HIGH or LOW themselves |
Returns: 1 if the operation was successful, PROS_ERR otherwise.
pros::ADIEncoder¶
Constructor(s)¶
This function uses the following values of errno
when an error state is reached:
ENXIO
- The given port is not within the range of ADI Ports
pros::ADIEncoder::ADIEncoder ( std::uint8_t port_top,
std::uint8_t port_bottom,
const bool reverse = false )
1 2 3 4 5 6 7 | #define PORT_TOP 1 #define PORT_BOTTOM 2 void opcontrol() { pros::ADIEncoder sensor (PORT_TOP, PORT_BOTTOM, false); // Use the sensor } |
Parameters | |
---|---|
port_top | the “top” wire from the encoder sensor with the removable cover side UP. This should be in port 1, 3, 5, or 7 (‘A’, ‘C’, ‘E’, ‘G’). |
port_bottom | the “bottom” wire from the encoder sensor |
reverse | if “true”, the sensor will count in the opposite direction. The default value is “false”. |
pros::ADIEncoder::ADIEncoder ( pros::ext_adi_port_tuple_t port_tuple
const bool reverse = false )
1 2 3 4 5 6 7 8 | #define PORT_TOP 'A' #define PORT_BOTTOM 'B' #define SMART_PORT 1 void opcontrol() { pros::ADIEncoder sensor ({ SMART_PORT, PORT_TOP, PORT_BOTTOM }, false); // Use the sensor } |
Parameters | |
---|---|
port_tuple | A 3 value tuple in the form of (smart_port, port_top, port_bottom} where smart_port is the smart port where the ADI expander is plugged in, port_top is the “top” wire from the encoder sensor with the removable cover side UP. This should be in port 1, 3, 5, or 7 (‘A’, ‘C’, ‘E’, ‘G’), and port_bottom being the “bottom” wire from the encoder sensor. |
reverse | if “true”, the sensor will count in the opposite direction. The default value is “false”. |
Methods¶
get_value¶
Gets the number of ticks recorded by the encoder.
There are 360 ticks in one revolution.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as an encoder (e.g. the port has been reconfigured)
Analogous to adi_encoder_get.
std::int32_t pros::ADIEncoder::get_value ( ) const
1 2 3 4 5 6 7 8 9 10 | #define PORT_TOP 1 #define PORT_BOTTOM 2 void opcontrol() { pros::ADIEncoder sensor (PORT_TOP, PORT_BOTTOM, false); while (true) { std::cout << "Encoder Value: " << sensor.get_value(); pros::delay(10); } } |
reset¶
Resets the encoder to zero.
It is safe to use this method while an encoder is enabled. It is not necessary to call this method before stopping or starting an encoder.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as an encoder (e.g. the port has been reconfigured)
Analogous to adi_encoder_reset.
std::int32_t pros::ADIEncoder::reset ( ) const
1 2 3 4 5 6 7 8 | #define PORT_TOP 1 #define PORT_BOTTOM 2 void opcontrol() { pros::ADIEncoder sensor (PORT_TOP, PORT_BOTTOM, false); delay(1000); // Move the encoder around in this time sensor.reset(); // The encoder is now zero again } |
Returns: 1 if the operation was successful, PROS_ERR otherwise.
pros::ADIMotor¶
Constructor(s)¶
This function uses the following values of errno
when an error state is reached:
ENXIO
- The given port is not within the range of ADI Ports
pros::ADIMotor::ADIMotor ( std::uint8_t port )
1 2 3 4 5 6 7 8 9 | #define MOTOR_PORT 1 void opcontrol() { pros::ADIMotor motor (MOTOR_PORT); motor.set_value(127); // Go full speed forward std::cout << "Commanded Motor Power: " << motor.get_value(); // Will display 127 delay(1000); motor.set_value(0); // Stop the motor } |
Parameters | |
---|---|
port | The ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’) for which to create an object |
pros::ADIMotor::ADIMotor ( pros::ext_adi_port_pair_t port_pair )
1 2 3 4 5 6 7 8 9 10 | #define EXT_ADI_SMART_PORT 1 #define ADI_MOTOR_PORT 'a' void opcontrol() { pros::ADIMotor motor ( {{ EXT_ADI_SMART_PORT , ADI_MOTOR_PORT}} ); motor.set_value(127); // Go full speed forward std::cout << "Commanded Motor Power: " << motor.get_value(); // Will display 127 delay(1000); motor.set_value(0); // Stop the motor } |
Parameters | |
---|---|
port_pair | 2 value pair in the form of {{smart_port , adi_port}} for which to create an object, where smart_port is an ADI expander’s smart port (1-22) and adi_port is ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’). |
Methods¶
get_value¶
Returns the last set speed of the motor on the given port.
Inherited from ADIPort::get_value.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as a motor (e.g. the port has been reconfigured)
Analogous to adi_motor_get.
std::int32_t pros::ADIMotor::get_value ( ) const
1 2 3 4 5 6 7 8 9 | #define MOTOR_PORT 1 void opcontrol() { pros::ADIMotor motor (MOTOR_PORT); motor.set_value(127); // Go full speed forward std::cout << "Commanded Motor Power: " << motor.get_value(); // Will display 127 delay(1000); motor.set_value(0); // Stop the motor } |
Returns: The last set speed of the motor on the given port.
set_value¶
Sets the speed of the given motor.
Inherited from ADIPort::set_value.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as a motor (e.g. the port has been reconfigured)
Analogous to adi_motor_set.
std::int32_t pros::ADIMotor::set_value ( std::int32_t value ) const
1 2 3 4 5 6 7 8 9 | #define MOTOR_PORT 1 void opcontrol() { pros::ADIMotor motor (MOTOR_PORT); motor.set_value(127); // Go full speed forward std::cout << "Commanded Motor Power: " << motor.get_value(); // Will display 127 delay(1000); motor.set_value(0); // Stop the motor } |
Parameters | |
---|---|
speed | the new signed speed; -127 is full reverse and 127 is full forward, with 0 being off |
Returns: 1 if the operation was successful, PROS_ERR otherwise
stop¶
Stops the given motor.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as a motor (e.g. the port has been reconfigured)
Analogous to adi_motor_stop.
std::int32_t pros::ADIMotor::stop ( ) const
1 2 3 4 5 6 7 8 9 | #define MOTOR_PORT 1 void opcontrol() { pros::ADIMotor motor (MOTOR_PORT); motor.set_value(127); // Go full speed forward std::cout << "Commanded Motor Power: " << motor.get_value(); // Will display 127 delay(1000); motor.stop(); // Stop the motor } |
Returns: 1 if the operation was successful, PROS_ERR otherwise.
pros::ADIPort¶
Constructor(s)¶
This function uses the following values of errno
when an error state is reached:
ENXIO
- The given port is not within the range of ADI Ports
pros::ADIPort::ADIPort ( std::uint8_t port,
adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED )
1 2 3 4 5 6 7 | #define ANALOG_SENSOR_PORT 1 void initialize() { pros::ADIPort sensor (ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); // Displays the value of E_ADI_ANALOG_IN std::cout << "Port Type: " << sensor.get_config(); } |
Parameters | |
---|---|
port | The ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’) for which to create an object |
type | The configuration type for the port |
pros::ADIPort::ADIPort ( pros::ext_adi_port_pair_t port_pair,
adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED )
1 2 3 4 5 6 7 8 | #define ANALOG_SENSOR_PORT 'a' #define EXT_ADI_SMART_PORT 1 void initialize() { pros::ADIPort sensor ({{ EXT_ADI_SMART_PORT , ANALOG_SENSOR_PORT }}, E_ADI_ANALOG_IN); // Displays the value of E_ADI_ANALOG_IN std::cout << "Port Type: " << sensor.get_config(); } |
Parameters | |
---|---|
port_pair | 2 value pair in the form of {{smart_port , adi_port}} for which to create an object, where smart_port is an ADI expander’s smart port (1-22) and adi_port is ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’). |
type | The configuration type for the port |
Methods¶
get_config¶
Returns the configuration for the given ADI port.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as a the type specified in the constructor (e.g. the port has been reconfigured)
Analogous to adi_port_get_config.
std::int32_t pros::ADIPort::get_config ( ) const;
1 2 3 4 5 6 7 | #define ANALOG_SENSOR_PORT 1 void initialize() { adi_port_set_config(ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); // Displays the value of E_ADI_ANALOG_IN printf("Port Type: %d\n", adi_port_get_config(ANALOG_SENSOR_PORT)); } |
get_value¶
Returns the value for the given ADI port.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as a the type specified in the constructor (e.g. the port has been reconfigured)
Analogous to adi_port_get_value.
std::int32_t pros::ADIPort::get_value ( ) const
1 2 3 4 5 6 | #define ANALOG_SENSOR_PORT 1 void opcontrol() { pros::ADIPort sensor (ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); std::cout << "Port Value: " << sensor.get_value(); } |
Returns: The value for the given ADI port.
set_config¶
Configures an ADI port to act as a given sensor type.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as a the type specified in the constructor (e.g. the port has been reconfigured)
Analogous to adi_port_set_config.
std::int32_t pros::ADIPort::set_config ( adi_port_config_e_t type ) const
1 2 3 4 5 6 7 8 | #define ANALOG_SENSOR_PORT 1 void initialize() { pros::ADIPort sensor (ANALOG_SENSOR_PORT, E_ADI_DIGITAL_IN); // Do things as a digital sensor // Digital is unplugged and an analog is plugged in sensor.set_config(E_ADI_ANALOG_IN); } |
Parameters | |
---|---|
type | The configuration type for the port |
Returns: 1 if the operation was successful, PROS_ERR otherwise.
set_value¶
Sets the value for the given ADI port
This only works on ports configured as outputs, and the behavior will change depending on the configuration of the port.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as a the type specified in the constructor (e.g. the port has been reconfigured)
Analogous to adi_port_set_value.
std::int32_t pros::ADIPort::set_value ( ) const;
1 2 3 4 5 6 | #define DIGITAL_SENSOR_PORT 1 void initialize() { pros::ADIPort sensor (DIGITAL_SENSOR_PORT, E_ADI_DIGITAL_OUT); sensor.set_value(DIGITAL_SENSOR_PORT, HIGH); } |
Parameters | |
---|---|
value | The value to set the ADI port to |
Returns: 1 if the operation was successful, PROS_ERR otherwise.
pros::ADIUltrasonic¶
Constructor(s)¶
This function uses the following values of errno
when an error state is reached:
ENXIO
- The given port is not within the range of ADI Ports
pros::ADIUltrasonic::ADIUltrasonic ( std::uint8_t port_ping,
std::uint8_t port_echo )
1 2 3 4 5 6 7 8 9 10 11 | #define PORT_PING 1 #define PORT_ECHO 2 void opcontrol() { pros::ADIUltrasonic sensor (PORT_PING, PORT_ECHO); while (true) { // Print the distance read by the ultrasonic std::cout << "Distance: " << sensor.get_value(); pros::delay(10); } } |
Parameters | |
---|---|
port_ping | the port connected to the orange OUTPUT cable. This should be in port 1, 3, 5, or 7 (‘A’, ‘C’, ‘E’, ‘G’). |
port_echo | the port connected to the yellow INPUT cable. This should be in the next highest port following port_ping. |
pros::ADIUltrasonic::ADIUltrasonic ( pros::ext_adi_port_tuple_t port_tuple )
1 2 3 4 5 6 7 8 9 10 11 12 | #define PORT_PING 'A' #define PORT_ECHO 'B' #define SMART_PORT 1 void opcontrol() { pros::ADIUltrasonic sensor ( {{ SMART_PORT, PORT_PING, PORT_ECHO }} ); while (true) { // Print the distance read by the ultrasonic std::cout << "Distance: " << sensor.get_value(); pros::delay(10); } } |
Parameters | |
---|---|
port_tuple | A 3 value tuple in the form of {{smart_port, port_ping, port_bottom}} where smart_port is the smart port where the ADI expander is plugged in, port_ping is the port connected to the orange OUTPUT cable and should be in port 1, 3, 5, or 7 (‘A’, ‘C’, ‘E’, ‘G’), and port_bottom being the port connected to the yellow INPUT cable in the next highest port following port_ping. Note the use of double paranthesis for this. |
Methods¶
get_value¶
Gets the current ultrasonic sensor value in centimeters.
If no object was found, zero is returned. If the ultrasonic sensor was never started, the return value is PROS_ERR. Round and fluffy objects can cause inaccurate values to be returned.
Inherited from ADIPort::get_value.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as an ultrasonic (e.g. the port has been reconfigured)
Analogous to adi_ultrasonic_get.
std::int32_t pros::ADIUltrasonic::get_value ( ) const
1 2 3 4 5 6 7 8 9 10 11 | #define PORT_PING 1 #define PORT_ECHO 2 void opcontrol() { pros::ADIUltrasonic sensor (PORT_PING, PORT_ECHO); while (true) { // Print the distance read by the ultrasonic std::cout << "Distance: " << sensor.get_value(); pros::delay(10); } } |
Returns: The distance to the nearest object in centimeters.
pros::ADIGyro¶
Constructor(s)¶
Initializes a gyroscope on the given port. If the given port has not previously been configured as a gyro, then this function starts a 1 second calibration period.
If calibration is required, it is highly recommended that this function be called from initialize when the robot is stationary.
This function uses the following values of errno
when an error state is reached:
ENXIO
- The given port is not within the range of ADI Ports
Analogous to adi_gyro_init.
pros::ADIGyro::ADIGyro ( std::uint8_t port,
double multiplier = 1 )
1 2 3 4 5 6 7 8 9 10 | #define GYRO_PORT 1 void opcontrol() { pros::ADIGyro gyro (GYRO_PORT); while (true) { // Get the gyro heading std::cout << "Distance: " << gyro.get_value(); pros::delay(10); } } |
Parameters | |
---|---|
port | The ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’) to initialize as a gyro |
multiplier | A scalar value that will be mutliplied by the gyro heading value |
pros::ADIGyro::ADIGyro ( pros::ext_adi_port_pair_t port_pair,
double multiplier = 1 )
1 2 3 4 5 6 7 8 9 10 11 | #define ADI_GYRO_PORT 'a' #define SMART_PORT 1 void opcontrol() { pros::ADIGyro gyro ({{ SMART_PORT , ADI_GYRO_PORT }}); while (true) { // Get the gyro heading std::cout << "Distance: " << gyro.get_value(); pros::delay(10); } } |
Parameters | |
---|---|
port_pair | 2 value pair in the form of {{smart_port , adi_port}} for which to create an object, where smart_port is an ADI expander’s smart port (1-22) and adi_port is ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’). |
Methods¶
get_value¶
Gets the current gyro angle in tenths of a degree. Unless a multiplier is applied to the gyro, the return value will be a whole number representing the number of degrees of rotation times 10.
There are 360 degrees in a circle, thus the gyro will return 3600 for one whole rotation.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as a gyro (e.g. the port has been reconfigured)
Analogous to adi_gyro_get.
double pros::ADIGyro::get_value ( ) const
1 2 3 4 5 6 7 8 9 10 | #define GYRO_PORT 1 void opcontrol() { pros::ADIGyro gyro (GYRO_PORT); while (true) { // Get the gyro heading std::cout << "Distance: " << gyro.get_value(); pros::delay(10); } } |
Returns: The gyro angle in tenths of a degree.
reset¶
Resets the gyro value to zero.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as a gyro (e.g. the port has been reconfigured)
Analogous to adi_gyro_reset.
std::int32_t pros::ADIGyro::reset ( ) const
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #define GYRO_PORT 1 void opcontrol() { pros::ADIGyro gyro (GYRO_PORT); std::uint32_t now = pros::millis(); while (true) { // Get the gyro heading std::cout << "Distance: " << gyro.get_value(); if (pros::millis() - now > 2000) { // Reset the gyro every 2 seconds gyro.reset(); now = pros::millis(); } pros::delay(10); } } |
Returns: 1 if the operation was successful or PROS_ERR
if the operation failed, setting errno
.
pros::ADIPotentiometer¶
Constructor(s)¶
Configures an ADI port to act as a Potentiometer.
This function uses the following values of errno
when an error state is reached:
ENXIO
- The given port is not within the range of ADI Ports
Analogous to adi_potentiometer_init.
pros::ADIPotentiometer::ADIPotentiometer ( std::uint8_t adi_port, adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR )
1 2 3 4 5 6 7 8 9 10 11 | #define POTENTIOMETER_PORT 1 #define POTENTIOMETER_TYPE pros::E_ADI_POT_EDR void opcontrol() { pros::ADIPotentiometer potentiometer (POTENTIOMETER_PORT, POTENTIOMETER_TYPE); while (true) { // Get the potentiometer angle std::cout << "Angle: " << potnetiometer.get_angle(); pros::delay(10); } } |
Parameters | |
---|---|
port | The ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’) to initialize as a potentiometer |
potentiometer_type | An adi_potentiometer_type_e_t enum value specifying the potentiometer version type |
pros::ADIPotentiometer::ADIPotentiometer ( ext_adi_port_pair_t port_pair, adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR )
1 2 3 4 5 6 7 8 9 10 11 | #define ADI_POTENTIOMETER_PORT 'a' #define SMART_PORT 1 void opcontrol() { pros::ADIPotentiometer potentiometer ({{ SMART_PORT , ADI_POTENTIOMETER_PORT }}); while (true) { // Get the potentiometer angle std::cout << "Angle: " << potentiometer.get_angle(); pros::delay(10); } } |
Parameters | |
---|---|
port_pair | 2 value pair in the form of {{smart_port , adi_port}} for which to create an object, where smart_port is an ADI expander’s smart port (1-22) and adi_port is ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’). |
potentiometer_type | An adi_potentiometer_type_e_t enum value specifying the potentiometer version type |
Methods¶
get_angle¶
Gets the current potentiometer angle in tenths of a degree.
The original potentiometer rotates 250 degrees thus returning an angle between 0-250 degrees.
Potentiometer V2 rotates 330 degrees thus returning an angle between 0-330 degrees.
This function uses the following values of errno
when an error state is reached:
EADDRINUSE
- The port is not configured as a potentiometer (e.g. the port has been reconfigured)
Analogous to adi_poteniometer_get.
double pros::ADIPotentiometer::get_angle ( ) const
1 2 3 4 5 6 7 8 9 10 11 | #define ADI_POTENTIOMETER_PORT 'a' #define SMART_PORT 1 void opcontrol() { pros::ADIPotentiometer potentiometer ({{ SMART_PORT , ADI_POTENTIOMETER_PORT }}); while (true) { // Get the potentiometer angle std::cout << "Angle: " << potentiometer.get_angle(); pros::delay(10); } } |
Returns: The potentiometer angle in tenths of a degree.
pros::ADILed¶
Note
pros::ADILed
and pros::ADILED
are synonymous.
Constructor(s)¶
This function uses the following values of errno
when an error state is reached:
ENXIO
- The given port is not within the range of ADI Ports
pros::ADILed::ADILed ( std::uint8_t adi_port,
std::uint32_t length )
1 2 3 4 5 6 7 | #define LED_PORT 1 #define LED_SIZE 64 void initalize() { pros::ADILed led (LED_PORT, LED_SIZE); // Use the led } |
Parameters | |
---|---|
port | The ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’) for which to create an object |
length | The number of LEDs in the chain |
pros::ADILed::ADILed ( ext_adi_port_pair_t port_pair,
std::uint32_t length )
1 2 3 4 5 6 7 8 | #define EXT_ADI_SMART_PORT 1 #define ADI_PORT 'a' #define LED_SIZE 64 void initalize() { pros::ADILed led ({{EXT_ADI_SMART_PORT,ADI_PORT}}, LED_SIZE); // Use the led } |
Parameters | |
---|---|
port_pair | 2 value pair in the form of {{smart_port , adi_port}} for which to create an object, where smart_port is an ADI expander’s smart port (1-22) and adi_port is ADI port number (from 1-8, ‘a’-‘h’, ‘A’-‘H’). |
length | The number of LEDs in the chain |
Methods¶
operator[]¶
Operator overload to access the buffer in the ADILed class, it is recommended that you call .update(); after doing any operations with this.
std::uint32_t& pros::ADILed::operator[] ( size_t i )
1 2 3 4 5 6 7 8 | #define LED_PORT 1 #define LED_SIZE 64 void initalize() { pros::ADILed led (LED_PORT, LED_SIZE); led[0] = 0x808080; led.update(); } |
Parameters | |
---|---|
i | 0 indexed pixel of the lED |
Returns: The address of the buffer at i to modify as a uint32_t&
clear¶
Clear the entire led strip of color
This function uses the following values of errno
when an error state is reached:
ENXIO
- The given port is not within the range of ADI PortsEINVAL
- A parameter is out of bounds/incorrectEADDRINUSE
- The port is not configured for ADI output
std::int32_t pros::ADILed::clear ( )
1 2 3 4 5 6 7 8 | #define LED_PORT 1 #define LED_SIZE 64 void initalize() { pros::ADILed led (LED_PORT, LED_SIZE); //Set colors led.clear(); } |
Returns: PROS_SUCCESS if successful, PROS_ERR if not
clear_all¶
Clear the entire led strip of color
This function uses the following values of errno
when an error state is reached:
ENXIO
- The given port is not within the range of ADI PortsEINVAL
- A parameter is out of bounds/incorrectEADDRINUSE
- The port is not configured for ADI output
std::int32_t pros::ADILed::clear_all ( )
1 2 3 4 5 6 7 8 | #define LED_PORT 1 #define LED_SIZE 64 void initalize() { pros::ADILed led (LED_PORT, LED_SIZE); //Set colors led.clear_all(); } |
Returns: PROS_SUCCESS if successful, PROS_ERR if not
clear_pixel¶
Clear one pixel on the led strip.
This function uses the following values of errno
when an error state is reached:
EINVAL
- A parameter is out of bounds/incorrectEADDRINUSE
- The port is not configured for ADI output
std::int32_t pros::ADILed::clear_pixel ( uint32_t pixel_position )
1 2 3 4 5 6 7 8 | #define LED_PORT 1 #define LED_SIZE 64 void initalize() { pros::ADILed led (LED_PORT, LED_SIZE); //Set led colors led.clear_pixel(0); } |
Parameters | |
---|---|
pixel_position | Position of the pixel to set |
Returns: PROS_SUCCESS if successful, PROS_ERR if not
length¶
Get the length of the led strip.
This function uses the following values of errno
when an error state is reached:
EINVAL
- A parameter is out of bounds/incorrectEADDRINUSE
- The port is not configured for ADI output
std::int32_t pros::ADILed::length ( )
1 2 3 4 5 6 7 | #define LED_PORT 1 #define LED_SIZE 64 void initalize() { pros::ADILed led (LED_PORT, LED_SIZE); std::cout << "Led size: " << led.length(); //Prints out led length } |
Returns: The length (in pixels) of the LED strip
set_all¶
Set the entire led strip to one color.
This function uses the following values of errno
when an error state is reached:
EINVAL
- A parameter is out of bounds/incorrectEADDRINUSE
- The port is not configured for ADI output
std::int32_t pros::ADILed::set_all ( uint32_t color )
1 2 3 4 5 6 7 8 | #define LED_PORT 1 #define LED_SIZE 64 void initalize() { pros::ADILed led (LED_PORT, LED_SIZE); led.set_all(0x808080); led.update(); } |
Parameters | |
---|---|
color | Color to set the entire led to |
Returns: PROS_SUCCESS if successful, PROS_ERR if not
set_pixel¶
Set one pixel on the led strip.
This function uses the following values of errno
when an error state is reached:
EINVAL
- A parameter is out of bounds/incorrectEADDRINUSE
- The port is not configured for ADI output
std::int32_t pros::ADILed::set_pixel ( uint32_t color,
uint32_t pixel_position )
1 2 3 4 5 6 7 | #define LED_PORT 1 #define LED_SIZE 64 void initalize() { pros::ADILed led (LED_PORT, LED_SIZE); led.set_pixel(0x808080, 0); } |
Parameters | |
---|---|
color | Color to set a pixel to |
pixel_position | Position of the pixel to set |
Returns: PROS_SUCCESS if successful, PROS_ERR if not
update¶
Force the LED strip to update with the current buffered values, this should be called after any changes to the buffer using the [] operator.
This function uses the following values of errno
when an error state is reached:
EINVAL
- A parameter is out of bounds/incorrectEADDRINUSE
- The port is not configured for ADI output
std::uint32_t& pros::ADILed::update() const
1 2 3 4 5 6 7 8 | #define LED_PORT 1 #define LED_SIZE 64 void initalize() { pros::ADILed led (LED_PORT, LED_SIZE); led[0] = 0x808080; led.update(); } |
Returns: PROS_SUCCESS if successful, PROS_ERR if not
Macros¶
HIGH¶
Used to specify a logic HIGH state to output.
In reality, using any non-zero expression or “true” will work to set a pin to HIGH.
Value: 1
LOW¶
Used to specify a logic LOW state to output.
In reality, using a zero expression or “false” will work to set a pin to LOW.
Value: 0
NUM_ADI_PORTS¶
The number of ADI ports available on the V5 Brain (from 1-8, ‘a’-‘h’, ‘A’-‘H’).
Value: 8
Enumerated Values¶
pros::adi_port_config_e_t¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | typedef enum adi_port_config_e { E_ADI_ANALOG_IN = 0, E_ADI_ANALOG_OUT, E_ADI_DIGITAL_IN, E_ADI_DIGITAL_OUT, E_ADI_SMART_BUTTON, E_ADI_SMART_POT, E_ADI_LEGACY_BUTTON, E_ADI_LEGACY_POT, E_ADI_LEGACY_LINE_SENSOR, E_ADI_LEGACY_LIGHT_SENSOR, E_ADI_LEGACY_GYRO, E_ADI_LEGACY_ACCELEROMETER, E_ADI_LEGACY_SERVO, E_ADI_LEGACY_PWM, E_ADI_LEGACY_ENCODER, E_ADI_LEGACY_ULTRASONIC, E_ADI_TYPE_UNDEFINED = 255, E_ADI_ERR = PROS_ERR } adi_port_config_e_t; |
Value | |
---|---|
pros::E_ADI_ANALOG_IN | Configures the ADI port as an analog input |
pros::E_ADI_ANALOG_OUT | Configures the ADI port as an analog output |
pros::E_ADI_DIGITAL_IN | Configures the ADI port as a digital input |
pros::E_ADI_DIGITAL_OUT | Configures the ADI port as a digital output |
pros::E_ADI_LEGACY_GYRO | Configures the ADI port for use with a Cortex-Era Gyro |
pros::E_ADI_LEGACY_ACCELEROMETER | Configures the ADI port for use with a Cortex-Era accelerometer |
pros::E_ADI_LEGACY_SERVO | Configures the ADI port for use with a Cortex-Era servo motor |
pros::E_ADI_LEGACY_PWM | Configures the ADI port for use with a Cortex-Era motor |
pros::E_ADI_LEGACY_ENCODER | Configures the ADI port (and the one immediately above it) for use with a Cortex-Era Encoder |
pros::E_ADI_LEGACY_ULTRASONIC | Configures the ADI port (and the one immediately above it) for use with a Cortex-Era Ultrasonic |
pros::E_ADI_TYPE_UNDEFINED | The default value for an uninitialized ADI port |
pros::E_ADI_ERR | Error return value for ADI port configuration |
pros::adi_potentiometer_type_e_t¶
typedef enum adi_potentiometer_type_e {
E_ADI_POT_EDR = 0,
E_ADI_POT_V2
} adi_potentiometer_type_e_t;
Value | |
---|---|
pros::E_ADI_POT_EDR | Configures the potentiometer as the original potentiometer |
pros::E_ADI_POT_V2 | Configures the potentiometer as the V2 potentiometer |
Typedefs¶
pros::adi_encoder_t¶
Reference type for an initialized encoder.
This merely contains the port number for the encoder, unlike its use as an object to store encoder data in PROS 2.
typedef int32_t adi_encoder_t;
pros::adi_gyro_t¶
Reference type for an initialized gyro.
This merely contains the port number for the gyro, unlike its use as an object to store gyro data in PROS 2.
typedef int32_t adi_gyro_t;
pros::adi_ultrasonic_t¶
Reference type for an initialized ultrasonic.
This merely contains the port number for the ultrasonic, unlike its use as an object to store ultrasonic data in PROS 2.
typedef int32_t adi_ultrasonic_t;