ai_car1
Dependencies: mbed ai_car ros_lib_melodic
Diff: Actuator/Motor.cpp
- Revision:
- 0:a35213e1e14e
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Actuator/Motor.cpp Mon May 03 07:22:52 2021 +0000 @@ -0,0 +1,41 @@ +#include "Motor.h" + + +Motor::Motor(PinName IN1, PinName IN2, PinName INH1, PinName INH2) + : IN1_(IN1), IN2_(IN2), INH1_(INH1), INH2_(INH2) +{ + INH1_=1; + INH2_=1; + IN1_.period_us(50); + IN2_.period_us(50); +} + +void Motor::setSpeed_percent(float percent, char direction) +{ + float duty = percent/100.0; + if(duty>1.0) { + duty=1.0; + } else if(duty<0.0) { + duty=0.0; + } + + if(direction==FORWARD) + { + IN1_=duty; + IN2_=0; + } + else if (direction == BACKWARD){ + IN1_=0; + IN2_=duty; + } + else if (direction == BREAK) + { + IN1_=1; + IN2_=1; + } + else + { + IN1_=0; + IN2_=0; + } +} \ No newline at end of file