Nicolae Marton / Mbed 2 deprecated TDP3_Final

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers IRSensor_H.h Source File

IRSensor_H.h

00001 #ifndef IRSensor_H
00002 #define IRSensor_H
00003 
00004 #include <mbed.h>
00005 
00006 
00007 //IRSensor deals with sampling and processing the data from the IR sensors
00008 //the IR sensors are used to determine the position of the robot wrt the black line
00009 //A PID controller system is used to stabilize the Robot above the black line
00010 
00011 //Instantiation: the 5 pins for the IRSensor and Kp Ki and Kd for the PID
00012 
00013 class IRSensor
00014 {
00015 private:
00016     
00017     DigitalIn m_leftIR;
00018     DigitalIn m_midLeftIR;
00019     DigitalIn m_midIR;
00020     DigitalIn m_midRightIR;
00021     DigitalIn m_rightIR;
00022 
00023     
00024     bool m_lineSensor[5];
00025     int m_error, m_prevError;
00026     
00027     float prevPID;
00028     
00029     float m_P, m_I, m_D;
00030     float m_PID;
00031     
00032 
00033 
00034 public:
00035     
00036     bool m_dirL, m_dirR, m_toggle;
00037     float m_speedL, m_speedR;
00038     bool  m_prevDirL, m_prevDirR;
00039     float m_Kp, m_Ki, m_Kd, m_noErSpeed , m_turnSpeed;
00040     int m_color;
00041     
00042     
00043     IRSensor(PinName pin1, PinName pin2, PinName pin3, PinName pin4, PinName pin5, float Kp, float Ki, float Kd, float noErSpeed, float turnSpeed);
00044     
00045     //function attached to the ticker
00046     //reads the values from the Photodiodes to the linesensor array
00047     void Sample();
00048     
00049     //Assigns a weight to the error from the IRsensors result
00050     void WeightPID();
00051     
00052     //Calculates the total PID
00053     //the response will highly depend on Kp, Ki and Kd which can assigned when instantiating
00054     void CalculatePID();
00055     
00056     //controls the motor depending on the error calculated by the previous methods
00057     //takes in both RobotControls instances which control the left and right
00058     void MotorControl();
00059     
00060     
00061 };
00062 
00063 
00064 
00065 #endif