37 static const int POWER_MAX = 100;
38 static const int POWER_MIN = -100;
39 static constexpr
float NUMBER_OF_DEGREES_PER_ROTATION = 360.0;
59 : m_port(static_cast<motor_port_t>(port)),
60 m_type(static_cast<motor_type_t>(type))
62 ev3_motor_config(m_port, m_type);
80 void off(
bool brake =
true) {
81 ev3_motor_stop(m_port, brake);
91 void on(
int power = 50) {
93 if(m_type != getType()) {
94 ev3_motor_config(m_port, m_type);
96 ev3_motor_set_power(m_port, power);
108 if(UNREGULATED_MOTOR != getType()) {
109 ev3_motor_config(m_port, UNREGULATED_MOTOR);
111 ev3_motor_set_power(m_port, power);
125 void onForDegrees(
int speed = 50,
int degrees = 360, bool_t brake =
true, bool_t blocking =
true,
unsigned int wait_after_ms = 60) {
132 ev3_motor_rotate_brake(m_port, degrees, speed, blocking, brake);
133 tslp_tsk(wait_after_ms);
147 void onForRotations(
int speed = 50,
float rotations = 1, bool_t brake =
true, bool_t blocking =
true,
unsigned int wait_after_ms = 60) {
152 rotations = -rotations;
154 ev3_motor_rotate_brake(m_port, NUMBER_OF_DEGREES_PER_ROTATION * rotations, speed, blocking, brake);
155 tslp_tsk(wait_after_ms);
165 void onForSeconds(
int speed = 50,
unsigned int time_ms = 1000, bool_t brake =
true) {
177 int degrees()
const {
return ev3_motor_get_counts(m_port); }
186 return ev3_motor_get_counts(m_port) / NUMBER_OF_DEGREES_PER_ROTATION;
209 motor_port_t
getPort()
const {
return m_port; }
219 ER_UINT motor_type = ev3_motor_get_type(m_port);
221 if(motor_type < 0 || motor_type >= TNUM_MOTOR_PORT)
void unregulated(int power=50)
Set power on unregulated motor. [TODO: fix - same behavior as on() -> problem in EV3RT].
Class Motor. API for working with motor.
MotorType
Enum with index of motor type.
float rotations() const
Get the actual position of a motor in rotations.
void on(int power=50)
Set speed on regulated motor.
motor_port_t getPort() const
Get motor port.
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.
void onForSeconds(int speed=50, unsigned int time_ms=1000, bool_t brake=true)
Rotates the motor for a given time.
int degrees() const
Get the actual position of a motor in degrees.
MotorPort
Enum with index of motor port (A - D)
void resetPosition()
Reset the angular position of the motor to zero.
int currentPower() const
Get the actual power (equivalent with speed) of a motor. [TODO: power/speed].
ER_UINT getType() const
Get curent type of motor which is set in EV3RT (not set by constructor).
Motor(MotorPort port, MotorType type=MotorType::LARGE)
Constructor of class motor.
void off(bool brake=true)
Stop motor.
~Motor()
Destructor of class motor.
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.