Nicolae Marton / Mbed 2 deprecated TDP3_OOP

Dependencies:   mbed

Committer:
Nicolaemf
Date:
Thu Mar 07 14:00:42 2019 +0000
Revision:
5:bb0bec710c91
Parent:
4:645b5d648c64
linefollower;

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 4:645b5d648c64 23
Nicolaemf 1:a2ceed49374e 24 bool m_lineSensor[5];
Nicolaemf 1:a2ceed49374e 25
Nicolaemf 3:54c41af9e119 26 int m_color;
Nicolaemf 5:bb0bec710c91 27 int m_error, m_prevError;
Nicolaemf 5:bb0bec710c91 28 float m_Kp, m_Ki, m_Kd;
Nicolaemf 1:a2ceed49374e 29 float m_P, m_I, m_D;
Nicolaemf 5:bb0bec710c91 30 float m_PID;
Nicolaemf 1:a2ceed49374e 31
Nicolaemf 1:a2ceed49374e 32
Nicolaemf 1:a2ceed49374e 33
Nicolaemf 1:a2ceed49374e 34 public:
Nicolaemf 1:a2ceed49374e 35
Nicolaemf 1:a2ceed49374e 36 bool m_dirL, m_dirR, m_toggle;
Nicolaemf 1:a2ceed49374e 37 float m_speedL, m_speedR;
Nicolaemf 4:645b5d648c64 38 bool m_prevDirL, m_prevDirR;
Nicolaemf 1:a2ceed49374e 39
Nicolaemf 3:54c41af9e119 40
Nicolaemf 1:a2ceed49374e 41 IRSensor(PinName pin1, PinName pin2, PinName pin3, PinName pin4, PinName pin5, float Kp, float Ki, float Kd);
Nicolaemf 3:54c41af9e119 42
Nicolaemf 3:54c41af9e119 43 //function attached to the ticker
Nicolaemf 3:54c41af9e119 44 //reads the values from the Photodiodes to the linesensor array
Nicolaemf 1:a2ceed49374e 45 void Sample();
Nicolaemf 3:54c41af9e119 46
Nicolaemf 3:54c41af9e119 47 //Assigns a weight to the error from the IRsensors result
Nicolaemf 1:a2ceed49374e 48 void WeightPID();
Nicolaemf 3:54c41af9e119 49
Nicolaemf 3:54c41af9e119 50 //Calculates the total PID
Nicolaemf 3:54c41af9e119 51 //the response will highly depend on Kp, Ki and Kd which can assigned when instantiating
Nicolaemf 1:a2ceed49374e 52 void CalculatePID();
Nicolaemf 3:54c41af9e119 53
Nicolaemf 3:54c41af9e119 54 //controls the motor depending on the error calculated by the previous methods
Nicolaemf 3:54c41af9e119 55 //takes in both RobotControls instances which control the left and right
Nicolaemf 5:bb0bec710c91 56 void MotorControl();
Nicolaemf 1:a2ceed49374e 57
Nicolaemf 1:a2ceed49374e 58
Nicolaemf 1:a2ceed49374e 59 };
Nicolaemf 1:a2ceed49374e 60
Nicolaemf 1:a2ceed49374e 61
Nicolaemf 1:a2ceed49374e 62
Nicolaemf 1:a2ceed49374e 63 #endif