gugus

Dependencies:   mbed

Committer:
Brignall
Date:
Fri May 18 12:18:21 2018 +0000
Revision:
0:1a0321f1ffbc
lala;

Who changed what in which revision?

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