Nicolae Marton / Mbed 2 deprecated TDP3_OOP

Dependencies:   mbed

LineFollowingRobot/main.cpp

Committer:
Nicolaemf
Date:
2019-02-02
Revision:
2:74d8b693bc62
Parent:
1:a2ceed49374e
Child:
3:54c41af9e119

File content as of revision 2:74d8b693bc62:

#include <mbed.h>
#include "RobotControl_H.h"
#include "IRSensor_H.h"

/*
Team Design Project 3 Group 1 : Create a Line Following Robot 

-----PINOUT-----

IR Sensor Pinout :
    - Left Sensor :         PTC6
    - Middle Left Sensor :  PTC5
    - Middle Sensor :       PTC4
    - Middle Right Sensor : PTC3
    - Right Sensor :        PTC0
    
Motor Left Control :
    - Motor Enable :        PTA12
    - Backwards PWM :       PTA4
    - Forward PWM :         PTA5

Motor Left Control :
    - Motor Enable :        PTA13
    - Backwards PWM :       PTD5
    - Forward PWM :         PTD0

-----ARCHITECTURE-----

RobotControl:
    Class which controls the speed and Direction of the Robot
    
IRSensor :
    Class which deals with sampling the IR sensors and with the PID Calculations
    The sampling happens every 10 ms thanks to the IRsampling Ticker
    
*/



Ticker IRsampling;



int main(){


bool toggleIR;

IRSensor IRSensor(PTC6, PTC5, PTC4, PTC3, PTC0, 0.0, 0.0, 0.0);

IRsampling.attach(callback(&IRSensor, &IRSensor::Sample), 0.01);

//initialise the class twice, one controls the left part and the other the right
RobotControl controlLeft(PTA12,PTA4,PTA5);
RobotControl controlRight(PTA13,PTD5,PTD0);


 
 while(1){

    //waits for an interrupt to occur, then performs all the calculations
    if(toggleIR != IRSensor.m_toggle){
        
        IRSensor.WeightPID();
        IRSensor.CalculatePID();
        IRSensor.MotorControl(controlLeft,controlRight);
        
        toggleIR = IRSensor.m_toggle;
        }
        
    }   
    
}