Old working code

Dependencies:   mbed QEI ros_lib_melodic

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Motor.cpp Source File

Motor.cpp

00001 #include "mbed.h"
00002 #include <string>
00003 
00004 #include "Motor.h"
00005 #include "QEI.h"
00006 
00007 ///////////////////////////////////////////////////////////////////
00008 // Constructor
00009 ///////////////////////////////////////////////////////////////////
00010 Motor::Motor(PinName in1, PinName in2, PinName pwm)
00011 : in1(in1), in2(in2), pwm(pwm)
00012 {
00013     this->pwm.period_ms(10);
00014 }
00015 
00016 ///////////////////////////////////////////////////////////////////
00017 // Public methods
00018 ///////////////////////////////////////////////////////////////////
00019 void Motor::setSpeed(float speed)
00020 {
00021     pwm.write(speed);
00022 }
00023 
00024 void Motor::stop()
00025 {
00026     setSpeed(0);
00027 }
00028 
00029 void Motor::move(int in1, int in2)
00030 {
00031     this->in1 = in1; 
00032     this->in2 = in2;  
00033 }