Motors C++ API module
Contents
Files
- file motors.hpp
Functions
-
Motor(const std::int8_t port,
const pros::
v5:: MotorGears gearset = pros:: v5:: MotorGears:: invalid, const pros:: v5:: MotorUnits encoder_units = pros::v5::MotorUnits::invalid) - Constructs a new Motor object.
- Motor(const Device& device)
-
const pros::
Motor operator""_mtr(const unsigned long long int m) - Constructs a Motor from a literal ending in _mtr.
-
const pros::
Motor operator""_rmtr(const unsigned long long int m) - Constructs a reversed Motor from a literal ending in _rmtr.
Motor movement functions
These functions allow programmers to make motors move
- std::int32_t move(std::int32_t voltage) const virtual
- Sets the voltage for the motor from -127 to 127.
- std::int32_t move_absolute(const double position, const std::int32_t velocity) const virtual
- Sets the target absolute position for the motor to move to.
- std::int32_t move_relative(const double position, const std::int32_t velocity) const virtual
- Sets the relative target position for the motor to move to.
- std::int32_t move_velocity(const std::int32_t velocity) const virtual
- Sets the velocity for the motor.
- std::int32_t move_voltage(const std::int32_t voltage) const virtual
- Sets the output voltage for the motor from -12000 to 12000 in millivolts.
- std::int32_t brake(void) const virtual
- Stops the motor using the currently configured brake mode.
- std::int32_t modify_profiled_velocity(const std::int32_t velocity) const virtual
- Changes the output velocity for a profiled movement (motor_move_absolute or motor_move_relative).
Motor telemetry functions
These functions allow programmers to collect telemetry from motors
- double get_target_position(const std::uint8_t index = 0) const virtual
- Gets the target position set for the motor by the user.
- std::int32_t get_target_velocity(const std::uint8_t index = 0) const virtual
- Gets the velocity commanded to the motor by the user at the index specified.
- double get_actual_velocity(const std::uint8_t index = 0) const virtual
- Gets the actual velocity of the motor.
- std::int32_t get_current_draw(const std::uint8_t index = 0) const virtual
- Gets the current drawn by the motor in mA.
- std::int32_t get_direction(const std::uint8_t index = 0) const virtual
- Gets the direction of movement for the motor.
- double get_efficiency(const std::uint8_t index = 0) const virtual
- Gets the efficiency of the motor in percent.
- std::uint32_t get_faults(const std::uint8_t index = 0) const virtual
- Gets the faults experienced by the motor.
- std::uint32_t get_flags(const std::uint8_t index = 0) const virtual
- Gets the flags set by the motor's operation.
- double get_position(const std::uint8_t index = 0) const virtual
- Gets the absolute position of the motor in its encoder units.
- double get_power(const std::uint8_t index = 0) const virtual
- Gets the power drawn by the motor in Watts.
- std::int32_t get_raw_position(std::uint32_t*const timestamp, const std::uint8_t index = 0) const virtual
- Gets the raw encoder count of the motor at a given timestamp.
- double get_temperature(const std::uint8_t index = 0) const virtual
- Gets the temperature of the motor in degrees Celsius.
- double get_torque(const std::uint8_t index = 0) const virtual
- Gets the torque generated by the motor in Newton Meters (Nm).
- std::int32_t get_voltage(const std::uint8_t index = 0) const virtual
- Gets the voltage delivered to the motor in millivolts.
- std::int32_t is_over_current(const std::uint8_t index = 0) const virtual
- Checks if the motor is drawing over its current limit.
- std::int32_t is_over_temp(const std::uint8_t index = 0) const virtual
- Gets the temperature limit flag for the motor.
Motor configuration functions
These functions allow programmers to configure the behavior of motors
- MotorBrake get_brake_mode(const std::uint8_t index = 0) const virtual
- Gets the brake mode that was set for the motor.
- std::int32_t get_current_limit(const std::uint8_t index = 0) const virtual
- Gets the current limit for the motor in mA.
- MotorUnits get_encoder_units(const std::uint8_t index = 0) const virtual
- Gets the encoder units that were set for the motor.
- MotorGears get_gearing(const std::uint8_t index = 0) const virtual
- Gets the gearset that was set for the motor.
- std::int32_t get_voltage_limit(const std::uint8_t index = 0) const virtual
- Gets the voltage limit set by the user.
- std::int32_t is_reversed(const std::uint8_t index = 0) const virtual
- Gets whether the motor is reversed or not.
- std::int32_t set_brake_mode(const MotorBrake mode, const std::uint8_t index = 0) const virtual
- Sets one of Motor_Brake to the motor.
- std::int32_t set_brake_mode(const pros::motor_brake_mode_e_t mode, const std::uint8_t index = 0) const virtual
- Sets one of MotorBrake to the motor.
- std::int32_t set_current_limit(const std::int32_t limit, const std::uint8_t index = 0) const virtual
- Sets the current limit for the motor in mA.
- std::int32_t set_encoder_units(const MotorUnits units, const std::uint8_t index = 0) const virtual
- Sets one of MotorUnits for the motor encoder.
- std::int32_t set_encoder_units(const pros::motor_encoder_units_e_t units, const std::uint8_t index = 0) const virtual
- Sets one of MotorUnits for the motor encoder.
- std::int32_t set_gearing(const MotorGears gearset, const std::uint8_t index = 0) const virtual
- Sets one of the gear cartridge (red, green, blue) for the motor.
- std::int32_t set_gearing(const pros::motor_gearset_e_t gearset, const std::uint8_t index = 0) const virtual
- Sets one of the gear cartridge (red, green, blue) for the motor.
- std::int32_t set_reversed(const bool reverse, const std::uint8_t index = 0) virtual
- Sets the reverse flag for the motor.
- std::int32_t set_voltage_limit(const std::int32_t limit, const std::uint8_t index = 0) const virtual
- Sets the voltage limit for the motor in Volts.
- std::int32_t set_zero_position(const double position, const std::uint8_t index = 0) const virtual
- Sets the position for the motor in its encoder units.
- std::int32_t tare_position(const std::uint8_t index = 0) const virtual
- Sets the "absolute" zero position of the motor to its current position.
- std::int8_t size(void) const virtual
- Gets the number of motors.
- static std::vector<Motor> get_all_devices()
- Gets all motors.
- std::int8_t get_port(const std::uint8_t index = 0) const virtual
- gets the port number of the motor
Additional motor functions
These functions allow for motors and motor groups to be used interchangeably
- std::vector<double> get_target_position_all(void) const virtual
- Gets a vector containing the target position set for the motor by the user.
- std::vector<std::int32_t> get_target_velocity_all(void) const virtual
- Gets a vector containing the velocity commanded to the motor by the user.
- std::vector<double> get_actual_velocity_all(void) const virtual
- Gets a vector containing the actual velocity commanded of the motor.
- std::vector<std::int32_t> get_current_draw_all(void) const virtual
- Gets a vector containing the current drawn by the motor in mA.
- std::vector<std::int32_t> get_direction_all(void) const virtual
- Gets a vector containing the direction of movement for the motor.
- std::vector<double> get_efficiency_all(void) const virtual
- Gets a vector containing the efficiency of the motor in percent.
- std::vector<std::uint32_t> get_faults_all(void) const virtual
- Gets a vector of the faults experienced by the motor.
- std::vector<std::uint32_t> get_flags_all(void) const virtual
- Gets a vector of the flags set by the motor's operation.
- std::vector<double> get_position_all(void) const virtual
- Gets a vector containing the absolute position of the motor in its encoder units.
- std::vector<double> get_power_all(void) const virtual
- Gets a vector containing the power drawn by the motor in Watts.
- std::vector<std::int32_t> get_raw_position_all(std::uint32_t*const timestamp) const virtual
- Gets a vector of the raw encoder count of the motor at a given timestamp.
- std::vector<double> get_temperature_all(void) const virtual
- Gets a vector of the temperature of the motor in degrees Celsius.
- std::vector<double> get_torque_all(void) const virtual
- Gets a vector of the torque generated by the motor in Newton Meters (Nm).
- std::vector<std::int32_t> get_voltage_all(void) const virtual
- Gets a vector of the voltage delivered to the motor in millivolts.
- std::vector<std::int32_t> is_over_current_all(void) const virtual
- Checks if the motor is drawing over its current limit.
- std::vector<std::int32_t> is_over_temp_all(void) const virtual
- Gets the temperature limit flag for the motor.
- std::vector<MotorBrake> get_brake_mode_all(void) const virtual
- Gets a vector containing the brake mode that was set for the motor.
- std::vector<std::int32_t> get_current_limit_all(void) const virtual
- Gets a vector containing the current limit for the motor in mA.
- std::vector<MotorUnits> get_encoder_units_all(void) const virtual
- Gets a vector containing the encoder units that were set for the motor.
- std::vector<MotorGears> get_gearing_all(void) const virtual
- Gets a vector containing the gearset that was set for the motor.
- std::vector<std::int8_t> get_port_all(void) const virtual
- Gets returns a vector with all the port numbers in the motor group.
- std::vector<std::int32_t> get_voltage_limit_all(void) const virtual
- Gets a vector of the voltage limit set by the user.
- std::vector<std::int32_t> is_reversed_all(void) const virtual
- Gets a vector containg whether the motor is reversed or not.
- std::int32_t set_brake_mode_all(const MotorBrake mode) const virtual
- Sets one of Motor_Brake to the motor.
- std::int32_t set_brake_mode_all(const pros::motor_brake_mode_e_t mode) const virtual
- Sets one of Motor_Brake to the motor.
- std::int32_t set_current_limit_all(const std::int32_t limit) const virtual
- Sets the current limit for the motor in mA.
- std::int32_t set_encoder_units_all(const MotorUnits units) const virtual
- Sets one of Motor_Units for the motor encoder.
- std::int32_t set_encoder_units_all(const pros::motor_encoder_units_e_t units) const virtual
- Sets one of Motor_Units for the motor encoder.
- std::int32_t set_gearing_all(const MotorGears gearset) const virtual
- Sets one of the gear cartridge (red, green, blue) for the motor.
- std::int32_t set_gearing_all(const pros::motor_gearset_e_t gearset) const virtual
- Sets one of the gear cartridge (red, green, blue) for the motor.
- std::int32_t set_reversed_all(const bool reverse) virtual
- Sets the reverse flag for the motor.
- std::int32_t set_voltage_limit_all(const std::int32_t limit) const virtual
- Sets the voltage limit for the motor in Volts.
- std::int32_t set_zero_position_all(const double position) const virtual
- Sets the position for the motor in its encoder units.
- std::int32_t tare_position_all(void) const virtual
- Sets the "absolute" zero position of the motor to its current position.
Variables
- std::int8_t _port
- The port of the motor.
Function documentation
Motor(const std::int8_t port,
const pros:: v5:: MotorGears gearset = pros:: v5:: MotorGears:: invalid,
const pros:: v5:: MotorUnits encoder_units = pros::v5::MotorUnits::invalid)
#include <pros/motors.hpp>
Constructs a new Motor object.
Parameters | |
---|---|
port | The V5 port number from 1 to 21, or from -21 to -1 for reversed motors. A reversed motor will reverse the input or output movement functions and movement related telemetry in order to produce consistant behavior with non-reversed motors |
gearset | = pros:: |
encoder_units | = pros::v5::MotorUnits::degrees Optional parameter for the encoder units of the motor Does not explicitly set the gearset if not specified or if the gearset is invalid |
This function uses the following values of errno when an error state is reached: ENXIO - The given value is not within the range of V5 ports |1-21|. ENODEV - The port cannot be configured as a motor
Example
void opcontrol() { Motor first_motor(1); //Creates a motor on port 1 without altering gearset or encoder units Motor reversed_motor(-2); //Creates a reversed motor on port 1 port 1 without altering gearset or encoder units Motor blue_motor(3, pros::v5::MotorGears::blue); //Creates a motor on port 3 with blue gear set Motor rotations_motor(4, pros::v5::MotorGears::green, pros::v5::MotorUnits::rotations); //port 4 w/ rotations }
Motor(const Device& device)
#include <pros/motors.hpp>
const pros:: Motor operator""_mtr(const unsigned long long int m)
#include <pros/motors.hpp>
Constructs a Motor from a literal ending in _mtr.
Returns | a pros:: |
---|
Example
using namespace pros::literals; void opcontrol() { pros::Motor motor = 2_mtr; //Makes an Motor object on port 2 }
const pros:: Motor operator""_rmtr(const unsigned long long int m)
#include <pros/motors.hpp>
Constructs a reversed Motor from a literal ending in _rmtr.
Returns | a pros:: |
---|
Example
using namespace pros::literals; void opcontrol() { pros::motor motor = 2_rmtr; //Makes an reversed Motor object on port 2 }
std::int32_t move(std::int32_t voltage) const virtual
#include <pros/motors.hpp>
Sets the voltage for the motor from -127 to 127.
Parameters | |
---|---|
voltage | The new motor voltage from -127 to 127 |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
This is designed to map easily to the input from the controller's analog stick for simple opcontrol use. The actual behavior of the motor is analogous to use of motor_
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void opcontrol() { pros::Motor Motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor.move(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); pros::delay(2); } }
std::int32_t move_absolute(const double position,
const std::int32_t velocity) const virtual
#include <pros/motors.hpp>
Sets the target absolute position for the motor to move to.
Parameters | |
---|---|
position | The absolute position to move to in the motor's encoder units |
velocity | The maximum allowable velocity for the movement in RPM |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
This movement is relative to the position of the motor when initialized or the position when it was most recently reset with pros::
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void autonomous() { pros::Motor motor (1); motor.move_absolute(100, 100); // Moves 100 units forward while (!((motor.get_position() < 105) && (motor.get_position() > 95))) { // Continue running this loop as long as the motor is not within +-5 units of its goal pros::delay(2); } motor.move_absolute(100, 100); // This does not cause a movement while (!((motor.get_position() < 105) && (motor.get_position() > 95))) { pros::delay(2); } motor.tare_position(); motor.move_absolute(100, 100); // Moves 100 units forward while (!((motor.get_position() < 105) && (motor.get_position() > 95))) { pros::delay(2); } }
std::int32_t move_relative(const double position,
const std::int32_t velocity) const virtual
#include <pros/motors.hpp>
Sets the relative target position for the motor to move to.
Parameters | |
---|---|
position | The relative position to move to in the motor's encoder units |
velocity | The maximum allowable velocity for the movement in RPM |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
This movement is relative to the current position of the motor as given in pros::
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void autonomous() { pros::Motor motor (1); motor.move_relative(100, 100); // Moves 100 units forward while (!((motor.get_position() < 105) && (motor.get_position() > 95))) { // Continue running this loop as long as the motor is not within +-5 units of its goal pros::delay(2); } motor.move_relative(100, 100); // Also moves 100 units forward while (!((motor.get_position() < 205) && (motor.get_position() > 195))) { pros::delay(2); } }
std::int32_t move_velocity(const std::int32_t velocity) const virtual
#include <pros/motors.hpp>
Sets the velocity for the motor.
Parameters | |
---|---|
velocity | The new motor velocity from -+-100, +-200, or +-600 depending on the motor's gearset |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
This velocity corresponds to different actual speeds depending on the gearset used for the motor. This results in a range of +-100 for E_MOTOR_GEARSET_36, +-200 for E_MOTOR_GEARSET_18, and +-600 for E_MOTOR_GEARSET_6. The velocity is held with PID to ensure consistent speed, as opposed to setting the motor's voltage.
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void autonomous() { pros::Motor motor (1); motor.move_velocity(100); pros::delay(1000); // Move at 100 RPM for 1 second motor.move_velocity(0); }
std::int32_t move_voltage(const std::int32_t voltage) const virtual
#include <pros/motors.hpp>
Sets the output voltage for the motor from -12000 to 12000 in millivolts.
Parameters | |
---|---|
voltage | The new voltage value from -12000 to 12000 |
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 cannot be configured as a motor
Example
void autonomous() { motor.move_voltage(12000); pros::delay(1000); // Move at max voltage for 1 second motor.move_voltage(0); }
std::int32_t brake(void) const virtual
#include <pros/motors.hpp>
Stops the motor using the currently configured brake mode.
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
---|
This function sets motor velocity to zero, which will cause it to act according to the set brake mode. If brake mode is set to MOTOR_BRAKE_HOLD, this function may behave differently than calling move_absolute(0) or motor_move_relative(0).
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void autonomous() { Motor motor(1); motor.move_voltage(12000); pros::delay(1000); // Move at max voltage for 1 second motor.brake(); }
std::int32_t modify_profiled_velocity(const std::int32_t velocity) const virtual
#include <pros/motors.hpp>
Changes the output velocity for a profiled movement (motor_move_absolute or motor_move_relative).
Parameters | |
---|---|
velocity | The new motor velocity from +-100, +-200, or +-600 depending on the motor's gearset |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
This will have no effect if the motor is not following a profiled movement.
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void autonomous() { pros::Motor motor (1); motor.move_absolute(100, 100); pros::delay(100); motor.modify_profiled_velocity(0); // Stop the motor early }
double get_target_position(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the target position set for the motor by the user.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | The target position in its encoder units or PROS_ERR_F if the operation failed, setting errno. |
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor EOVERFLOW - The index is non 0
Example
void autonomous() { pros::Motor motor (1); motor.move_absolute(100, 100); std::cout << "Motor Target: " << motor.get_target_position(); // Prints 100 }
std::int32_t get_target_velocity(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the velocity commanded to the motor by the user at the index specified.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | The commanded motor velocity from +-100, +-200, or +-600, 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 cannot be configured as a motor EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); std::cout << "Motor Velocity: " << motor.get_target_velocity(); // Prints the value of E_CONTROLLER_ANALOG_LEFT_Y pros::delay(2); } }
double get_actual_velocity(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the actual velocity of the motor.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | The motor's actual velocity in RPM or PROS_ERR_F if the operation failed, setting errno. |
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); while (true) { motor = controller_get_analog(E_CONTROLLER_MASTER, E_CONTROLLER_ANALOG_LEFT_Y); printf("Actual velocity: %lf\n", motor.get_actual_velocity()); pros::delay(2); } }
std::int32_t get_current_draw(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the current drawn by the motor in mA.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | The motor's current in mA 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 cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Current Draw: " << motor.get_current_draw(); pros::delay(2); } }
std::int32_t get_direction(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the direction of movement for the motor.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | 1 for moving in the positive direction, -1 for moving in the negative direction, and 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 cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Direction: " << motor.get_direction(); pros::delay(2); } }
double get_efficiency(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the efficiency of the motor in percent.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | The motor's efficiency in percent or PROS_ERR_F if the operation failed, setting errno. |
An efficiency of 100% means that the motor is moving electrically while drawing no electrical power, and an efficiency of 0% means that the motor is drawing power but not moving.
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Efficiency: " << motor.get_efficiency(); pros::delay(2); } }
std::uint32_t get_faults(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the faults experienced by the motor.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | A bitfield containing the motor's faults. |
Compare this bitfield to the bitmasks in pros::motor_fault_e_t.
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Faults: " << motor.get_faults();pros::delay(2); } }
std::uint32_t get_flags(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the flags set by the motor's operation.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | A bitfield containing the motor's flags. |
Compare this bitfield to the bitmasks in pros::motor_flag_e_t.
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Faults: " << motor.get_faults(); pros::delay(2); } }
double get_position(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the absolute position of the motor in its encoder units.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | The motor's absolute position in its encoder units or PROS_ERR_F if the operation failed, setting errno. |
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Position: " << motor.get_position(); pros::delay(2); } }
double get_power(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the power drawn by the motor in Watts.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | The motor's power draw in Watts or PROS_ERR_F if the operation failed, setting errno. |
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Power: " << motor.get_power(); pros::delay(2); } }
std::int32_t get_raw_position(std::uint32_t*const timestamp,
const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the raw encoder count of the motor at a given timestamp.
Parameters | |
---|---|
timestamp | A pointer to a time in milliseconds for which the encoder count will be returned. If NULL, the timestamp at which the encoder count was read will not be supplied |
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | The raw encoder count at the given timestamp or PROS_ERR if the operation failed. |
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void opcontrol() { std::uint32_t now = pros::millis(); pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Position: " << motor.get_raw_position(&now); pros::delay(2); } }
double get_temperature(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the temperature of the motor in degrees Celsius.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | The motor's temperature in degrees Celsius or PROS_ERR_F if the operation failed, setting errno. |
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Temperature: " << motor.get_temperature(); pros::delay(2); } }
double get_torque(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the torque generated by the motor in Newton Meters (Nm).
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | The motor's torque in Nm or PROS_ERR_F if the operation failed, setting errno. |
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Torque: " << motor.get_torque(); pros::delay(2); } }
std::int32_t get_voltage(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the voltage delivered to the motor in millivolts.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | The motor's voltage in mV or PROS_ERR_F if the operation failed, setting errno. |
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Voltage: " << motor.get_voltage(); pros::delay(2); } }
std::int32_t is_over_current(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Checks if the motor is drawing over its current limit.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | 1 if the motor's current limit is being exceeded and 0 if the current limit is not exceeded, 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 cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Is the motor over its current limit?: " << motor.is_over_current(); pros::delay(2); } }
std::int32_t is_over_temp(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the temperature limit flag for the motor.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | 1 if the temperature limit is exceeded and 0 if the temperature is below the limit, 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 cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Is the motor over its temperature limit?: " << motor.is_over_temp(); pros::delay(2); } }
MotorBrake get_brake_mode(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the brake mode that was set for the motor.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | One of MotorBrake, according to what was set for the motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. |
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void initialize() { pros::Motor motor (1); motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); std::cout << "Brake Mode: " << motor.get_brake_mode(); }
std::int32_t get_current_limit(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the current limit for the motor in mA.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | The motor's current limit in mA 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 cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); while (true) { std::cout << "Motor Current Limit: " << motor.get_current_limit(); pros::delay(2); } }
MotorUnits get_encoder_units(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the encoder units that were set for the motor.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | One of MotorUnits according to what is set for the motor or E_MOTOR_ENCODER_INVALID if the operation failed. |
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void initialize() { pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS); std::cout << "Motor Encoder Units: " << motor.get_encoder_units(); }
MotorGears get_gearing(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the gearset that was set for the motor.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | One of MotorGears according to what is set for the motor, or pros::MotorGears::invalid if the operation failed. |
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void initialize() { pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS); std::cout << "Motor Gearing: " << motor.get_gearing(); }
std::int32_t get_voltage_limit(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets the voltage limit set by the user.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Default value is 0V, which means that there is no software limitation imposed on the voltage.
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void initialize() { pros::Motor motor (1); std::cout << "Motor Voltage Limit: " << motor.get_voltage_limit(); }
std::int32_t is_reversed(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Gets whether the motor is reversed or not.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | 1 if the motor has been reversed and 0 if the motor was not reversed, or PROS_ERR if the operation failed, setting errno. |
This function uses the following values of errno when an error state is reached:
EOVERFLOW - The index is non 0
Example
void initialize() { pros::Motor motor (1); std::cout << "Is the motor reversed? " << motor.is_reversed(); // Prints "0" }
std::int32_t set_brake_mode(const MotorBrake mode,
const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Sets one of Motor_Brake to the motor.
Parameters | |
---|---|
mode | The MotorBrake to set for the motor |
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
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 cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void initialize() { pros::Motor motor (1); motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); std::cout << "Brake Mode: " << motor.get_brake_mode(); }
std::int32_t set_brake_mode(const pros::motor_brake_mode_e_t mode,
const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Sets one of MotorBrake to the motor.
Parameters | |
---|---|
mode | The MotorBrake to set for the motor |
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
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 cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void initialize() { pros::Motor motor (1); motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); std::cout << "Brake Mode: " << motor.get_brake_mode(); }
std::int32_t set_current_limit(const std::int32_t limit,
const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Sets the current limit for the motor in mA.
Parameters | |
---|---|
limit | The new current limit in mA |
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
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 cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); motor.set_current_limit(1000); while (true) { motor = controller_get_analog(E_CONTROLLER_ANALOG_LEFT_Y); // The motor will reduce its output at 1000 mA instead of the default 2500 mA pros::delay(2); } }
std::int32_t set_encoder_units(const MotorUnits units,
const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Sets one of MotorUnits for the motor encoder.
Parameters | |
---|---|
units | The new motor encoder units |
index | |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
Works with the C enum and the C++ enum class.
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void initialize() { pros::Motor motor (1); motor.set_encoder_units(E_MOTOR_ENCODER_DEGREES); std::cout << "Encoder Units: " << motor.get_encoder_units(); }
std::int32_t set_encoder_units(const pros::motor_encoder_units_e_t units,
const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Sets one of MotorUnits for the motor encoder.
Parameters | |
---|---|
units | The new motor encoder units |
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
Works with the C enum and the C++ enum class.
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void initialize() { pros::Motor motor (1); motor.set_encoder_units(E_MOTOR_ENCODER_DEGREES); std::cout << "Encoder Units: " << motor.get_encoder_units(); }
std::int32_t set_gearing(const MotorGears gearset,
const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Sets one of the gear cartridge (red, green, blue) for the motor.
Parameters | |
---|---|
gearset | The new motor gearset |
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
Usable with the C++ enum class and the C enum.
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void initialize() { pros::Motor motor (1); motor.set_gearing(E_MOTOR_GEARSET_06); std::cout << "Gearset: " << motor.get_gearing(); }
std::int32_t set_gearing(const pros::motor_gearset_e_t gearset,
const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Sets one of the gear cartridge (red, green, blue) for the motor.
Parameters | |
---|---|
gearset | The new motor gearset |
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
Usable with the C++ enum class and the C enum.
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void initialize() { pros::Motor motor (1); motor.set_gearing(E_MOTOR_GEARSET_06); std::cout << "Gearset: " << motor.get_gearing(); }
std::int32_t set_reversed(const bool reverse,
const std::uint8_t index = 0) virtual
#include <pros/motors.hpp>
Sets the reverse flag for the motor.
Parameters | |
---|---|
reverse | True reverses the motor, false is default direction |
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
This will invert its movements and the values returned for its position.
This function uses the following values of errno when an error state is reached:
EOVERFLOW - The index is non 0
Example
void initialize() { pros::Motor motor (1); motor.set_reversed(true); std::cout << "Is this motor reversed? " << motor.is_reversed(); }
std::int32_t set_voltage_limit(const std::int32_t limit,
const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Sets the voltage limit for the motor in Volts.
Parameters | |
---|---|
limit | The new voltage limit in Volts |
index | |
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 cannot be configured as a motor
Example
void autonomous() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); motor.set_voltage_limit(10000); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); // The motor will not output more than 10 V pros::delay(2); } }
std::int32_t set_zero_position(const double position,
const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Sets the position for the motor in its encoder units.
Parameters | |
---|---|
position | The new reference position in its encoder units |
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
This will be the future reference point for the motor's "absolute" position.
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void autonomous() { pros::Motor motor (1); motor.move_absolute(100, 100); // Moves 100 units forward motor.move_absolute(100, 100); // This does not cause a movement motor.set_zero_position(80); motor.move_absolute(100, 100); // Moves 80 units forward }
std::int32_t tare_position(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
Sets the "absolute" zero position of the motor to its current position.
Parameters | |
---|---|
index | Optional parameter. The zero-indexed index of the motor to get the target position of. By default index is 0, and will return an error for a non-zero index |
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 cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void autonomous() { pros::Motor motor (1); motor.move_absolute(100, 100); // Moves 100 units forward motor.move_absolute(100, 100); // This does not cause a movement motor.tare_position(); motor.move_absolute(100, 100); // Moves 100 units forward }
std::int8_t size(void) const virtual
#include <pros/motors.hpp>
Gets the number of motors.
Returns | Always returns 1 |
---|
static std::vector<Motor> get_all_devices()
#include <pros/motors.hpp>
Gets all motors.
Returns | A vector of Motor objects. |
---|
Example
void opcontrol() { std::vector<Motor> motor_all = pros::Motor::get_all_devices(); // All motors that are connected }
std::int8_t get_port(const std::uint8_t index = 0) const virtual
#include <pros/motors.hpp>
gets the port number of the motor
Returns | The signed port of the motor. (negative if the motor is reversed) |
---|
std::vector<double> get_target_position_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector containing the target position set for the motor by the user.
Returns | A vector containing the target position in its encoder units or PROS_ERR_F if the operation failed, setting errno. |
---|
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void autonomous() { pros::Motor motor (1); motor.move_absolute(100, 100); std::cout << "Motor Target: " << motor.get_target_position_all()[0]; // Prints 100 }
std::vector<std::int32_t> get_target_velocity_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector containing the velocity commanded to the motor by the user.
Returns | A vector containing the commanded motor velocity from +-100, +-200, or +-600, 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 cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); std::cout << "Motor Velocity: " << motor.get_target_velocity_all()[0]; // Prints the value of E_CONTROLLER_ANALOG_LEFT_Y pros::delay(2); } }
std::vector<double> get_actual_velocity_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector containing the actual velocity commanded of the motor.
Returns | A vector containing the motor's actual velocity in RPM or PROS_ERR_F if the operation failed, setting errno. |
---|
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor.move_velocity(master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y)); std::cout << "Motor Velocity: " << motor.get_actual_velocity_all()[0]; // Prints the value of E_CONTROLLER_ANALOG_LEFT_Y pros::delay(2); } }
std::vector<std::int32_t> get_current_draw_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector containing the current drawn by the motor in mA.
Returns | A vector containing the motor's current in mA 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 cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Current Draw: " << motor.get_current_draw_all()[0]; pros::delay(2); } }
std::vector<std::int32_t> get_direction_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector containing the direction of movement for the motor.
Returns | A vector containing 1 for moving in the positive direction, -1 for moving in the negative direction, and 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 cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Direction: " << motor.get_direction_all()[0]; pros::delay(2); } }
std::vector<double> get_efficiency_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector containing the efficiency of the motor in percent.
Returns | A vector containing The motor's efficiency in percent or PROS_ERR_F if the operation failed, setting errno. |
---|
An efficiency of 100% means that the motor is moving electrically while drawing no electrical power, and an efficiency of 0% means that the motor is drawing power but not moving.
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Efficiency: " << motor.get_efficiency(); pros::delay(2); } }
std::vector<std::uint32_t> get_faults_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector of the faults experienced by the motor.
Returns | A bitfield containing the motor's faults. |
---|
Compare this bitfield to the bitmasks in pros::motor_fault_e_t.
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Faults: " << motor.get_faults_all()[0]; pros::delay(2); } }
std::vector<std::uint32_t> get_flags_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector of the flags set by the motor's operation.
Returns | A bitfield containing the motor's flags. |
---|
Compare this bitfield to the bitmasks in pros::motor_flag_e_t.
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Faults: " << motor.get_faults_all()[0]; pros::delay(2); } }
std::vector<double> get_position_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector containing the absolute position of the motor in its encoder units.
Returns | A vector containing the motor's absolute position in its encoder units or PROS_ERR_F if the operation failed, setting errno. |
---|
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Position: " << motor.get_position_all()[0]; pros::delay(2); } }
std::vector<double> get_power_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector containing the power drawn by the motor in Watts.
Returns | A vector containing the motor's power draw in Watts or PROS_ERR_F if the operation failed, setting errno. |
---|
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Power: " << motor.get_power_all()[0]; pros::delay(2); } }
std::vector<std::int32_t> get_raw_position_all(std::uint32_t*const timestamp) const virtual
#include <pros/motors.hpp>
Gets a vector of the raw encoder count of the motor at a given timestamp.
Parameters | |
---|---|
timestamp | A pointer to a time in milliseconds for which the encoder count will be returned. If NULL, the timestamp at which the encoder count was read will not be supplied |
Returns | A vector containing the raw encoder count at the given timestamp or PROS_ERR if the operation failed. |
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
Example
void opcontrol() { std::uint32_t now = pros::millis(); pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Position: " << motor.get_raw_position(&now); pros::delay(2); } }
std::vector<double> get_temperature_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector of the temperature of the motor in degrees Celsius.
Returns | A vector contaioning the motor's temperature in degrees Celsius or PROS_ERR_F if the operation failed, setting errno. |
---|
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Temperature: " << motor.get_temperature_all()[0]; pros::delay(2); } }
std::vector<double> get_torque_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector of the torque generated by the motor in Newton Meters (Nm).
Returns | A vector containing the motor's torque in Nm or PROS_ERR_F if the operation failed, setting errno. |
---|
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Torque: " << motor.get_torque(); pros::delay(2); } }
std::vector<std::int32_t> get_voltage_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector of the voltage delivered to the motor in millivolts.
Returns | A vector of the motor's voltage in mV or PROS_ERR_F if the operation failed, setting errno. |
---|
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Motor Voltage: " << motor.get_voltage_all()[0]; pros::delay(2); } }
std::vector<std::int32_t> is_over_current_all(void) const virtual
#include <pros/motors.hpp>
Checks if the motor is drawing over its current limit.
Returns | A vector containing 1 if the motor's current limit is being exceeded and 0 if the current limit is not exceeded, 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 cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Is the motor over its current limit?: " << motor.is_over_current_all()[0]; pros::delay(2); } }
std::vector<std::int32_t> is_over_temp_all(void) const virtual
#include <pros/motors.hpp>
Gets the temperature limit flag for the motor.
Returns | A vector containing 1 if the temperature limit is exceeded and 0 if the temperature is below the limit, 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 cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); std::cout << "Is the motor over its temperature limit?: " << motor.is_over_temp_all(); pros::delay(2); } }
std::vector<MotorBrake> get_brake_mode_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector containing the brake mode that was set for the motor.
Returns | One of Motor_Brake, according to what was set for the motor, or E_MOTOR_BRAKE_INVALID if the operation failed, setting errno. |
---|
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void initialize() { pros::Motor motor (1); motor.set_brake_mode(pros::E_MOTOR_BRAKE_HOLD); std::cout << "Brake Mode: " << motor.get_brake_mode(); }
std::vector<std::int32_t> get_current_limit_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector containing the current limit for the motor in mA.
Returns | A vector containing the motor's current limit in mA or PROS_ERR if the operation failed, setting errno. |
---|
The default value is 2500 mA.
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); while (true) { std::cout << "Motor Current Limit: " << motor.get_current_limit_all()[0]; pros::delay(2); } }
std::vector<MotorUnits> get_encoder_units_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector containing the encoder units that were set for the motor.
Returns | A vector containing One of Motor_Units according to what is set for the motor or E_MOTOR_ENCODER_INVALID if the operation failed. |
---|
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void initialize() { pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS); std::cout << "Motor Encoder Units: " << motor.get_encoder_units_all()[0]; }
std::vector<MotorGears> get_gearing_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector containing the gearset that was set for the motor.
Returns | A vector containing one of Motor_Gears according to what is set for the motor, or pros::Motor_Gears::invalid if the operation failed. |
---|
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void initialize() { pros::Motor motor (1, E_MOTOR_GEARSET_06, E_MOTOR_ENCODER_COUNTS); std::cout << "Motor Gearing: " << motor.get_gearing_all()[0]; }
std::vector<std::int8_t> get_port_all(void) const virtual
#include <pros/motors.hpp>
Gets returns a vector with all the port numbers in the motor group.
Returns | A vector containing the signed port of the motor. (negative if the motor is reversed) |
---|
std::vector<std::int32_t> get_voltage_limit_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector of the voltage limit set by the user.
Returns | A vector containing the motor's voltage limit in V or PROS_ERR if the operation failed, setting errno. |
---|
Default value is 0V, which means that there is no software limitation imposed on the voltage.
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void initialize() { pros::Motor motor (1); std::cout << "Motor Voltage Limit: " << motor.get_voltage_limit_all()[0]; }
std::vector<std::int32_t> is_reversed_all(void) const virtual
#include <pros/motors.hpp>
Gets a vector containg whether the motor is reversed or not.
Returns | A vector containing 1 if the motor has been reversed and 0 if the motor was not reversed, or PROS_ERR if the operation failed, setting errno. |
---|
Example
void initialize() { pros::Motor motor (1); std::cout << "Is the motor reversed? " << motor.is_reversed_all()[0]; // Prints "0" }
std::int32_t set_brake_mode_all(const MotorBrake mode) const virtual
#include <pros/motors.hpp>
Sets one of Motor_Brake to the motor.
Parameters | |
---|---|
mode | The Motor_Brake to set for the motor |
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 cannot be configured as a motor
Example
void initialize() { pros::Motor motor (1); motor.set_brake_mode_all(pros::E_MOTOR_BRAKE_HOLD); std::cout << "Brake Mode: " << motor.get_brake_mode(); }
std::int32_t set_brake_mode_all(const pros::motor_brake_mode_e_t mode) const virtual
#include <pros/motors.hpp>
Sets one of Motor_Brake to the motor.
Parameters | |
---|---|
mode | The Motor_Brake to set for the motor |
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 cannot be configured as a motor
Example
void initialize() { pros::Motor motor (1); motor.set_brake_mode_all(pros::E_MOTOR_BRAKE_HOLD); std::cout << "Brake Mode: " << motor.get_brake_mode(); }
std::int32_t set_current_limit_all(const std::int32_t limit) const virtual
#include <pros/motors.hpp>
Sets the current limit for the motor in mA.
Parameters | |
---|---|
limit | The new current limit in mA |
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 cannot be configured as a motor
Example
void opcontrol() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); motor.set_current_limit_all(1000); while (true) { motor = controller_get_analog(E_CONTROLLER_ANALOG_LEFT_Y); // The motor will reduce its output at 1000 mA instead of the default 2500 mA pros::delay(2); } }
std::int32_t set_encoder_units_all(const MotorUnits units) const virtual
#include <pros/motors.hpp>
Sets one of Motor_Units for the motor encoder.
Parameters | |
---|---|
units | The new motor encoder units |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
Works with the C enum and the C++ enum class.
This function uses the following values of errno when an error state is reached:
ENODEV - The port cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void initialize() { pros::Motor motor (1); motor.set_encoder_units_all(E_MOTOR_ENCODER_DEGREES); std::cout << "Encoder Units: " << motor.get_encoder_units(); }
std::int32_t set_encoder_units_all(const pros::motor_encoder_units_e_t units) const virtual
#include <pros/motors.hpp>
Sets one of Motor_Units for the motor encoder.
Parameters | |
---|---|
units | The new motor encoder units |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
Works with the C enum and the C++ enum class.
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void initialize() { pros::Motor motor (1); motor.set_encoder_units_all(E_MOTOR_ENCODER_DEGREES); std::cout << "Encoder Units: " << motor.get_encoder_units(); }
std::int32_t set_gearing_all(const MotorGears gearset) const virtual
#include <pros/motors.hpp>
Sets one of the gear cartridge (red, green, blue) for the motor.
Parameters | |
---|---|
gearset | The new motor gearset |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
Usable with the C++ enum class and the C enum.
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void initialize() { pros::Motor motor (1); motor.set_gearing_all(E_MOTOR_GEARSET_06); std::cout << "Gearset: " << motor.get_gearing(); }
std::int32_t set_gearing_all(const pros::motor_gearset_e_t gearset) const virtual
#include <pros/motors.hpp>
Sets one of the gear cartridge (red, green, blue) for the motor.
Parameters | |
---|---|
gearset | The new motor gearset |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
Usable with the C++ enum class and the C enum.
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void initialize() { pros::Motor motor (1); motor.set_gearing_all(E_MOTOR_GEARSET_06); std::cout << "Gearset: " << motor.get_gearing(); }
std::int32_t set_reversed_all(const bool reverse) virtual
#include <pros/motors.hpp>
Sets the reverse flag for the motor.
Parameters | |
---|---|
reverse | True reverses the motor, false is default direction |
Returns | 1 |
This will invert its movements and the values returned for its position.
Example
void initialize() { pros::Motor motor (1); motor.set_reversed_all(true); std::cout << "Is this motor reversed? " << motor.is_reversed(); }
std::int32_t set_voltage_limit_all(const std::int32_t limit) const virtual
#include <pros/motors.hpp>
Sets the voltage limit for the motor in Volts.
Parameters | |
---|---|
limit | The new voltage limit in Volts |
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 cannot be configured as a motor
EOVERFLOW - The index is non 0
Example
void autonomous() { pros::Motor motor (1); pros::Controller master (E_CONTROLLER_MASTER); motor.set_voltage_limit_all(10000); while (true) { motor = master.get_analog(E_CONTROLLER_ANALOG_LEFT_Y); // The motor will not output more than 10 V pros::delay(2); } }
std::int32_t set_zero_position_all(const double position) const virtual
#include <pros/motors.hpp>
Sets the position for the motor in its encoder units.
Parameters | |
---|---|
position | The new reference position in its encoder units |
Returns | 1 if the operation was successful or PROS_ERR if the operation failed, setting errno. |
This will be the future reference point for the motor's "absolute" position.
This function uses the following values of errno when an error state is reached: ENODEV - The port cannot be configured as a motor
Example
void autonomous() { pros::Motor motor (1); motor.move_absolute(100, 100); // Moves 100 units forward motor.move_absolute(100, 100); // This does not cause a movement motor.set_zero_position_all(80); motor.move_absolute(100, 100); // Moves 80 units forward }
std::int32_t tare_position_all(void) const virtual
#include <pros/motors.hpp>
Sets the "absolute" zero position of the motor to its current position.
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 cannot be configured as a motor
Example
void autonomous() { pros::Motor motor (1); motor.move_absolute(100, 100); // Moves 100 units forward motor.move_absolute(100, 100); // This does not cause a movement motor.tare_position_all(); motor.move_absolute(100, 100); // Moves 100 units forward }
Variable documentation
std::int8_t _port
#include <pros/motors.hpp>
The port of the motor.
Negative ports indicate that the motor is reversed