Do NOT modify!

Dependencies:   mbed Servo ServoArm

Fork of PES_Yanick by zhaw_st16b_pes2_10

Committer:
beacon
Date:
Wed Apr 19 12:23:52 2017 +0000
Revision:
4:67d7177c213f
Parent:
2:01e9de508316
Child:
5:1aaf5de776ff
l;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
beacon 0:d267b248eff4 1 #include "mbed.h"
beacon 0:d267b248eff4 2 #include "Robot.h"
beacon 4:67d7177c213f 3 #include "Declarations.h"
beacon 0:d267b248eff4 4
beacon 0:d267b248eff4 5 #include <cstdlib>
beacon 0:d267b248eff4 6
beacon 4:67d7177c213f 7 //DistanceSensors related bottom:
beacon 0:d267b248eff4 8 Serial pc(SERIAL_TX, SERIAL_RX);
beacon 0:d267b248eff4 9
beacon 0:d267b248eff4 10 AnalogIn sensorVoltage(PB_1);
beacon 0:d267b248eff4 11 DigitalOut enable(PC_1);
beacon 0:d267b248eff4 12 DigitalOut bit0(PH_1);
beacon 0:d267b248eff4 13 DigitalOut bit1(PC_2);
beacon 0:d267b248eff4 14 DigitalOut bit2(PC_3);
beacon 1:388c915756f5 15
beacon 4:67d7177c213f 16 //DistanceSensors top:
beacon 4:67d7177c213f 17 AnalogIn frontS(A1);
beacon 4:67d7177c213f 18 AnalogIn leftS(A2);
beacon 4:67d7177c213f 19 AnalogIn rightS(A3);
beacon 4:67d7177c213f 20
beacon 1:388c915756f5 21 //Leds related:
beacon 1:388c915756f5 22 DigitalOut leds[6] = { PC_8, PC_6, PB_12, PA_7, PC_0, PC_9 };
beacon 0:d267b248eff4 23
beacon 1:388c915756f5 24 //motor related:
beacon 1:388c915756f5 25 PwmOut left(PA_8);
beacon 1:388c915756f5 26 PwmOut right(PA_9);
beacon 0:d267b248eff4 27
beacon 1:388c915756f5 28 DigitalOut powerSignal(PB_2);
beacon 1:388c915756f5 29 DigitalIn errorSignal(PB_14);
beacon 1:388c915756f5 30 DigitalIn overtemperatur(PB_15);
beacon 1:388c915756f5 31
beacon 4:67d7177c213f 32 //Arm:
beacon 4:67d7177c213f 33 //Servo arm(PC_7);
beacon 4:67d7177c213f 34
beacon 1:388c915756f5 35 //Farbsensor:
beacon 1:388c915756f5 36 AnalogIn FarbVoltage(A0);
beacon 1:388c915756f5 37
beacon 4:67d7177c213f 38 Robot sam( &left, &right, &powerSignal, leds, &FarbVoltage, &frontS, &leftS, &rightS ); //Implement the Farbsensor into the Robot init function!!
beacon 1:388c915756f5 39
beacon 1:388c915756f5 40 void initializeDistanceSensors(){
beacon 4:67d7177c213f 41 for( int ii = 0; ii<9; ++ii) {
beacon 4:67d7177c213f 42 sam.sensors[ii].init(&sensorVoltage, &frontS, &leftS, &rightS, &bit0, &bit1, &bit2, ii);
beacon 0:d267b248eff4 43
beacon 1:388c915756f5 44 enable = 1;
beacon 0:d267b248eff4 45 }
beacon 0:d267b248eff4 46 }
beacon 0:d267b248eff4 47
beacon 1:388c915756f5 48 /* */
beacon 1:388c915756f5 49 int main(){
beacon 4:67d7177c213f 50 initializeDistanceSensors(); //Initialises IR-Sensors.
beacon 4:67d7177c213f 51 int counter = 0; //Counts how many times the robot has turned, before driving
beacon 4:67d7177c213f 52 int timer = 0; //Is used, to reset the robot. Returns time in [0.1s]
beacon 4:67d7177c213f 53 //int lastFun = -1; //Is used, to check if the same action in Robot::search() was made multiple times.
beacon 4:67d7177c213f 54 int found = 0; //0:= no block available, 1 := a lego is ready to be picked up
beacon 0:d267b248eff4 55
beacon 4:67d7177c213f 56 while( 1 ){
beacon 4:67d7177c213f 57 if ( timer > TIMEOUT ){
beacon 4:67d7177c213f 58 NVIC_SystemReset(); //Resets Sam.
beacon 4:67d7177c213f 59 }
beacon 4:67d7177c213f 60 else if (found == 0){
beacon 4:67d7177c213f 61 sam.search(&counter, &timer, &found);
beacon 4:67d7177c213f 62 }
beacon 4:67d7177c213f 63 else{
beacon 4:67d7177c213f 64 //pick up lego
beacon 4:67d7177c213f 65 //found = 0;
beacon 4:67d7177c213f 66 }
beacon 1:388c915756f5 67
beacon 1:388c915756f5 68 wait( 0.1f );
beacon 0:d267b248eff4 69 }
beacon 0:d267b248eff4 70 return 0;
beacon 4:67d7177c213f 71 }
beacon 4:67d7177c213f 72
beacon 4:67d7177c213f 73 /* * /
beacon 4:67d7177c213f 74 int main(){
beacon 4:67d7177c213f 75
beacon 4:67d7177c213f 76 initializeDistanceSensors();
beacon 4:67d7177c213f 77 sam.stop();
beacon 4:67d7177c213f 78
beacon 4:67d7177c213f 79 while ( 1 ){
beacon 4:67d7177c213f 80 for (int i=0; i<6; i++){
beacon 4:67d7177c213f 81 sam.sensors[i] < NEAR ? sam.leds[i] = 1 : sam.leds[i] = 0;
beacon 4:67d7177c213f 82 }
beacon 4:67d7177c213f 83
beacon 4:67d7177c213f 84 sam.turnLeftS();
beacon 4:67d7177c213f 85
beacon 4:67d7177c213f 86 while (sam.sensors[FWD] < NEAR){
beacon 4:67d7177c213f 87 wait(0.05f);
beacon 4:67d7177c213f 88 sam.stop();
beacon 4:67d7177c213f 89 }
beacon 4:67d7177c213f 90
beacon 4:67d7177c213f 91 }
beacon 4:67d7177c213f 92 return 0;
beacon 4:67d7177c213f 93 }
beacon 4:67d7177c213f 94 /* */
beacon 4:67d7177c213f 95
beacon 4:67d7177c213f 96 /* * /
beacon 4:67d7177c213f 97 int main(){
beacon 4:67d7177c213f 98 for(float p=0; p<1.0; p += 0.1) {
beacon 4:67d7177c213f 99 // arm = p;
beacon 4:67d7177c213f 100 wait(0.2);
beacon 4:67d7177c213f 101 }
beacon 4:67d7177c213f 102 }
beacon 4:67d7177c213f 103 /* */