20 static_assert(POWER_DIVIDER * PERIOD_US == MAX_POWER);
29 Motor(
const PinName pin0,
const PinName pin1)
30 : m_maxPowerPercent(100)
32 #if defined MOTOR_HARDWARE_PWM 33 m_in0 =
new PwmOut(pin0);
34 m_in1 =
new PwmOut(pin1);
35 #elif defined MOTOR_SOFTWARE_PWM 43 m_in0->pulsewidth_us(0);
44 m_in1->pulsewidth_us(0);
68 power = (m_inverse ? -1 : 1) * power;
69 if (m_maxPowerPercent != 100) {
70 power = (power * m_maxPowerPercent) / 100;
75 m_in1->pulsewidth_us(0);
77 m_in0->pulsewidth_us(0);
90 m_maxPowerPercent = nxpcup::clamp<int>(percent, 0, 100);
104 #if defined MOTOR_HARDWARE_PWM 107 #elif defined MOTOR_SOFTWARE_PWM 112 bool m_inverse =
false;
113 int m_maxPowerPercent;
static constexpr int POWER_DIVIDER
Definition: Motor.h:19
Motor(const PinName pin0, const PinName pin1)
Definition: Motor.h:29
bool inverse
Definition: Motor.h:15
void power(int power)
Definition: Motor.h:64
static constexpr int PERIOD_US
Definition: Motor.h:17
static constexpr int MAX_POWER
Definition: Motor.h:18
Definition: BorderDetector.h:6
int maxPower() const
Definition: Motor.h:101
void setMaxPowerPercent(int percent)
Definition: Motor.h:88
PinName pwm0
Definition: Motor.h:13
int maxPowerPercent() const
Definition: Motor.h:96
Motor(const Config &config)
Definition: Motor.h:52
PinName pwm1
Definition: Motor.h:14