Cpp-abstract-motor module

Modules

module Cpp-motor-telemetry

Files

file abstract_motor.hpp

Classes

class pros::v5::AbstractMotor

Motor movement functions

These functions allow programmers to make motors move

std::int32_t move(std::int32_t voltage) const pure 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 pure 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 pure virtual
Sets the relative target position for the motor to move to.
std::int32_t move_velocity(const std::int32_t velocity) const pure virtual
Sets the velocity for the motor.
std::int32_t move_voltage(const std::int32_t voltage) const pure virtual
Sets the output voltage for the motor from -12000 to 12000 in millivolts.
std::int32_t brake(void) const pure virtual
Stops the motor using the currently configured brake mode.
std::int32_t modify_profiled_velocity(const std::int32_t velocity) const pure virtual
Changes the output velocity for a profiled movement (motor_move_absolute or motor_move_relative).
double get_target_position(const std::uint8_t index = 0) const pure virtual
Gets the target position set for the motor by the user, with a parameter for the motor index.
std::vector<double> get_target_position_all(void) const pure virtual
Gets a vector containing the target position(s) set for the motor(s) by the user.
std::int32_t get_target_velocity(const std::uint8_t index = 0) const pure virtual
Gets the velocity commanded to the motor by the user.
std::vector<std::int32_t> get_target_velocity_all(void) const pure virtual
Gets a vector containing the velocity/velocities commanded to the motor(s) by the user.

Function documentation

std::int32_t move(std::int32_t voltage) const pure virtual

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_move(), or motorSet() from the PROS 2 API.

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

std::int32_t move_absolute(const double position, const std::int32_t velocity) const pure virtual

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::Motor::set_zero_position().

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

std::int32_t move_relative(const double position, const std::int32_t velocity) const pure virtual

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::Motor::motor_get_position(). Providing 10.0 as the position parameter would result in the motor moving clockwise 10 units, no matter what the current position is.

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

std::int32_t move_velocity(const std::int32_t velocity) const pure virtual

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

std::int32_t move_voltage(const std::int32_t voltage) const pure virtual

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

std::int32_t brake(void) const pure virtual

Stops the motor using the currently configured brake mode.

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

std::int32_t modify_profiled_velocity(const std::int32_t velocity) const pure virtual

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

double get_target_position(const std::uint8_t index = 0) const pure virtual

Gets the target position set for the motor by the user, with a parameter for the motor index.

Parameters
index Optional parameter. The index of the motor to get the target position of. By default index is 0, and will return an error for an out of bounds 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

std::vector<double> get_target_position_all(void) const pure virtual

Gets a vector containing the target position(s) set for the motor(s) by the user.

Returns A vector containing the target position(s) 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

std::int32_t get_target_velocity(const std::uint8_t index = 0) const pure virtual

Gets the velocity commanded to the motor by the user.

Parameters
index Optional parameter. The index of the motor to get the target position of. By default index is 0, and will return an error for an out of bounds 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

std::vector<std::int32_t> get_target_velocity_all(void) const pure virtual

Gets a vector containing the velocity/velocities commanded to the motor(s) by the user.

Returns A vector containing the commanded motor velocity/velocities 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