Do NOT modify!

Dependencies:   mbed Servo ServoArm

Fork of PES_Yanick by zhaw_st16b_pes2_10

Committer:
beacon
Date:
Wed Apr 26 14:09:08 2017 +0000
Revision:
6:ba26dd3251b3
Parent:
5:1aaf5de776ff
Child:
7:6fed0dcae9c1
YESSS! On time!!

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 6:ba26dd3251b3 33 Servo servoArm(PA_6);
beacon 4:67d7177c213f 34
beacon 1:388c915756f5 35 //Farbsensor:
beacon 1:388c915756f5 36 AnalogIn FarbVoltage(A0);
beacon 1:388c915756f5 37
beacon 6:ba26dd3251b3 38 Robot sam( &left, &right, &powerSignal, leds, &FarbVoltage, &frontS, &leftS, &rightS, &servoArm); //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 6:ba26dd3251b3 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 5:1aaf5de776ff 66 sam.stop(); //Nur zum Testen
beacon 4:67d7177c213f 67 }
beacon 1:388c915756f5 68
beacon 1:388c915756f5 69 wait( 0.1f );
beacon 0:d267b248eff4 70 }
beacon 0:d267b248eff4 71 return 0;
beacon 4:67d7177c213f 72 }
beacon 4:67d7177c213f 73
beacon 4:67d7177c213f 74 /* * /
beacon 4:67d7177c213f 75 int main(){
beacon 4:67d7177c213f 76
beacon 4:67d7177c213f 77 initializeDistanceSensors();
beacon 4:67d7177c213f 78 sam.stop();
beacon 4:67d7177c213f 79
beacon 4:67d7177c213f 80 while ( 1 ){
beacon 4:67d7177c213f 81 for (int i=0; i<6; i++){
beacon 4:67d7177c213f 82 sam.sensors[i] < NEAR ? sam.leds[i] = 1 : sam.leds[i] = 0;
beacon 4:67d7177c213f 83 }
beacon 4:67d7177c213f 84
beacon 4:67d7177c213f 85 sam.turnLeftS();
beacon 4:67d7177c213f 86
beacon 4:67d7177c213f 87 while (sam.sensors[FWD] < NEAR){
beacon 4:67d7177c213f 88 wait(0.05f);
beacon 4:67d7177c213f 89 sam.stop();
beacon 4:67d7177c213f 90 }
beacon 4:67d7177c213f 91
beacon 4:67d7177c213f 92 }
beacon 4:67d7177c213f 93 return 0;
beacon 4:67d7177c213f 94 }
beacon 4:67d7177c213f 95 /* */
beacon 4:67d7177c213f 96
beacon 4:67d7177c213f 97 /* * /
beacon 4:67d7177c213f 98 int main(){
beacon 4:67d7177c213f 99 for(float p=0; p<1.0; p += 0.1) {
beacon 4:67d7177c213f 100 // arm = p;
beacon 4:67d7177c213f 101 wait(0.2);
beacon 4:67d7177c213f 102 }
beacon 4:67d7177c213f 103 }
beacon 6:ba26dd3251b3 104 /* */
beacon 6:ba26dd3251b3 105
beacon 6:ba26dd3251b3 106 /* */
beacon 6:ba26dd3251b3 107 int main(){
beacon 6:ba26dd3251b3 108 sam.stop();
beacon 6:ba26dd3251b3 109 int done = 0; //1:= finished process; 0:= not finished
beacon 6:ba26dd3251b3 110 int fun = 0; //just to test.
beacon 6:ba26dd3251b3 111
beacon 6:ba26dd3251b3 112 while(1){
beacon 6:ba26dd3251b3 113 if(fun == 0){
beacon 6:ba26dd3251b3 114 done = 0;
beacon 6:ba26dd3251b3 115 sam.Arm.collecttoback(&done);
beacon 6:ba26dd3251b3 116 done == 0 ? fun = 0 : fun = 1;
beacon 6:ba26dd3251b3 117 }
beacon 6:ba26dd3251b3 118 else if(fun == 1){
beacon 6:ba26dd3251b3 119 done = 0;
beacon 6:ba26dd3251b3 120 sam.Arm.backtocollect(&done);
beacon 6:ba26dd3251b3 121 done == 0 ? fun = 1 : fun = 2;
beacon 6:ba26dd3251b3 122 }
beacon 6:ba26dd3251b3 123 else if(fun == 2){
beacon 6:ba26dd3251b3 124 done = 0;
beacon 6:ba26dd3251b3 125 sam.Arm.collecttodown(&done);
beacon 6:ba26dd3251b3 126 done == 0 ? fun = 2 : fun = 3;
beacon 6:ba26dd3251b3 127 }
beacon 6:ba26dd3251b3 128 else if(fun == 3){
beacon 6:ba26dd3251b3 129 done = 0;
beacon 6:ba26dd3251b3 130 sam.Arm.downtocollect(&done);
beacon 6:ba26dd3251b3 131 done == 0 ? fun = 3 : fun = 0;
beacon 6:ba26dd3251b3 132 }
beacon 6:ba26dd3251b3 133 wait(0.1);
beacon 6:ba26dd3251b3 134 }
beacon 6:ba26dd3251b3 135 }