Nicolae Marton / Mbed 2 deprecated TDP3_OOP

Dependencies:   mbed

Committer:
Nicolaemf
Date:
Sun Feb 03 16:42:44 2019 +0000
Revision:
3:54c41af9e119
Parent:
1:a2ceed49374e
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 1:a2ceed49374e 1 #ifndef IRSensor_H
Nicolaemf 1:a2ceed49374e 2 #define IRSensor_H
Nicolaemf 1:a2ceed49374e 3
Nicolaemf 1:a2ceed49374e 4 #include <mbed.h>
Nicolaemf 1:a2ceed49374e 5 #include "RobotControl_H.h"
Nicolaemf 1:a2ceed49374e 6
Nicolaemf 3:54c41af9e119 7 //IRSensor deals with sampling and processing the data from the IR sensors
Nicolaemf 3:54c41af9e119 8 //the IR sensors are used to determine the position of the robot wrt the black line
Nicolaemf 3:54c41af9e119 9 //A PID controller system is used to stabilize the Robot above the black line
Nicolaemf 3:54c41af9e119 10
Nicolaemf 3:54c41af9e119 11 //Instantiation: the 5 pins for the IRSensor and Kp Ki and Kd for the PID
Nicolaemf 3:54c41af9e119 12
Nicolaemf 1:a2ceed49374e 13 class IRSensor
Nicolaemf 1:a2ceed49374e 14 {
Nicolaemf 1:a2ceed49374e 15 private:
Nicolaemf 1:a2ceed49374e 16
Nicolaemf 1:a2ceed49374e 17 DigitalIn m_leftIR;
Nicolaemf 1:a2ceed49374e 18 DigitalIn m_midLeftIR;
Nicolaemf 1:a2ceed49374e 19 DigitalIn m_midIR;
Nicolaemf 1:a2ceed49374e 20 DigitalIn m_midRightIR;
Nicolaemf 1:a2ceed49374e 21 DigitalIn m_rightIR;
Nicolaemf 1:a2ceed49374e 22
Nicolaemf 1:a2ceed49374e 23 bool m_prevDirL, m_prevDirR;
Nicolaemf 1:a2ceed49374e 24 bool m_lineSensor[5];
Nicolaemf 1:a2ceed49374e 25
Nicolaemf 3:54c41af9e119 26 int m_color;
Nicolaemf 1:a2ceed49374e 27 short int m_error, m_prevError;
Nicolaemf 1:a2ceed49374e 28 const float m_Kp, m_Ki, m_Kd;
Nicolaemf 1:a2ceed49374e 29 float m_P, m_I, m_D;
Nicolaemf 1:a2ceed49374e 30
Nicolaemf 1:a2ceed49374e 31
Nicolaemf 1:a2ceed49374e 32
Nicolaemf 1:a2ceed49374e 33 public:
Nicolaemf 1:a2ceed49374e 34
Nicolaemf 1:a2ceed49374e 35 bool m_dirL, m_dirR, m_toggle;
Nicolaemf 1:a2ceed49374e 36 float m_speedL, m_speedR;
Nicolaemf 1:a2ceed49374e 37
Nicolaemf 3:54c41af9e119 38
Nicolaemf 1:a2ceed49374e 39 IRSensor(PinName pin1, PinName pin2, PinName pin3, PinName pin4, PinName pin5, float Kp, float Ki, float Kd);
Nicolaemf 3:54c41af9e119 40
Nicolaemf 3:54c41af9e119 41 //function attached to the ticker
Nicolaemf 3:54c41af9e119 42 //reads the values from the Photodiodes to the linesensor array
Nicolaemf 1:a2ceed49374e 43 void Sample();
Nicolaemf 3:54c41af9e119 44
Nicolaemf 3:54c41af9e119 45 //Assigns a weight to the error from the IRsensors result
Nicolaemf 1:a2ceed49374e 46 void WeightPID();
Nicolaemf 3:54c41af9e119 47
Nicolaemf 3:54c41af9e119 48 //Calculates the total PID
Nicolaemf 3:54c41af9e119 49 //the response will highly depend on Kp, Ki and Kd which can assigned when instantiating
Nicolaemf 1:a2ceed49374e 50 void CalculatePID();
Nicolaemf 3:54c41af9e119 51
Nicolaemf 3:54c41af9e119 52 //controls the motor depending on the error calculated by the previous methods
Nicolaemf 3:54c41af9e119 53 //takes in both RobotControls instances which control the left and right
Nicolaemf 1:a2ceed49374e 54 void MotorControl(RobotControl controlLeft, RobotControl controlRight);
Nicolaemf 1:a2ceed49374e 55
Nicolaemf 1:a2ceed49374e 56
Nicolaemf 1:a2ceed49374e 57 };
Nicolaemf 1:a2ceed49374e 58
Nicolaemf 1:a2ceed49374e 59
Nicolaemf 1:a2ceed49374e 60
Nicolaemf 1:a2ceed49374e 61 #endif