class
#include <pros/adi.hpp>
Motor
Constructors, destructors, conversion operators
- 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.
Public functions
- std::int32_t stop() const
- Stops the motor on the given port.
- std::int32_t set_value(std::int32_t value) const
- Sets the speed of the motor on the given port.
- std::int32_t get_value() const
- Gets the last set speed of the motor on the given port.
-
ext_
adi_ port_ tuple_ t get_port() const - Gets the port of the sensor.
Function documentation
std::int32_t pros:: adi:: Motor:: set_value(std::int32_t value) const
Sets the speed of the motor on the given port.
Parameters | |
---|---|
value | The new signed speed; -127 is full reverse and 127 is full forward, with 0 being off |
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.set_value(0); // Stop the motor }
std::int32_t pros:: adi:: Motor:: get_value() const
Gets the last set speed of the motor on the given port.
Returns | The last set speed of the motor on the given |
---|
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.set_value(0); // Stop the motor }
ext_ adi_ port_ tuple_ t pros:: adi:: Motor:: 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); }