EV3RT CXX API Reference [English]
An RTOS-based development platform for LEGO Mindstorms EV3.
ev3cxx_motor_tank.h
1 
7 #pragma once
8 
9 #include "ev3cxx_motor.h"
10 
11 namespace ev3cxx {
12 
17 class MotorTank
18  : public detail::MotorConstants
19 {
20 public:
21 
22  MotorTank() = delete;
23 
31  MotorTank(MotorPort left_motor_port, MotorPort right_motor_port, MotorType type = MotorType::LARGE)
32  : m_left_motor(left_motor_port, type),
33  m_right_motor(right_motor_port, type)
34  {}
35 
42  void off(bool brake = true) {
43  m_left_motor.off(brake);
44  m_right_motor.off(brake);
45  }
46 
57  void on(int left_speed = 50, int right_speed = 50) {
58  m_left_motor.on(left_speed);
59  m_right_motor.on(right_speed);
60  }
61 
71  void unregulated(int left_power = 50, int right_power = 50) {
72  m_left_motor.unregulated(left_power);
73  m_right_motor.unregulated(right_power);
74  }
75 
88  void onForDegrees(int left_speed = 50, int right_speed = 50, int degrees = 360, bool_t brake = true, bool_t blocking = true, unsigned int wait_after_ms = 60) {
89  int labs = abs(left_speed);
90  int rabs = abs(right_speed);
91  if (labs > rabs) {
92  const float sr = float(rabs) / float(labs);
93  m_right_motor.onForDegrees(right_speed, degrees * sr, brake, false, 0);
94  m_left_motor.onForDegrees (left_speed, degrees, brake, blocking, wait_after_ms);
95  } else {
96  const float sr = rabs != 0 ? float(labs) / float(rabs) : 0;
97  m_left_motor.onForDegrees (left_speed, degrees * sr, brake, false, 0);
98  m_right_motor.onForDegrees(right_speed, degrees, brake, blocking, wait_after_ms);
99  }
100  }
101 
114  void onForRotations(int left_speed = 50, int right_speed = 50, float rotations = 1, bool_t brake = true, bool_t blocking = true, unsigned int wait_after_ms = 60) {
115  onForDegrees(left_speed, right_speed, rotations * NUMBER_OF_DEGREES_PER_ROTATION, brake, blocking, wait_after_ms);
116  }
117 
126  void onForSeconds(int left_speed = 50, int right_speed = 50, unsigned int time_ms = 1000, bool_t brake = true) {
127  on(left_speed, right_speed);
128  tslp_tsk(time_ms);
129  off(brake);
130  }
131 
138  {
139  m_left_motor.resetPosition();
140  m_right_motor.resetPosition();
141  }
142 
148  Motor& leftMotor() { return m_left_motor; }
149 
155  const Motor& leftMotor() const { return m_left_motor; }
156 
162  Motor& rightMotor() { return m_right_motor; }
163 
169  const Motor& rightMotor() const { return m_right_motor; }
170 
171 private:
172  Motor m_left_motor;
173  Motor m_right_motor;
174 }; // class MotorTank
175 } // namespace ev3cxx
Motor & leftMotor()
Return reference to the left motor.
void unregulated(int power=50)
Set power on unregulated motor. [TODO: fix - same behavior as on() -> problem in EV3RT].
Definition: ev3cxx_motor.h:106
Definition: ev3cxx.h:35
MotorTank(MotorPort left_motor_port, MotorPort right_motor_port, MotorType type=MotorType::LARGE)
Constructor of class MotorTank.
Large servo motor.
EV3RT CPP API for motors.
const Motor & rightMotor() const
Return const reference to the right motor.
Class Motor. API for working with motor.
Definition: ev3cxx_motor.h:47
void resetPosition()
Reset the angular position of the motors to zero.
MotorType
Enum with index of motor type.
Definition: ev3cxx_motor.h:28
void on(int power=50)
Set speed on regulated motor.
Definition: ev3cxx_motor.h:91
void on(int left_speed=50, int right_speed=50)
Set speed on regulated motors.
void unregulated(int left_power=50, int right_power=50)
Set power on unregulated motors.
MotorPort
Enum with index of motor port (A - D)
Definition: ev3cxx_motor.h:17
const Motor & leftMotor() const
Return const reference to the left motor.
Motor & rightMotor()
Return reference to the right motor.
void resetPosition()
Reset the angular position of the motor to zero.
Definition: ev3cxx_motor.h:202
Class MotorTank. API for working with two motors together.
void onForSeconds(int left_speed=50, int right_speed=50, unsigned int time_ms=1000, bool_t brake=true)
Rotates the motor for a given time.
void off(bool brake=true)
Stop motors.
void off(bool brake=true)
Stop motor.
Definition: ev3cxx_motor.h:80
void onForDegrees(int left_speed=50, int right_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 motors.
void onForRotations(int left_speed=50, int right_speed=50, float rotations=1, bool_t brake=true, bool_t blocking=true, unsigned int wait_after_ms=60)
Set number of rotations to rotate with regulated motors.
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.
Definition: ev3cxx_motor.h:125