3rd year group project. Electronic and Electrical Engineering. Heriot-Watt University. This is the code for the mbed for the Automatic Little Object Organiser (ALOO).

Dependencies:   MCP23017 TCS3472_I2C WattBob_TextLCD mbed

Revision:
32:9a4046224b11
Parent:
22:993821a4c396
--- a/fpga.cpp	Thu Dec 03 15:50:14 2015 +0000
+++ b/fpga.cpp	Thu Dec 17 17:23:24 2015 +0100
@@ -5,6 +5,7 @@
 #include "fpga.h"
 #include "mbed.h"
 
+// Macro to sync MBED and FPGA clocks
 #define CLK() bbClk.write(1); wait(0.000001); bbClk.write(0); wait(0.000001);
 
 DigitalOut bbClk(p11);
@@ -21,23 +22,20 @@
 
 }
 
-/**  Function that checks first IR sensor to detect if block in shoot
-    @return 1 if sensor beam broken, 0 otherwise
- */
+/// Function that checks first IR sensor to detect if block in shoot
+/// @return 1 if sensor beam broken, 0 otherwise
 int FPGA::checkForBlock(){
 	return this->getBeamValue(1);
 }
 
-/**  Function that checks if block is also breaking the second IR sensor.
-    @result 1 if it's large, 0 otherwise
- */
+/// Function that checks if block is also breaking the second IR sensor.
+/// @result 1 if it's large, 0 otherwise
 int FPGA::checkForSize(){
 	return this->getBeamValue(2);
 }
 
-/** Moves the stopping servo in the "hopper" to stop blocks from falling
-    @param position: TBD
- */
+/// No longer used since idea of using top servo was discontinued.
+/// Moves the stopping servo in the "hopper" to stop blocks from falling
 void FPGA::moveStoppingServo(StoppingServoPositions position) {
 	if (position == Stop){
 		bbRst.write(0);
@@ -135,9 +133,7 @@
 	this->stoppingServoPosition = position;
 }
 
-/** Moves the servoe which decides which basket block should go into i.e. bad/good
-    @param positon: TBD
- */
+/// Moves the servoe which decides which basket block should go into i.e. haz or not
 void FPGA::moveSortingServo(SortingServoPositions position){
 	if (position == Haz){
 			// HAZ = 26
@@ -233,6 +229,8 @@
 	this->sortingServoPosition = position;
 }
 
+/// Toggles stopping servo based on current position.
+/// Used in the servo test mode.
 void FPGA::toggleStoppingServo(){
 	if (this->stoppingServoPosition == Go)
 		this->moveStoppingServo(Stop);
@@ -240,6 +238,8 @@
 		this->moveStoppingServo(Go);
 }
 
+/// Toggles sorting servo based on current position
+/// Used in the servo test mode.
 void FPGA::toggleSortingServo() {
 	if (this->sortingServoPosition == Haz)
 		this->moveSortingServo(NonHaz);
@@ -247,23 +247,25 @@
 		this->moveSortingServo(Haz);
 }
 
-/** Reset the stopping servo to default posiotn i.e. not letting blcoks fall.
- */
+/// Place holder function. Since all servo move to their default position after kServoWaitTime
+///Reset the stopping servo to default position
 void FPGA::resetStoppingServo(){
 
 }
-/** Reset the sorting servo to default posiont i.e. falling blocks go in haz-bin
- */
+/// Place holder function. Since all servo move to their default position after kServoWaitTime
+/// Reset the sorting servo to default position
 void FPGA::resetSortingServo(){
 
 }
-/** Reset both servos, simply calls their respective reset methods.
- */
+/// Place holder function. Since all servo move to their default position after kServoWaitTime
+/// Reset both servos, simply calls their respective reset methods.
 void FPGA::resetAllServos(){
 	resetSortingServo();
 	resetStoppingServo();
 }
 
+/// Get beam value i.e. high = 1, low = 0;
+/// Beam number Top = 1, Bottom = 2. USE ENUMS to avoid mistakes.
 int FPGA::getBeamValue(int beamNumber){
 	// Return 0 or 1 value for break beam
 	bbRst.write(0);
@@ -303,6 +305,8 @@
 	return -1;
 }
 
+/// Place holder for more servos that can be attached.
+/// Currently both servo have their own designated methods.
 void FPGA::moveServo(int servoNumber, int position){
 
 }