Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: LineFollowingRobot/IRSensor_H.h
- Revision:
- 3:54c41af9e119
- Parent:
- 1:a2ceed49374e
- Child:
- 4:645b5d648c64
diff -r 74d8b693bc62 -r 54c41af9e119 LineFollowingRobot/IRSensor_H.h --- a/LineFollowingRobot/IRSensor_H.h Sat Feb 02 16:38:08 2019 +0000 +++ b/LineFollowingRobot/IRSensor_H.h Sun Feb 03 16:42:44 2019 +0000 @@ -4,6 +4,12 @@ #include <mbed.h> #include "RobotControl_H.h" +//IRSensor deals with sampling and processing the data from the IR sensors +//the IR sensors are used to determine the position of the robot wrt the black line +//A PID controller system is used to stabilize the Robot above the black line + +//Instantiation: the 5 pins for the IRSensor and Kp Ki and Kd for the PID + class IRSensor { private: @@ -17,6 +23,7 @@ bool m_prevDirL, m_prevDirR; bool m_lineSensor[5]; + int m_color; short int m_error, m_prevError; const float m_Kp, m_Ki, m_Kd; float m_P, m_I, m_D; @@ -28,10 +35,22 @@ bool m_dirL, m_dirR, m_toggle; float m_speedL, m_speedR; + IRSensor(PinName pin1, PinName pin2, PinName pin3, PinName pin4, PinName pin5, float Kp, float Ki, float Kd); + + //function attached to the ticker + //reads the values from the Photodiodes to the linesensor array void Sample(); + + //Assigns a weight to the error from the IRsensors result void WeightPID(); + + //Calculates the total PID + //the response will highly depend on Kp, Ki and Kd which can assigned when instantiating void CalculatePID(); + + //controls the motor depending on the error calculated by the previous methods + //takes in both RobotControls instances which control the left and right void MotorControl(RobotControl controlLeft, RobotControl controlRight);