ADI (TriPort) C++ API module
Files
- file adi.hpp
Classes
- class pros::adi::Port
Functions
- Port(std::uint8_t adi_port, adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED) explicit
- Configures an ADI port to act as a given sensor type.
- Port(ext_adi_port_pair_t port_pair, adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED) explicit
- Configures an ADI port on an adi expander to act as a given sensor type.
- std::int32_t get_config() const
- Gets the configuration for the given ADI port.
- std::int32_t get_value() const
- Gets the value for the given ADI port.
- std::int32_t set_config(adi_port_config_e_t type) const
- Configures an ADI port to act as a given sensor type.
- std::int32_t set_value(std::int32_t value) const
- Sets the value for the given ADI port.
- ext_adi_port_tuple_t get_port() const virtual
- Gets the port of the sensor.
- AnalogIn(std::uint8_t adi_port) explicit
- Configures an ADI port to act as an Analog Input.
- AnalogIn(ext_adi_port_pair_t port_pair) explicit
- Configures an ADI port to act as an Analog Input.
- std::int32_t calibrate() const
- Calibrates the analog sensor on the specified port and returns the new calibration value.
- std::int32_t get_value_calibrated() const
- Gets the 12 bit calibrated value of an analog input port.
- std::int32_t get_value_calibrated_HR() const
- Gets the 16 bit calibrated value of an analog input port.
- AnalogOut(std::uint8_t adi_port) explicit
- Configures an ADI port to act as an Analog Output.
- AnalogOut(ext_adi_port_pair_t port_pair) explicit
- Configures an ADI port on an adi_expander to act as an Analog Output.
- DigitalOut(std::uint8_t adi_port, bool init_state = LOW) explicit
- Configures an ADI port to act as a Digital Output.
- DigitalOut(ext_adi_port_pair_t port_pair, bool init_state = LOW) explicit
- Configures an ADI port on an adi_expander to act as a Digital Output.
- DigitalIn(std::uint8_t adi_port) explicit
- Configures an ADI port to act as a Digital Input.
- DigitalIn(ext_adi_port_pair_t port_pair) explicit
- Configures an ADI port on an adi_expander to act as a Digital Input.
- std::int32_t get_new_press() const
- Gets a rising-edge case for a digital button press.
- Motor(std::uint8_t adi_port) explicit
- Configures an ADI port to act as a Motor.
- Motor(ext_adi_port_pair_t port_pair) explicit
- Configures an ADI port on an adi_expander to act as a Motor.
- std::int32_t stop() const
- Stops the motor on the given port.
- Encoder(std::uint8_t adi_port_top, std::uint8_t adi_port_bottom, bool reversed = false) explicit
- Configures a set of ADI ports to act as an Encoder.
- Encoder(ext_adi_port_tuple_t port_tuple, bool reversed = false) explicit
- Configures a set of ADI ports on an adi_expander to act as an Encoder.
- std::int32_t reset() const
- Sets the encoder value to zero.
- std::int32_t get_value() const
- Gets the number of ticks recorded by the encoder.
- ext_adi_port_tuple_t get_port() const override
- Gets the port of the sensor.
- Ultrasonic(std::uint8_t adi_port_ping, std::uint8_t adi_port_echo) explicit
- Configures a set of ADI ports to act as an Ultrasonic sensor.
- Ultrasonic(ext_adi_port_tuple_t port_tuple) explicit
- Configures a set of ADI ports on an adi_expander to act as an Ultrasonic sensor.
- std::int32_t get_value() const
- Gets the current ultrasonic sensor value in centimeters.
- Gyro(std::uint8_t adi_port, double multiplier = 1) explicit
- Initializes a gyroscope on the given port.
- Gyro(ext_adi_port_pair_t port_pair, double multiplier = 1) explicit
- Initializes a gyroscope on the given port of an adi expander.
- double get_value() const
- Gets the current gyro angle in tenths of a degree.
- std::int32_t reset() const
- Resets the gyroscope value to zero.
- Potentiometer(std::uint8_t adi_port, adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR) explicit
- Configures an ADI port to act as a Potentiometer.
- Potentiometer(ext_adi_port_pair_t port_pair, adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR) explicit
- Configures an ADI port on an adi_expander to act as a Potentiometer.
- double get_angle() const
- Gets the current potentiometer angle in tenths of a degree.
- Led(std::uint8_t adi_port, std::uint32_t length) explicit
- Configures an ADI port to act as a LED.
- Led(ext_adi_port_pair_t port_pair, std::uint32_t length) explicit
- Configures an ADI port on a adi_expander to act as a LED.
- std::int32_t clear_all()
- Operator overload to access the buffer in the ADILed class, it is recommended that you call .update(); after doing any operations with this.
- std::int32_t clear()
- std::int32_t update() const
- Force the LED strip to update with the current buffered values, this should be called after any changes to the buffer using the [] operator.
- std::int32_t set_all(uint32_t color)
- Set the entire led strip to one color.
- std::int32_t set_pixel(uint32_t color, uint32_t pixel_position)
- Set one pixel on the led strip.
- std::int32_t clear_pixel(uint32_t pixel_position)
- Clear one pixel on the led strip.
- std::int32_t length()
- Get the length of the led strip.
- Pneumatics(std::uint8_t adi_port, bool start_extended, bool extended_is_low = false) explicit
- Creates a Pneumatics object for the given port.
- Pneumatics(ext_adi_port_pair_t port_pair, bool start_extended, bool extended_is_low = false) explicit
- Creates a Pneumatics object for the given port pair.
- std::int32_t extend()
- Extends the piston, if not already extended.
- std::int32_t retract()
- Retracts the piston, if not already retracted.
- std::int32_t toggle()
- Puts the piston into the opposite state of its current state.
- bool is_extended() const
- Returns whether the piston is extended or not.
Variables
- std::uint8_t _smart_port
- std::uint8_t _adi_port
- ext_adi_port_pair_t _port_pair
- std::vector<uint32_t> _buffer
- bool state
- bool extended_is_low
Function documentation
Port(std::uint8_t adi_port,
adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED) explicit
#include <pros/adi.hpp>
Configures an ADI port to act as a given sensor type.
Parameters | |
---|---|
adi_port | The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
type | The configuration type for the port |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#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); } }
Port(ext_adi_port_pair_t port_pair,
adi_port_config_e_t type = E_ADI_TYPE_UNDEFINED) explicit
#include <pros/adi.hpp>
Configures an ADI port on an adi expander to act as a given sensor type.
Parameters | |
---|---|
port_pair | The pair of the smart port number (from 1-22) and the ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
type | The configuration type for the port |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define ANALOG_SENSOR_PORT 'a' #define EXT_ADI_SMART_PORT 1 void initialize() { pros::adi::Port 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(); }
std::int32_t get_config() const
#include <pros/adi.hpp>
Gets the configuration for the given ADI port.
Returns | The ADI configuration for the given port |
---|
Example
#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)); }
std::int32_t get_value() const
#include <pros/adi.hpp>
Gets the value for the given ADI port.
Returns | The value stored for the given port |
---|
Example
#define ANALOG_SENSOR_PORT 1 void opcontrol() { pros::adi::Port sensor (ANALOG_SENSOR_PORT, E_ADI_ANALOG_IN); std::cout << "Port Value: " << sensor.get_value(); }
std::int32_t set_config(adi_port_config_e_t type) const
#include <pros/adi.hpp>
Configures an ADI port to act as a given sensor type.
Parameters | |
---|---|
type | The configuration type for the port |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
Example
#define ANALOG_SENSOR_PORT 1 void initialize() { pros::adi::Port 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); }
std::int32_t set_value(std::int32_t value) const
#include <pros/adi.hpp>
Sets the value for the given ADI port.
Parameters | |
---|---|
value | The value to set the ADI port to |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
This only works on ports configured as outputs, and the behavior will change depending on the configuration of the port.
Example
#define DIGITAL_SENSOR_PORT 1 void initialize() { pros::adi::Port sensor (DIGITAL_SENSOR_PORT, E_ADI_DIGITAL_OUT); sensor.set_value(DIGITAL_SENSOR_PORT, HIGH); }
ext_adi_port_tuple_t get_port() const virtual
#include <pros/adi.hpp>
Gets the port of the sensor.
Returns | returns a tuple of integer ports. |
---|
Example
#define DIGITAL_SENSOR_PORT 1 // 'A' void initialize() { pros::adi::AnalogIn sensor (DIGITAL_SENSOR_PORT); // Getting values from the tuple using std::get<index> int sensorSmartPort = std::get<0>(sensor.get_port()); // First value int sensorAdiPort = std::get<1>(sensor.get_port()); // Second value // Prints the first and second value from the port tuple (The Adi Port. The first value is the Smart Port) printf("Sensor Smart Port: %d\n", sensorSmartPort); printf("Sensor Adi Port: %d\n", sensorAdiPort); }
AnalogIn(std::uint8_t adi_port) explicit
#include <pros/adi.hpp>
Configures an ADI port to act as an Analog Input.
Parameters | |
---|---|
adi_port | The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define ANALOG_SENSOR_PORT 1 void opcontrol() { pros::ADIAnalogIn sensor (ANALOG_SENSOR_PORT); while (true) { // Use the sensor } }
AnalogIn(ext_adi_port_pair_t port_pair) explicit
#include <pros/adi.hpp>
Configures an ADI port to act as an Analog Input.
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
---|
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#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 } }
std::int32_t calibrate() const
#include <pros/adi.hpp>
Calibrates the analog sensor on the specified port and returns the new calibration value.
Returns | The average sensor value computed by this function |
---|
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 pros::AnalogIn::get_value_calibrated() and pros::AnalogIn::get_value_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).
This function uses the following values of errno when an error state is reached: ENODEV - The port is not configured as an analog input
Example
#define ANALOG_SENSOR_PORT 1 void initialize() { pros::adi::AnalogIn 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 }
std::int32_t get_value_calibrated() const
#include <pros/adi.hpp>
Gets the 12 bit calibrated value of an analog input port.
Returns | The difference of the sensor value from its calibrated default from -4095 to 4095 |
---|
The pros::
This function uses the following values of errno when an error state is reached: ENODEV - The port is not configured as an analog input
Example
#define ANALOG_SENSOR_PORT 1 void initialize() { pros::adi::AnalogIn 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 }
std::int32_t get_value_calibrated_HR() const
#include <pros/adi.hpp>
Gets the 16 bit calibrated value of an analog input port.
Returns | The difference of the sensor value from its calibrated default from -16384 to 16384 |
---|
The pros::
The value returned actually has 16 bits of "precision", even though the ADC only reads 12 bits, so that error induced by the average value being between two values when integrated over time is trivial. Think of the value as the true value times 16.
This function uses the following values of errno when an error state is reached: ENODEV - The port is not configured as an analog input
Example
#define ANALOG_SENSOR_PORT 1 void initialize() { pros::adi::AnalogIn 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 }
AnalogOut(std::uint8_t adi_port) explicit
#include <pros/adi.hpp>
Configures an ADI port to act as an Analog Output.
Parameters | |
---|---|
adi_port | The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define ANALOG_SENSOR_PORT 1 void opcontrol() { pros::AnalogOut sensor (ANALOG_SENSOR_PORT); // Use the sensor }
AnalogOut(ext_adi_port_pair_t port_pair) explicit
#include <pros/adi.hpp>
Configures an ADI port on an adi_expander to act as an Analog Output.
Parameters | |
---|---|
port_pair | The pair of the smart port number (from 1-22) and the ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define EXT_ADI_SMART_PORT 1 #define ADI_PORT 'a' void opcontrol() { pros::AnalogOut sensor ({{EXT_ADI_SMART_PORT, ADI_PORT}}); // Use the sensor }
DigitalOut(std::uint8_t adi_port,
bool init_state = LOW) explicit
#include <pros/adi.hpp>
Configures an ADI port to act as a Digital Output.
Parameters | |
---|---|
adi_port | The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
init_state | The initial state for the port |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define DIGITAL_SENSOR_PORT 1 void opcontrol() { bool state = LOW; pros::adi::DigitalOut sensor (DIGITAL_SENSOR_PORT, state); while (true) { state != state; sensor.set_value(state); pros::delay(10); // toggle the sensor value every 50ms } }
DigitalOut(ext_adi_port_pair_t port_pair,
bool init_state = LOW) explicit
#include <pros/adi.hpp>
Configures an ADI port on an adi_expander to act as a Digital Output.
Parameters | |
---|---|
port_pair | The pair of the smart port number (from 1-22) and the ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
init_state | The initial state for the port |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define EXT_ADI_SMART_PORT 1 #define ADI_PORT 'a' void opcontrol() { bool state = LOW; pros::adi::DigitalOut sensor ( {{ EXT_ADI_SMART_PORT , ADI_PORT }}); while (true) { state != state; sensor.set_value(state); pros::delay(10); // toggle the sensor value every 50ms } }
DigitalIn(std::uint8_t adi_port) explicit
#include <pros/adi.hpp>
Configures an ADI port to act as a Digital Input.
Parameters | |
---|---|
adi_port | The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define DIGITAL_SENSOR_PORT 1 void opcontrol() { pros::adi::DigitalIn sensor (ANALOG_SENSOR_PORT); // Use the sensor }
DigitalIn(ext_adi_port_pair_t port_pair) explicit
#include <pros/adi.hpp>
Configures an ADI port on an adi_expander to act as a Digital Input.
Parameters | |
---|---|
port_pair | The pair of the smart port number (from 1-22) and the ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define EXT_ADI_SMART_PORT 1 #define ADI_PORT 'a' void opcontrol() { pros::adi::DigitalIn sensor ({{EXT_ADI_SMART_PORT, ADI_PORT}}); // Use the sensor }
std::int32_t get_new_press() const
#include <pros/adi.hpp>
Gets a rising-edge case for a digital button press.
Returns | 1 if the button is pressed and had not been pressed the last time this function was called, 0 otherwise. |
---|
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: ENODEV - The port is not configured as a digital input
Example
#define DIGITAL_SENSOR_PORT 1 void opcontrol() { pros::adi::DigitalIn sensor (DIGITAL_SENSOR_PORT); while (true) { if (sensor.get_new_press()) { // Toggle pneumatics or other state operations } pros::delay(10); } }
Motor(std::uint8_t adi_port) explicit
#include <pros/adi.hpp>
Configures an ADI port to act as a Motor.
Parameters | |
---|---|
adi_port | The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define MOTOR_PORT 1 void opcontrol() { pros::adi::Motor 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 }
Motor(ext_adi_port_pair_t port_pair) explicit
#include <pros/adi.hpp>
Configures an ADI port on an adi_expander to act as a Motor.
Parameters | |
---|---|
port_pair | The pair of the smart port number (from 1-22) and the ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define EXT_ADI_SMART_PORT 1 #define ADI_MOTOR_PORT 'a' void opcontrol() { pros::adi::Motor 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 }
std::int32_t stop() const
#include <pros/adi.hpp>
Stops the motor on the given port.
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
---|
This function uses the following values of errno when an error state is reached: ENODEV - The port is not configured as a motor
Example
#define MOTOR_PORT 1 void opcontrol() { pros::adi::Motor 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 }
Encoder(std::uint8_t adi_port_top,
std::uint8_t adi_port_bottom,
bool reversed = false) explicit
#include <pros/adi.hpp>
Configures a set of ADI ports to act as an Encoder.
Parameters | |
---|---|
adi_port_top | The "top" wire from the encoder sensor with the removable cover side up |
adi_port_bottom | The "bottom" wire from the encoder sensor |
reversed |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define PORT_TOP 1 #define PORT_BOTTOM 2 void opcontrol() { pros::adi::Encoder sensor (PORT_TOP, PORT_BOTTOM, false); // Use the sensor }
Encoder(ext_adi_port_tuple_t port_tuple,
bool reversed = false) explicit
#include <pros/adi.hpp>
Configures a set of ADI ports on an adi_expander to act as an Encoder.
Parameters | |
---|---|
port_tuple | The tuple of the smart port number, the "top" wire from the encoder sensor with the removable cover side up, and the "bottom" wire from the encoder sensor |
reversed |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define PORT_TOP 'A' #define PORT_BOTTOM 'B' #define SMART_PORT 1 void opcontrol() { pros::adi::Encoder sensor ({ SMART_PORT, PORT_TOP, PORT_BOTTOM }, false); // Use the sensor }
std::int32_t reset() const
#include <pros/adi.hpp>
Sets the encoder value to zero.
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
---|
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: ENODEV - The port is not configured as a motor
Example
#define PORT_TOP 1 #define PORT_BOTTOM 2 void opcontrol() { pros::adi::Encoder sensor (PORT_TOP, PORT_BOTTOM, false); delay(1000); // Move the encoder around in this time sensor.reset(); // The encoder is now zero again }
std::int32_t get_value() const
#include <pros/adi.hpp>
Gets the number of ticks recorded by the encoder.
Returns | The signed and cumulative number of counts since the last start or |
---|
There are 360 ticks in one revolution.
This function uses the following values of errno when an error state is reached: ENODEV - The port is not configured as a motor
Example
#define PORT_TOP 1 #define PORT_BOTTOM 2 void opcontrol() { pros::adi::Encoder sensor (PORT_TOP, PORT_BOTTOM, false); while (true) { std::cout << "Encoder Value: " << sensor.get_value(); pros::delay(10); } }
ext_adi_port_tuple_t get_port() const override
#include <pros/adi.hpp>
Gets the port of the sensor.
Returns | returns a tuple of integer ports. |
---|
Example
#define DIGITAL_SENSOR_PORT 1 // 'A' void initialize() { pros::adi::AnalogIn sensor (DIGITAL_SENSOR_PORT); // Getting values from the tuple using std::get<index> int sensorSmartPort = std::get<0>(sensor.get_port()); // First value int sensorAdiPort = std::get<1>(sensor.get_port()); // Second value // Prints the first and second value from the port tuple (The Adi Port. The first value is the Smart Port) printf("Sensor Smart Port: %d\n", sensorSmartPort); printf("Sensor Adi Port: %d\n", sensorAdiPort); }
Ultrasonic(std::uint8_t adi_port_ping,
std::uint8_t adi_port_echo) explicit
#include <pros/adi.hpp>
Configures a set of ADI ports to act as an Ultrasonic sensor.
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define PORT_PING 1 #define PORT_ECHO 2 void opcontrol() { pros::adi::Ultrasonic sensor (PORT_PING, PORT_ECHO); while (true) { // Print the distance read by the ultrasonic std::cout << "Distance: " << sensor.get_value(); pros::delay(10); } }
Ultrasonic(ext_adi_port_tuple_t port_tuple) explicit
#include <pros/adi.hpp>
Configures a set of ADI ports on an adi_expander to act as an Ultrasonic sensor.
Parameters | |
---|---|
port_tuple | The tuple of the smart port number, the port connected to the orange OUTPUT cable (1, 3, 5, 7 or 'A', 'C', 'E', 'G'), and the port connected to the yellow INPUT cable (the next) highest port following port_ping). |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define PORT_PING 'A' #define PORT_ECHO 'B' #define SMART_PORT 1 void opcontrol() { pros::adi::Ultrasonic 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); } }
std::int32_t get_value() const
#include <pros/adi.hpp>
Gets the current ultrasonic sensor value in centimeters.
Returns | The distance to the nearest object in m^-4 (10000 indicates 1 meter), measured from the sensor's mounting points. |
---|
If no object was found, zero is returned. If the ultrasonic sensor was never started, the return value is undefined. Round and fluffy objects can cause inaccurate values to be returned.
This function uses the following values of errno when an error state is reached: ENODEV - The port is not configured as an ultrasonic
Example
#define PORT_PING 1 #define PORT_ECHO 2 void opcontrol() { pros::adi::Ultrasonic sensor (PORT_PING, PORT_ECHO); while (true) { // Print the distance read by the ultrasonic std::cout << "Distance: " << sensor.get_value(); pros::delay(10); } }
Gyro(std::uint8_t adi_port,
double multiplier = 1) explicit
#include <pros/adi.hpp>
Initializes a gyroscope on the given port.
Parameters | |
---|---|
adi_port | The ADI port to initialize as a gyro (from 1-8, 'a'-'h', 'A'-'H') |
multiplier | A scalar value that will be multiplied by the gyro heading value supplied by the |
If the given port has not previously been configured as a gyro, then this function starts a 1300ms calibration period.
It is highly recommended that an Gyro object be created in initialize() when the robot is stationary to ensure proper calibration. If an Gyro object is declared at the global scope, a hardcoded 1300ms delay at the beginning of initialize will be necessary to ensure that the gyro's returned values are correct at the beginning of autonomous/opcontrol.
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define GYRO_PORT 1 void opcontrol() { pros::adi::Gyro gyro (GYRO_PORT); while (true) { // Get the gyro heading std::cout << "Distance: " << gyro.get_value(); pros::delay(10); } }
Gyro(ext_adi_port_pair_t port_pair,
double multiplier = 1) explicit
#include <pros/adi.hpp>
Initializes a gyroscope on the given port of an adi expander.
Parameters | |
---|---|
port_pair | The pair of the smart port number (from 1-22) and the ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
multiplier | A scalar value that will be multiplied by the gyro heading value supplied by the |
If the given port has not previously been configured as a gyro, then this function starts a 1300ms calibration period.
It is highly recommended that an adi::
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define ADI_GYRO_PORT 'a' #define SMART_PORT 1 void opcontrol() { pros::adi::Gyro gyro ({{ SMART_PORT , ADI_GYRO_PORT }}); while (true) { // Get the gyro heading std::cout << "Distance: " << gyro.get_value(); pros::delay(10); } }
double get_value() const
#include <pros/adi.hpp>
Gets the current gyro angle in tenths of a degree.
Returns | The gyro angle in degrees. |
---|
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: ENODEV - The port is not configured as a gyro
Example
#define GYRO_PORT 1 void opcontrol() { pros::adi::Gyro gyro (GYRO_PORT); while (true) { // Get the gyro heading std::cout << "Distance: " << gyro.get_value(); pros::delay(10); } }
std::int32_t reset() const
#include <pros/adi.hpp>
Resets the gyroscope value to zero.
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
---|
This function uses the following values of errno when an error state is reached: ENODEV - The port is not configured as a gyro
Example
#define GYRO_PORT 1 void opcontrol() { pros::adi::Gyro 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); } }
Potentiometer(std::uint8_t adi_port,
adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR) explicit
#include <pros/adi.hpp>
Configures an ADI port to act as a Potentiometer.
Parameters | |
---|---|
adi_port | The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
potentiometer_type | An adi_potentiometer_type_e_t enum value specifying the potentiometer version type |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define POTENTIOMETER_PORT 1 #define POTENTIOMETER_TYPE pros::E_ADI_POT_EDR void opcontrol() { pros::adi::Potentiometer potentiometer (POTENTIOMETER_PORT, POTENTIOMETER_TYPE); while (true) { // Get the potentiometer angle std::cout << "Angle: " << potentiometer.get_angle(); pros::delay(10); } }
Potentiometer(ext_adi_port_pair_t port_pair,
adi_potentiometer_type_e_t potentiometer_type = E_ADI_POT_EDR) explicit
#include <pros/adi.hpp>
Configures an ADI port on an adi_expander to act as a Potentiometer.
Parameters | |
---|---|
port_pair | |
potentiometer_type | An adi_potentiometer_type_e_t enum value specifying the potentiometer version type |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example
#define ADI_POTENTIOMETER_PORT 'a' #define SMART_PORT 1 void opcontrol() { pros::adi::Potentiometer potentiometer ({{ SMART_PORT , ADI_POTENTIOMETER_PORT }}); while (true) { // Get the potentiometer angle std::cout << "Angle: " << potentiometer.get_angle(); pros::delay(10); } }
double get_angle() const
#include <pros/adi.hpp>
Gets the current potentiometer angle in tenths of a degree.
Returns | The potentiometer angle in degrees. |
---|
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: ENXIO - The given value is not within the range of ADI Ports EADDRINUSE - The port is not configured as a potentiometer
Example
#define ADI_POTENTIOMETER_PORT 'a' #define SMART_PORT 1 void opcontrol() { pros::adi::Potentiometer potentiometer ({{ SMART_PORT , ADI_POTENTIOMETER_PORT }}); while (true) { // Get the potentiometer angle std::cout << "Angle: " << potentiometer.get_angle(); pros::delay(10); } }
Led(std::uint8_t adi_port,
std::uint32_t length) explicit
#include <pros/adi.hpp>
Configures an ADI port to act as a LED.
Parameters | |
---|---|
adi_port | The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
length | The number of LEDs in the chain |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example:
#define LED_PORT 'a' #define LED_LENGTH 3 void opcontrol() { pros::Led led (LED_PORT, LED_LENGTH); while (true) { // Set entire LED strip to red led.set_all(0xFF0000); pros::delay(20); } }
Led(ext_adi_port_pair_t port_pair,
std::uint32_t length) explicit
#include <pros/adi.hpp>
Configures an ADI port on a adi_expander to act as a LED.
Parameters | |
---|---|
port_pair | The pair of the smart port number (from 1-22) and the ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
length | The number of LEDs in the chain |
This function uses the following values of errno when an error state is reached: ENXIO - Either the ADI port value or the smart port value is not within its valid range (ADI port: 1-8, 'a'-'h', or 'A'-'H'; smart port: 1-21).
Example:
#define LED_PORT 'a' #define SMART_PORT 1 #define LED_LENGTH 3 void opcontrol() { pros::Led led ({{ SMART_PORT , LED_PORT }}, LED_LENGTH); while (true) { // Set entire LED strip to red led.set_all(0xFF0000); pros::delay(20); } }
std::int32_t clear_all()
#include <pros/adi.hpp>
Operator overload to access the buffer in the ADILed class, it is recommended that you call .update(); after doing any operations with this.
Returns | uint32_t& the address of the buffer at i to modify |
---|
Example:
#define LED_PORT 'a' #define LED_LENGTH 3 void opcontrol() { pros::Led led (LED_PORT, LED_LENGTH); while (true) { // Set the first 3 pixels to red, green, and blue led.set_pixel(0xFF0000, 0); led.set_pixel(0x00FF00, 1); led.set_pixel(0x0000FF, 2); pros::delay(20); // Use the [] operator to set the first pixel to black led.operator[](0) = 0x000000; led.update(); pros::delay(20); } } / std::uint32_t& operator[] (size_t i); /** * @brief Clear the entire led strip of color * * This function uses the following values of errno when an error state is * reached: * ENXIO - The given value is not within the range of ADI Ports * EINVAL - A parameter is out of bounds/incorrect * EADDRINUSE - The port is not configured for ADI output * * @return PROS_SUCCESS if successful, PROS_ERR if not * * \b Example: * \code * #define LED_PORT 'a' * #define LED_LENGTH 3 * * void opcontrol() { * pros::Led led (LED_PORT, LED_LENGTH); * while (true) { * // Set the first 3 pixels to red, green, and blue * led.set_pixel(0xFF0000, 0); * led.set_pixel(0x00FF00, 1); * led.set_pixel(0x0000FF, 2); * pros::delay(20); * * // Clear the led strip of color * led.clear(); * pros::delay(20); * } * } *
std::int32_t clear()
#include <pros/adi.hpp>
std::int32_t update() const
#include <pros/adi.hpp>
Force the LED strip to update with the current buffered values, this should be called after any changes to the buffer using the [] operator.
Returns | PROS_SUCCESS if successful, PROS_ERR if not |
---|
This function uses the following values of errno when an error state is reached: EINVAL - A parameter is out of bounds/incorrect EADDRINUSE - The port is not configured for ADI output
Example:
#define LED_PORT 'a' #define LED_LENGTH 3 void opcontrol() { pros::Led led (LED_PORT, LED_LENGTH); while (true) { // Set the first 3 pixels to red, green, and blue led.set_pixel(0xFF0000, 0); led.set_pixel(0x00FF00, 1); led.set_pixel(0x0000FF, 2); pros::delay(20); // Use the [] operator to set the first pixel to black led.operator[](0) = 0x000000; // Update the led strip with the new values led.update(); pros::delay(20); } }
std::int32_t set_all(uint32_t color)
#include <pros/adi.hpp>
Set the entire led strip to one color.
Parameters | |
---|---|
color | color to set all the led strip value to |
Returns | PROS_SUCCESS if successful, PROS_ERR if not |
This function uses the following values of errno when an error state is reached: EINVAL - A parameter is out of bounds/incorrect EADDRINUSE - The port is not configured for ADI output
Example:
#define LED_PORT 'a' #define LED_LENGTH 3 void opcontrol() { pros::Led led (LED_PORT, LED_LENGTH); while (true) { // Set the entire led strip to blue led.set_all(0x0000FF); pros::delay(20); } }
std::int32_t set_pixel(uint32_t color,
uint32_t pixel_position)
#include <pros/adi.hpp>
Set one pixel on the led strip.
Parameters | |
---|---|
color | color to clear all the led strip to |
pixel_position | position of the pixel to clear |
Returns | PROS_SUCCESS if successful, PROS_ERR if not |
This function uses the following values of errno when an error state is reached: EINVAL - A parameter is out of bounds/incorrect EADDRINUSE - The port is not configured for ADI output
Example:
#define LED_PORT 'a' #define LED_LENGTH 3 void opcontrol() { pros::Led led (LED_PORT, LED_LENGTH); while (true) { // Set the first pixel to blue led.set_pixel(0x0000FF, 0); pros::delay(20); } }
std::int32_t clear_pixel(uint32_t pixel_position)
#include <pros/adi.hpp>
Clear one pixel on the led strip.
Parameters | |
---|---|
pixel_position | position of the pixel to clear |
Returns | PROS_SUCCESS if successful, PROS_ERR if not |
This function uses the following values of errno when an error state is reached: EINVAL - A parameter is out of bounds/incorrect EADDRINUSE - The port is not configured for ADI output
Example:
#define LED_PORT 'a' #define LED_LENGTH 3 void opcontrol() { pros::Led led (LED_PORT, LED_LENGTH); while (true) { // Set the first pixel to blue led.set_pixel(0x0000FF, 0); pros::delay(20); // Clear the first pixel led.clear_pixel(0); pros::delay(20); } }
std::int32_t length()
#include <pros/adi.hpp>
Get the length of the led strip.
Returns | The length (in pixels) 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/incorrect EADDRINUSE - The port is not configured for ADI output
Example:
#define LED_PORT 'a' #define LED_LENGTH 3 void opcontrol() { pros::Led led (LED_PORT, LED_LENGTH); while (true) { // Get the length of the led strip int length = led.length(); pros::lcd::print(1, "Length: %d", length); pros::delay(20); } }
Pneumatics(std::uint8_t adi_port,
bool start_extended,
bool extended_is_low = false) explicit
#include <pros/adi.hpp>
Creates a Pneumatics object for the given port.
Parameters | |
---|---|
adi_port | The ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
start_extended | If true, the pneumatic will start extended when the program starts. By default, the piston starts retracted when the program starts. |
extended_is_low | A flag to set whether the the pneumatic is extended when the ADI it receives a high or a low value. When true, the extended state corresponds to a output low on the ADI port. This allows the user to reverse the behavior of the pneumatics if needed. |
This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of ADI Ports
/b Example:
void opcontrol() { pros::adi::Pneumatics left_piston('a', false); // Starts retracted, extends when the ADI port is high pros::adi::Pneumatics right_piston('b', false, true); // Starts retracted, extends when the ADI port is low pros::Controller master(pros::E_CONTROLLER_MASTER); while (true) { if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L1)) { left_piston.extend(); } if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L2)) { left_piston.retract(); } if(master.get_digital(pros::E_CONTROLLER_DIGITAL_R1)) { left_piston.extend(); } if(master.get_digital(pros::E_CONTROLLER_DIGITAL_2)) { left_piston.retract(); } pros::delay(10); }
Pneumatics(ext_adi_port_pair_t port_pair,
bool start_extended,
bool extended_is_low = false) explicit
#include <pros/adi.hpp>
Creates a Pneumatics object for the given port pair.
Parameters | |
---|---|
port_pair | The pair of the smart port number (from 1-22) and the ADI port number (from 1-8, 'a'-'h', 'A'-'H') to configure |
start_extended | If true, the pneumatic will start extended when the program starts. By default, the piston starts retracted when the program starts. |
extended_is_low | A flag to set whether the the pneumatic is extended when the ADI it receives a high or a low value. When true, the extended state corresponds to a output low on the ADI port. This allows the user to reverse the behavior of the pneumatics if needed. |
This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of ADI Ports
/b Example:
void opcontrol() { pros::adi::Pneumatics left_piston({1, 'a'}, false); // Starts retracted, extends when the ADI port is high pros::adi::Pneumatics right_piston({1, 'b'}, false, true); // Starts retracted, extends when the ADI port is low pros::Controller master(pros::E_CONTROLLER_MASTER); while (true) { if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L1)) { left_piston.extend(); } if(master.get_digital(pros::E_CONTROLLER_DIGITAL_L2)) { left_piston.retract(); } if(master.get_digital(pros::E_CONTROLLER_DIGITAL_R1)) { left_piston.extend(); } if(master.get_digital(pros::E_CONTROLLER_DIGITAL_R2)) { left_piston.retract(); } pros::delay(10); } }
std::int32_t extend()
#include <pros/adi.hpp>
Extends the piston, if not already extended.
Returns | 1 if the piston newly extended, 0 if the piston was already extended, or PROS_ERR is the operation failed, setting errno. |
---|
Example:
void opcontrol() { pros::adi::Pneumatics piston({1, 'a'}, false); // Starts retracted, extends when the ADI port is high pros::Controller master(pros::E_CONTROLLER_MASTER); while (true) { if(master.get_digital(pros::E_CONTROLLER_DIGITAL_X)) { left_piston.extend(); } if(master.get_digital(pros::E_CONTROLLER_DIGITAL_B)) { left_piston.retract(); } if(mastetr.get_digital(pros::E_CONTROLLER_DIGITAL_A)) { left_piston.toggle(); } pros::delay(10); } }
std::int32_t retract()
#include <pros/adi.hpp>
Retracts the piston, if not already retracted.
Returns | 1 if the piston newly retracted, 0 if the piston was already retracted, or PROS_ERR is the operation failed, setting errno. |
---|
Example:
void opcontrol() { pros::adi::Pneumatics piston({1, 'a'}, false); // Starts retracted, extends when the ADI port is high pros::Controller master(pros::E_CONTROLLER_MASTER); while (true) { if(master.get_digital(pros::E_CONTROLLER_DIGITAL_X)) { left_piston.extend(); } if(master.get_digital(pros::E_CONTROLLER_DIGITAL_B)) { left_piston.retract(); } if(mastetr.get_digital(pros::E_CONTROLLER_DIGITAL_A)) { left_piston.toggle(); } pros::delay(10); } }
std::int32_t toggle()
#include <pros/adi.hpp>
Puts the piston into the opposite state of its current state.
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
---|
If it is retracted, it will extend. If it is extended, it will retract.
Example:
void opcontrol() { pros::adi::Pneumatics piston({1, 'a'}, false); // Starts retracted, extends when the ADI port is high pros::Controller master(pros::E_CONTROLLER_MASTER); while (true) { if(master.get_digital(pros::E_CONTROLLER_DIGITAL_X)) { left_piston.extend(); } if(master.get_digital(pros::E_CONTROLLER_DIGITAL_B)) { left_piston.retract(); } if(mastetr.get_digital(pros::E_CONTROLLER_DIGITAL_A)) { left_piston.toggle(); } pros::delay(10); } }
bool is_extended() const
#include <pros/adi.hpp>
Returns whether the piston is extended or not.
Returns | true if the piston is extended, false if it is retracted. |
---|
Example
#define ADI_PNEUMATICS_PORT 'a' void opcontrol() { pros::adi::Pneumatics pneumatics (ADI_PNEUMATICS_PORT); while (true) { // Check if the piston is extended if (pneumatics.is_extended()) { printf("The pneumatic is extended\n"); } else { printf("The pneumatic is not extended\n"); } pros::delay(10); } }
Variable documentation
std::uint8_t _smart_port
#include <pros/adi.hpp>
std::uint8_t _adi_port
#include <pros/adi.hpp>
ext_adi_port_pair_t _port_pair
#include <pros/adi.hpp>
std::vector<uint32_t> _buffer
#include <pros/adi.hpp>
bool state
#include <pros/adi.hpp>
bool extended_is_low
#include <pros/adi.hpp>