ROME_P5

Dependencies:   mbed

Committer:
Inaueadr
Date:
Fri Apr 27 08:47:34 2018 +0000
Revision:
0:29be10cb0afc
Hallo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Inaueadr 0:29be10cb0afc 1 /*
Inaueadr 0:29be10cb0afc 2 * Main.cpp
Inaueadr 0:29be10cb0afc 3 * Copyright (c) 2018, ZHAW
Inaueadr 0:29be10cb0afc 4 * All rights reserved.
Inaueadr 0:29be10cb0afc 5 */
Inaueadr 0:29be10cb0afc 6
Inaueadr 0:29be10cb0afc 7 #include <cstdlib>
Inaueadr 0:29be10cb0afc 8 #include <mbed.h>
Inaueadr 0:29be10cb0afc 9 #include "EncoderCounter.h"
Inaueadr 0:29be10cb0afc 10 #include "IRSensor.h"
Inaueadr 0:29be10cb0afc 11 #include "IMU.h"
Inaueadr 0:29be10cb0afc 12 #include "LIDAR.h"
Inaueadr 0:29be10cb0afc 13 #include "Controller.h"
Inaueadr 0:29be10cb0afc 14 #include "StateMachine.h"
Inaueadr 0:29be10cb0afc 15 #include "SerialServer.h"
Inaueadr 0:29be10cb0afc 16
Inaueadr 0:29be10cb0afc 17 int main() {
Inaueadr 0:29be10cb0afc 18
Inaueadr 0:29be10cb0afc 19
Inaueadr 0:29be10cb0afc 20
Inaueadr 0:29be10cb0afc 21 // create miscellaneous periphery objects
Inaueadr 0:29be10cb0afc 22
Inaueadr 0:29be10cb0afc 23 DigitalOut led(LED1);
Inaueadr 0:29be10cb0afc 24 DigitalIn button(USER_BUTTON);
Inaueadr 0:29be10cb0afc 25
Inaueadr 0:29be10cb0afc 26 DigitalOut led0(PC_8);
Inaueadr 0:29be10cb0afc 27 DigitalOut led1(PC_6);
Inaueadr 0:29be10cb0afc 28 DigitalOut led2(PB_12);
Inaueadr 0:29be10cb0afc 29 DigitalOut led3(PA_7);
Inaueadr 0:29be10cb0afc 30 DigitalOut led4(PC_0);
Inaueadr 0:29be10cb0afc 31 DigitalOut led5(PC_9);
Inaueadr 0:29be10cb0afc 32
Inaueadr 0:29be10cb0afc 33 // create motor control objects
Inaueadr 0:29be10cb0afc 34
Inaueadr 0:29be10cb0afc 35 DigitalOut enableMotorDriver(PB_2);
Inaueadr 0:29be10cb0afc 36 DigitalIn motorDriverFault(PB_14);
Inaueadr 0:29be10cb0afc 37 DigitalIn motorDriverWarning(PB_15);
Inaueadr 0:29be10cb0afc 38
Inaueadr 0:29be10cb0afc 39 PwmOut pwmLeft(PA_8);
Inaueadr 0:29be10cb0afc 40 PwmOut pwmRight(PA_9);
Inaueadr 0:29be10cb0afc 41
Inaueadr 0:29be10cb0afc 42 EncoderCounter counterLeft(PB_6, PB_7);
Inaueadr 0:29be10cb0afc 43 EncoderCounter counterRight(PA_6, PC_7);
Inaueadr 0:29be10cb0afc 44
Inaueadr 0:29be10cb0afc 45 // create distance sensor objects
Inaueadr 0:29be10cb0afc 46
Inaueadr 0:29be10cb0afc 47 DigitalOut enableIRSensors(PC_1);
Inaueadr 0:29be10cb0afc 48 enableIRSensors = 1;
Inaueadr 0:29be10cb0afc 49
Inaueadr 0:29be10cb0afc 50 AnalogIn distance(PB_1);
Inaueadr 0:29be10cb0afc 51 DigitalOut bit0(PH_1);
Inaueadr 0:29be10cb0afc 52 DigitalOut bit1(PC_2);
Inaueadr 0:29be10cb0afc 53 DigitalOut bit2(PC_3);
Inaueadr 0:29be10cb0afc 54
Inaueadr 0:29be10cb0afc 55 IRSensor irSensor0(distance, bit0, bit1, bit2, 0);
Inaueadr 0:29be10cb0afc 56 IRSensor irSensor1(distance, bit0, bit1, bit2, 1);
Inaueadr 0:29be10cb0afc 57 IRSensor irSensor2(distance, bit0, bit1, bit2, 2);
Inaueadr 0:29be10cb0afc 58 IRSensor irSensor3(distance, bit0, bit1, bit2, 3);
Inaueadr 0:29be10cb0afc 59 IRSensor irSensor4(distance, bit0, bit1, bit2, 4);
Inaueadr 0:29be10cb0afc 60 IRSensor irSensor5(distance, bit0, bit1, bit2, 5);
Inaueadr 0:29be10cb0afc 61
Inaueadr 0:29be10cb0afc 62 // create LIDAR object
Inaueadr 0:29be10cb0afc 63
Inaueadr 0:29be10cb0afc 64 PwmOut pwm(PA_10);
Inaueadr 0:29be10cb0afc 65 pwm.period(0.00005f);
Inaueadr 0:29be10cb0afc 66 pwm.write(0.5f); // 50% duty-cycle
Inaueadr 0:29be10cb0afc 67
Inaueadr 0:29be10cb0afc 68 RawSerial uart(PA_0, PA_1);
Inaueadr 0:29be10cb0afc 69
Inaueadr 0:29be10cb0afc 70 LIDAR lidar(uart);
Inaueadr 0:29be10cb0afc 71
Inaueadr 0:29be10cb0afc 72 // create robot controller objects
Inaueadr 0:29be10cb0afc 73
Inaueadr 0:29be10cb0afc 74 Controller controller(pwmLeft, pwmRight, counterLeft, counterRight);
Inaueadr 0:29be10cb0afc 75 StateMachine stateMachine(controller, enableMotorDriver, led0, led1, led2, led3, led4, led5, button, irSensor0, irSensor1, irSensor2, irSensor3, irSensor4, irSensor5);
Inaueadr 0:29be10cb0afc 76
Inaueadr 0:29be10cb0afc 77 // create serial server object
Inaueadr 0:29be10cb0afc 78
Inaueadr 0:29be10cb0afc 79 RawSerial serial(PB_10, PC_5);
Inaueadr 0:29be10cb0afc 80 serial.baud(9600);
Inaueadr 0:29be10cb0afc 81 serial.format(8, SerialBase::None, 1);
Inaueadr 0:29be10cb0afc 82
Inaueadr 0:29be10cb0afc 83 DigitalOut reset(PB_3);
Inaueadr 0:29be10cb0afc 84 DigitalOut modes1(PB_4);
Inaueadr 0:29be10cb0afc 85
Inaueadr 0:29be10cb0afc 86 modes1 = 0;
Inaueadr 0:29be10cb0afc 87
Inaueadr 0:29be10cb0afc 88 reset = 1; wait(0.1f);
Inaueadr 0:29be10cb0afc 89 reset = 0; wait(0.1f);
Inaueadr 0:29be10cb0afc 90 reset = 1; wait(0.1f);
Inaueadr 0:29be10cb0afc 91
Inaueadr 0:29be10cb0afc 92
Inaueadr 0:29be10cb0afc 93
Inaueadr 0:29be10cb0afc 94
Inaueadr 0:29be10cb0afc 95 SerialServer serialServer(serial, lidar, controller);
Inaueadr 0:29be10cb0afc 96
Inaueadr 0:29be10cb0afc 97
Inaueadr 0:29be10cb0afc 98 while (true) {
Inaueadr 0:29be10cb0afc 99
Inaueadr 0:29be10cb0afc 100 led = !led; // toggle led
Inaueadr 0:29be10cb0afc 101 led0 = !led0;
Inaueadr 0:29be10cb0afc 102 led1 = !led1;
Inaueadr 0:29be10cb0afc 103 led2 = !led2;
Inaueadr 0:29be10cb0afc 104 led3 = !led3;
Inaueadr 0:29be10cb0afc 105 led4 = !led4;
Inaueadr 0:29be10cb0afc 106 led5 = !led5;
Inaueadr 0:29be10cb0afc 107
Inaueadr 0:29be10cb0afc 108 //printf("hallo \r \n ");
Inaueadr 0:29be10cb0afc 109 wait(1.0f); // wait for 200 ms
Inaueadr 0:29be10cb0afc 110
Inaueadr 0:29be10cb0afc 111 lidar.lookForBeacon();
Inaueadr 0:29be10cb0afc 112 }
Inaueadr 0:29be10cb0afc 113 }
Inaueadr 0:29be10cb0afc 114