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.
Dependencies: mbed
Diff: Main.cpp
- Revision:
- 1:08ca9b208045
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Main.cpp Fri Mar 31 11:00:19 2017 +0000
@@ -0,0 +1,76 @@
+/*
+ * Main.cpp
+ * Copyright (c) 2017, ZHAW
+ * All rights reserved.
+ */
+
+#include <cstdlib>
+#include <mbed.h>
+#include "IRSensor.h"
+#include "EncoderCounter.h"
+#include "Controller.h"
+#include "StateMachine.h"
+
+using namespace std;
+
+/**
+ * This is the main program of the mobile robot control software.
+ */
+int main() {
+
+ // create and initialize miscellaneous periphery objects
+
+ DigitalOut led(LED1);
+ DigitalIn button(USER_BUTTON);
+
+ DigitalOut led0(PC_8);
+ DigitalOut led1(PC_6);
+ DigitalOut led2(PB_12);
+ DigitalOut led3(PA_7);
+ DigitalOut led4(PC_0);
+ DigitalOut led5(PC_9);
+
+ // create distance sensor objects
+
+ DigitalOut enableIRSensors(PC_1);
+ enableIRSensors = 1;
+
+ AnalogIn distance(PB_1);
+ DigitalOut bit0(PH_1);
+ DigitalOut bit1(PC_2);
+ DigitalOut bit2(PC_3);
+
+ IRSensor irSensor0(distance, bit0, bit1, bit2, 0);
+ IRSensor irSensor1(distance, bit0, bit1, bit2, 1);
+ IRSensor irSensor2(distance, bit0, bit1, bit2, 2);
+ IRSensor irSensor3(distance, bit0, bit1, bit2, 3);
+ IRSensor irSensor4(distance, bit0, bit1, bit2, 4);
+ IRSensor irSensor5(distance, bit0, bit1, bit2, 5);
+
+ // create motor control objects
+
+ DigitalOut enableMotorDriver(PB_2);
+ DigitalIn motorDriverFault(PB_14);
+ DigitalIn motorDriverWarning(PB_15);
+
+ PwmOut pwmLeft(PA_8);
+ PwmOut pwmRight(PA_9);
+
+ EncoderCounter counterLeft(PB_6, PB_7);
+ EncoderCounter counterRight(PA_6, PC_7);
+
+ // create robot controller objects
+
+ Controller controller(pwmLeft, pwmRight, counterLeft, counterRight);
+ StateMachine stateMachine(controller, enableMotorDriver, led0, led1, led2, led3, led4, led5, button, irSensor0, irSensor1, irSensor2, irSensor3, irSensor4, irSensor5);
+
+ // enter main loop
+
+ while (true) {
+
+ led = !led;
+
+ wait((stateMachine.getState() != StateMachine::ROBOT_OFF) ? 0.1f : 0.2f);
+ }
+}
+