Nicolae Marton / Mbed 2 deprecated TDP3_OOP

Dependencies:   mbed

Committer:
Nicolaemf
Date:
Sun Feb 03 16:42:44 2019 +0000
Revision:
3:54c41af9e119
Parent:
0:a02a278513d9
Child:
4:645b5d648c64
Wrote PIDweight function, accomodated SetSpeed function, added methods to the header files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nicolaemf 0:a02a278513d9 1 #include "RobotControl_H.h"
Nicolaemf 0:a02a278513d9 2 #include <mbed.h>
Nicolaemf 0:a02a278513d9 3
Nicolaemf 0:a02a278513d9 4
Nicolaemf 0:a02a278513d9 5 RobotControl::RobotControl(PinName pin1, PinName pin2, PinName pin3):m_motorEnable(pin1),m_motorBw(pin2),m_motorFw(pin3){
Nicolaemf 0:a02a278513d9 6 /*class constructor : initializes the motors with
Nicolaemf 0:a02a278513d9 7 forward enable and speed of 0.3 */
Nicolaemf 0:a02a278513d9 8
Nicolaemf 3:54c41af9e119 9 //m_dir = true;
Nicolaemf 3:54c41af9e119 10 //m_speed = 0.2;
Nicolaemf 3:54c41af9e119 11
Nicolaemf 3:54c41af9e119 12 m_motorBw.period_ms(1);
Nicolaemf 3:54c41af9e119 13 m_motorFw.period_ms(1);
Nicolaemf 3:54c41af9e119 14
Nicolaemf 3:54c41af9e119 15 SetDirection(1);
Nicolaemf 3:54c41af9e119 16 SetSpeed(0.2);
Nicolaemf 0:a02a278513d9 17 }
Nicolaemf 0:a02a278513d9 18
Nicolaemf 0:a02a278513d9 19
Nicolaemf 0:a02a278513d9 20 void RobotControl::SetDirection(bool dir){
Nicolaemf 0:a02a278513d9 21 /*set direction of one of the sides depending on pwmSelect
Nicolaemf 0:a02a278513d9 22 direction : 1 go forward ,0 go backwards */
Nicolaemf 0:a02a278513d9 23
Nicolaemf 0:a02a278513d9 24 m_motorBw.write(0);
Nicolaemf 0:a02a278513d9 25 m_motorFw.write(0);
Nicolaemf 0:a02a278513d9 26
Nicolaemf 0:a02a278513d9 27 wait(0.1);
Nicolaemf 0:a02a278513d9 28
Nicolaemf 0:a02a278513d9 29 if(dir){
Nicolaemf 0:a02a278513d9 30 m_motorEnable = true;
Nicolaemf 0:a02a278513d9 31 m_pwmPtr = &m_motorFw;
Nicolaemf 0:a02a278513d9 32 }else{
Nicolaemf 0:a02a278513d9 33 m_motorEnable = false;
Nicolaemf 0:a02a278513d9 34 m_pwmPtr = &m_motorBw;
Nicolaemf 0:a02a278513d9 35 }
Nicolaemf 0:a02a278513d9 36
Nicolaemf 0:a02a278513d9 37 m_prevDir = dir;
Nicolaemf 0:a02a278513d9 38
Nicolaemf 0:a02a278513d9 39 }
Nicolaemf 0:a02a278513d9 40
Nicolaemf 0:a02a278513d9 41
Nicolaemf 0:a02a278513d9 42 void RobotControl::SetSpeed(float speed){
Nicolaemf 0:a02a278513d9 43 /*set speed on the pwm which is point by m_pwmPtr (set by SetDirection)
Nicolaemf 0:a02a278513d9 44 speed : the speed given to the motor, ranges from 0 to 1*/
Nicolaemf 0:a02a278513d9 45
Nicolaemf 3:54c41af9e119 46 if(speed<=0) m_pwmPtr->write(0);
Nicolaemf 3:54c41af9e119 47 else if(speed>=1.0)m_pwmPtr->write(1.0);
Nicolaemf 3:54c41af9e119 48 else m_pwmPtr->write(speed);
Nicolaemf 3:54c41af9e119 49
Nicolaemf 0:a02a278513d9 50 }
Nicolaemf 0:a02a278513d9 51
Nicolaemf 0:a02a278513d9 52