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/main.cpp
- Revision:
- 2:74d8b693bc62
- Parent:
- 1:a2ceed49374e
- Child:
- 3:54c41af9e119
diff -r a2ceed49374e -r 74d8b693bc62 LineFollowingRobot/main.cpp
--- a/LineFollowingRobot/main.cpp Sat Feb 02 16:11:37 2019 +0000
+++ b/LineFollowingRobot/main.cpp Sat Feb 02 16:38:08 2019 +0000
@@ -2,31 +2,70 @@
#include "RobotControl_H.h"
#include "IRSensor_H.h"
+/*
+Team Design Project 3 Group 1 : Create a Line Following Robot
-Ticker sampling;
+-----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);
-sampling.attach(callback(&IRSensor, &IRSensor::Sample), 0.01);
+IRsampling.attach(callback(&IRSensor, &IRSensor::Sample), 0.01);
-RobotControl controlLeft(PTC12,PTD4,PTA5);
-RobotControl controlRight(PTA13,PTA12,PTA4);
+//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;
}
}