libhal-google / libhal-soft

Library for generic soft drivers officially supported by libhal
Apache License 2.0
1 stars 6 forks source link

Add `hal::soft::dual_pwm_motor` implementation #22

Open kammce opened 1 year ago

kammce commented 1 year ago
#include <libhal/motor.hpp>
#include <libhal/pwm.hpp>

class dual_pwm_motor : public hal::motor
{
  dual_pwm_motor(hal::pwm& p_forward, hal::pwm& p_reverse);
  hal::status slow_decay(bool p_enable = true);
};

Some motor controllers require two pwm signals to operate with speed control for both forward and reverse operations. A list of such drivers can be found below:

This slow_decay() function allows the user to control whether the motor is in slow decay or fast decay mode. The driver should default to slow decay. Fast decay allows the motor to coast when not driven by the driver or when reducing speed. Slow decay means braking when speed is reduced which tends to give a better and more linear drive response for control.

kammce commented 1 year ago

Also! The constructor should also take in a struct that identifies what voltage level represents slow decay and fast decay. Usually slow decay would mean setting both pins to HIGH and fast decay is setting both pins LOW, or vise versa.