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.
Fork of OmniWheels by
Diff: Main.cpp
- Revision:
- 0:d698f15ceaf1
- Child:
- 1:9c5af431a1f1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Main.cpp Mon Mar 12 08:07:29 2018 +0000 @@ -0,0 +1,125 @@ +/* + * Main.cpp + * Copyright (c) 2017, ZHAW + * All rights reserved. + * + * Created on: 06.10.2017 + * Author: Marcel Honegger + */ + +#include <cstdlib> +#include <mbed.h> +#include "IRSensor.h" +#include "Controller.h" +#include "StateMachine.h" +#include "SerialServer.h" + +using namespace std; + +class Main { + + public: + + Main(); + virtual ~Main(); + + private: + + static const uint32_t STACK_SIZE = 8192; // stack size of thread, given in [bytes] + + Thread thread; + void run(); +}; + +Main::Main() : thread(osPriorityNormal, STACK_SIZE) { + + thread.start(callback(this, &Main::run)); +} + +Main::~Main() {} + +void Main::run() { + + // create miscellaneous periphery objects + + DigitalOut led(LED1); + DigitalIn button(USER_BUTTON); + + DigitalOut led0(PB_1); + DigitalOut led1(PC_3); + DigitalOut led2(PD_2); + + // create motor control objects + + DigitalOut enableMotorDriver0(PB_5); + DigitalIn motor0Error(PA_13); + PwmOut pwm0(PB_8); + AnalogIn motor0Current(PA_0); + + DigitalOut enableMotorDriver1(PB_4); + DigitalIn motor1Error(PA_14); + PwmOut pwm1(PB_9); + AnalogIn motor1Current(PA_1); + + DigitalOut enableMotorDriver2(PB_3); + DigitalIn motor2Error(PA_15); + PwmOut pwm2(PB_6); + AnalogIn motor2Current(PA_4); + + // create distance sensor objects + + AnalogIn distance0(PC_0); + AnalogIn distance1(PC_1); + AnalogIn distance2(PC_2); + + IRSensor irSensor0(distance0); + IRSensor irSensor1(distance1); + IRSensor irSensor2(distance2); + + // create robot controller objects + + Controller controller(pwm0, pwm1, pwm2); + StateMachine stateMachine(controller, enableMotorDriver0, enableMotorDriver1, enableMotorDriver2, led0, led1, led2, button, irSensor0, irSensor1, irSensor2); + + // create serial server object + + RawSerial serial(PA_11, PA_12); + serial.baud(38400); + serial.format(8, SerialBase::None, 1); + + DigitalOut reset(PB_12); + DigitalOut modes1(PB_0); + + modes1 = 0; + + reset = 1; Thread::wait(100); + reset = 0; Thread::wait(100); + reset = 1; Thread::wait(100); + + SerialServer serialServer(serial, stateMachine); + + // enter main loop + + while (true) { + + led = !led; + + if (stateMachine.getState() == StateMachine::STATE_MANUAL) { + Thread::wait(100); + } else if (stateMachine.getState() == StateMachine::STATE_AUTOMATIC) { + Thread::wait(200); + } else { + Thread::wait(500); + } + } +} + +/** + * This is the main program of the ROME2RevG firmware. + */ +int32_t main() { + + Main main; + + Thread::wait(osWaitForever); +}