pros::adi::Potentiometer class

Base classes

class AnalogIn

Constructors, destructors, conversion operators

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.

Public functions

double get_angle() const
Gets the current potentiometer angle in tenths of a degree.
std::int32_t get_value() const
Gets the 12-bit value of the specified port.
std::int32_t calibrate() const
Calibrates the potentiometer on the specified port and returns the new calibration value.
std::int32_t get_value_calibrated() const
Gets the 12 bit calibrated value of a potentiometer port.
ext_adi_port_tuple_t get_port() const
Gets the port of the sensor.

Friends

std::ostream& operator<<(std::ostream& os, pros::adi::Potentiometer& potentiometer)
This is the overload for the << operator for printing to streams Potentiometer [value: (value), value calibrated: (calibrated value), angle: (angle)] Prints in format(this below is all in one line with no new line):

Function documentation

std::int32_t pros::adi::Potentiometer::get_value() const

Gets the 12-bit value of the specified port.

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

The value returned is undefined if the analog pin has been switched to a different mode.

This function uses the following values of errno when an error state is reached: ENODEV - The port is not configured as a potentiometer

std::int32_t pros::adi::Potentiometer::calibrate() const

Calibrates the potentiometer on the specified port and returns the new calibration value.

Returns The average potentiometer value computed by this function

This method assumes that the potentiometer 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::adi::Potentiometer::get_value_calibrated() function. This function will return the difference between this value and the current sensor value when called.

Do not use this function when the potentiometer value might be unstable (rotating the potentiometer)

This function uses the following values of errno when an error state is reached: ENODEV - The port is not configured as a potentiometer

std::int32_t pros::adi::Potentiometer::get_value_calibrated() const

Gets the 12 bit calibrated value of a potentiometer port.

Returns The difference of the potentiometer value from its calibrated default from -4095 to 4095

The pros::adi::Potentiometer::calibrate() function must be run first.

This function uses the following values of errno when an error state is reached: ENODEV - The port is not configured as a potentiometer

ext_adi_port_tuple_t pros::adi::Potentiometer::get_port() const

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);   
}