Class Motor. API for working with motor. More...
#include <ev3cxx_motor.h>
Public Member Functions | |
Motor (MotorPort port, MotorType type=MotorType::LARGE) | |
Constructor of class motor. More... | |
~Motor () | |
Destructor of class motor. More... | |
void | off (bool brake=true) |
Stop motor. More... | |
void | on (int power=50) |
Set speed on regulated motor. More... | |
void | unregulated (int power=50) |
Set power on unregulated motor. [TODO: fix - same behavior as on() -> problem in EV3RT]. More... | |
void | onForDegrees (int speed=50, int degrees=360, bool_t brake=true, bool_t blocking=true, unsigned int wait_after_ms=60) |
Set number of degrees to rotate with regulated motor. More... | |
void | onForRotations (int speed=50, float rotations=1, bool_t brake=true, bool_t blocking=true, unsigned int wait_after_ms=60) |
Set number of rotation to rotate with regulated motor. More... | |
void | onForSeconds (int speed=50, unsigned int time_ms=1000, bool_t brake=true) |
Rotates the motor for a given time. More... | |
int | degrees () const |
Get the actual position of a motor in degrees. More... | |
float | rotations () const |
Get the actual position of a motor in rotations. More... | |
int | currentPower () const |
Get the actual power (equivalent with speed) of a motor. [TODO: power/speed]. More... | |
void | resetPosition () |
Reset the angular position of the motor to zero. More... | |
motor_port_t | getPort () const |
Get motor port. More... | |
ER_UINT | getType () const |
Get curent type of motor which is set in EV3RT (not set by constructor). More... | |
Private Attributes | |
motor_port_t | m_port |
motor_type_t | m_type |
Additional Inherited Members | |
Static Public Attributes inherited from MotorConstants | |
static const int | POWER_MAX = 100 |
Max power on motor. | |
static const int | POWER_MIN = -100 |
Min power on motor. | |
static constexpr float | NUMBER_OF_DEGREES_PER_ROTATION = 360.0 |
Class Motor. API for working with motor.
Definition at line 47 of file ev3cxx_motor.h.
|
inline |
Constructor of class motor.
port | Port number |
type | Type of port: motor_type_t |
Definition at line 58 of file ev3cxx_motor.h.
|
inline |
Destructor of class motor.
Turns off the motor and lefts it coasts.
Definition at line 70 of file ev3cxx_motor.h.
References Motor::off().
|
inline |
Get the actual power (equivalent with speed) of a motor. [TODO: power/speed].
When an incorrect motor port number is specified, it always returns 0.
Definition at line 195 of file ev3cxx_motor.h.
|
inline |
Get the actual position of a motor in degrees.
When an incorrect motor port number is specified, it always returns 0.
Definition at line 177 of file ev3cxx_motor.h.
|
inline |
|
inline |
Get curent type of motor which is set in EV3RT (not set by constructor).
>=0 | Motor type of specified motor port |
E_ID | Illegal motor port number |
Definition at line 218 of file ev3cxx_motor.h.
|
inline |
Stop motor.
Set the motor power or speed to 0 and depending on param brake will brake the motor.
brake | Start braking the motor (true = braking, false = not braking). Default value is true. |
Definition at line 80 of file ev3cxx_motor.h.
Referenced by MotorTank::off(), and Motor::~Motor().
|
inline |
Set speed on regulated motor.
Using regulated motor driver (motor should has constant speed) and param power is equivalent to speed. Motor control real power to keep constant speed.
power | Motor speed. Range: -100 to +100. A negative value moves the robot backwards. Default value is 50. If a out-of-range value is given, it will be clipped to the minimum (-100) or maximum (100) value. |
Definition at line 91 of file ev3cxx_motor.h.
Referenced by MotorTank::on().
|
inline |
Set number of degrees to rotate with regulated motor.
speed | Speed of motor. Range: -100 to +100. Default value is 50. |
degrees | Number of degrees for rotation of motor. A negative value moves the robot backwards. Default value is 360. |
brake | If true, then motor start braking after reach the position (= degrees). |
blocking | true (The function will be blocked until the move is finished), or false (The function will not be blocked). Default value is false. |
wait_after_ms | Adds wait after the functuion executes. Default wait is 60 ms. It is important because of some race condition when another motor rotation follows immediately |
Definition at line 125 of file ev3cxx_motor.h.
Referenced by MotorTank::onForDegrees().
|
inline |
Set number of rotation to rotate with regulated motor.
speed | Speed of motor. Range: -100 to +100. Default value is 50. |
rotations | Number of rotation for rotate with motor. A negative value moves the robot backwards. Default value is 1. |
brake | If true, then motor start braking after reach the position (= degrees). |
blocking | true (The function will be blocked until the move is finished), or false (The function will not be blocked). Default value is false. |
wait_after_ms | Adds wait after the functuion executes. Default wait is 60 ms. It is important because of some race condition when another motor rotation follows immediately |
Definition at line 147 of file ev3cxx_motor.h.
|
inline |
Rotates the motor for a given time.
speed | Speed of motor. Range: -100 to +100. Default value is 50. |
time | Number of miliseconds for rotate with motor. Default value is 1000. |
brake | If true, then motor start braking after reach the position (= degrees). |
Definition at line 165 of file ev3cxx_motor.h.
|
inline |
Reset the angular position of the motor to zero.
Setting the value of the angular position sensor of the motor does not affect the actual power and position of the motor.
Definition at line 202 of file ev3cxx_motor.h.
Referenced by MotorTank::resetPosition().
|
inline |
Get the actual position of a motor in rotations.
When an incorrect motor port number is specified, it always returns 0.
Definition at line 185 of file ev3cxx_motor.h.
|
inline |
Set power on unregulated motor. [TODO: fix - same behavior as on() -> problem in EV3RT].
Motor works with constant power, NOT speed. Speed changes depend on load.
power | Motor power. Range: -100 to +100. A negative value moves the robot backwards. Default value is 50. If a out-of-range value is given, it will be clipped to the minimum (-100) or maximum (100) value. |
Definition at line 106 of file ev3cxx_motor.h.
Referenced by MotorTank::unregulated().