a
Dependencies: Servo ServoArm mbed
Fork of PES_Official-TestF by
Headers/Robot.h@6:ba26dd3251b3, 2017-04-26 (annotated)
- Committer:
- beacon
- Date:
- Wed Apr 26 14:09:08 2017 +0000
- Revision:
- 6:ba26dd3251b3
- Parent:
- 5:1aaf5de776ff
- Child:
- 10:f76476943a6c
YESSS! On time!!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
beacon | 0:d267b248eff4 | 1 | #ifndef ROBOT_H |
beacon | 0:d267b248eff4 | 2 | #define ROBOT_H |
beacon | 0:d267b248eff4 | 3 | |
beacon | 0:d267b248eff4 | 4 | #include <cstdlib> |
beacon | 0:d267b248eff4 | 5 | #include <mbed.h> |
beacon | 4:67d7177c213f | 6 | #include "Servo.h" |
beacon | 0:d267b248eff4 | 7 | |
beacon | 0:d267b248eff4 | 8 | #include "mbed.h" |
beacon | 0:d267b248eff4 | 9 | |
beacon | 0:d267b248eff4 | 10 | |
beacon | 0:d267b248eff4 | 11 | /* Declarations for the Motors in the Robot in order to drive -------- */ |
beacon | 1:388c915756f5 | 12 | |
beacon | 1:388c915756f5 | 13 | class DistanceSensors |
beacon | 1:388c915756f5 | 14 | { |
beacon | 1:388c915756f5 | 15 | public: |
beacon | 1:388c915756f5 | 16 | |
beacon | 4:67d7177c213f | 17 | DistanceSensors(AnalogIn* sensorVoltage, AnalogIn* frontS, AnalogIn* leftS, AnalogIn* rightS, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number); |
beacon | 1:388c915756f5 | 18 | DistanceSensors(); |
beacon | 1:388c915756f5 | 19 | |
beacon | 4:67d7177c213f | 20 | void init(AnalogIn* sensorVoltage, AnalogIn* frontS, AnalogIn* leftS, AnalogIn* rightS, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number); |
beacon | 1:388c915756f5 | 21 | virtual ~DistanceSensors(); |
beacon | 1:388c915756f5 | 22 | float read(); |
beacon | 1:388c915756f5 | 23 | |
beacon | 1:388c915756f5 | 24 | operator float(); //Is here to constantly return the value of read. |
beacon | 1:388c915756f5 | 25 | |
beacon | 1:388c915756f5 | 26 | private: |
beacon | 1:388c915756f5 | 27 | |
beacon | 1:388c915756f5 | 28 | AnalogIn* sensorVoltage; |
beacon | 4:67d7177c213f | 29 | AnalogIn* frontS; |
beacon | 4:67d7177c213f | 30 | AnalogIn* leftS; |
beacon | 4:67d7177c213f | 31 | AnalogIn* rightS; |
beacon | 4:67d7177c213f | 32 | |
beacon | 1:388c915756f5 | 33 | DigitalOut* bit0; |
beacon | 1:388c915756f5 | 34 | DigitalOut* bit1; |
beacon | 1:388c915756f5 | 35 | DigitalOut* bit2; |
beacon | 1:388c915756f5 | 36 | |
beacon | 1:388c915756f5 | 37 | int number; |
beacon | 1:388c915756f5 | 38 | |
beacon | 1:388c915756f5 | 39 | }; |
beacon | 1:388c915756f5 | 40 | |
beacon | 1:388c915756f5 | 41 | class Farbsensor |
beacon | 1:388c915756f5 | 42 | { |
beacon | 1:388c915756f5 | 43 | public: |
beacon | 1:388c915756f5 | 44 | |
beacon | 1:388c915756f5 | 45 | Farbsensor(); |
beacon | 1:388c915756f5 | 46 | Farbsensor(AnalogIn* FarbVoltage); |
beacon | 1:388c915756f5 | 47 | |
beacon | 1:388c915756f5 | 48 | void init(AnalogIn* FarbVoltage); |
beacon | 1:388c915756f5 | 49 | int read(); |
beacon | 1:388c915756f5 | 50 | operator int(); |
beacon | 1:388c915756f5 | 51 | |
beacon | 1:388c915756f5 | 52 | private: |
beacon | 1:388c915756f5 | 53 | |
beacon | 1:388c915756f5 | 54 | AnalogIn* FarbVoltage; |
beacon | 1:388c915756f5 | 55 | }; |
beacon | 6:ba26dd3251b3 | 56 | |
beacon | 4:67d7177c213f | 57 | class Arm{ |
beacon | 4:67d7177c213f | 58 | |
beacon | 4:67d7177c213f | 59 | public: |
beacon | 6:ba26dd3251b3 | 60 | |
beacon | 4:67d7177c213f | 61 | Arm(); |
beacon | 6:ba26dd3251b3 | 62 | Arm(Servo* servoArm); |
beacon | 4:67d7177c213f | 63 | |
beacon | 6:ba26dd3251b3 | 64 | void init(Servo* servoArm); |
beacon | 6:ba26dd3251b3 | 65 | |
beacon | 6:ba26dd3251b3 | 66 | void collecttodown(int* done); |
beacon | 6:ba26dd3251b3 | 67 | void downtocollect(int* done); |
beacon | 6:ba26dd3251b3 | 68 | void collecttoback(int* done); |
beacon | 6:ba26dd3251b3 | 69 | void backtocollect(int* done); |
beacon | 4:67d7177c213f | 70 | |
beacon | 4:67d7177c213f | 71 | private: |
beacon | 6:ba26dd3251b3 | 72 | Servo* servoArm; |
beacon | 6:ba26dd3251b3 | 73 | float angle; |
beacon | 4:67d7177c213f | 74 | |
beacon | 4:67d7177c213f | 75 | }; |
beacon | 1:388c915756f5 | 76 | |
beacon | 0:d267b248eff4 | 77 | class Robot |
beacon | 0:d267b248eff4 | 78 | { |
beacon | 0:d267b248eff4 | 79 | |
beacon | 0:d267b248eff4 | 80 | public: |
beacon | 0:d267b248eff4 | 81 | |
beacon | 0:d267b248eff4 | 82 | //Robot related: |
beacon | 6:ba26dd3251b3 | 83 | Robot(PwmOut* left, PwmOut* right, DigitalOut* enableSignal, DigitalOut* leds, AnalogIn* FarbVoltage, AnalogIn* frontS, AnalogIn* leftS, AnalogIn* rightS, Servo* Arm ); |
beacon | 4:67d7177c213f | 84 | |
beacon | 4:67d7177c213f | 85 | //Drive Functions |
beacon | 0:d267b248eff4 | 86 | void drive(); |
beacon | 4:67d7177c213f | 87 | void driveB(); |
beacon | 4:67d7177c213f | 88 | |
beacon | 0:d267b248eff4 | 89 | void turnLeft(); |
beacon | 4:67d7177c213f | 90 | void turnLeftS(); |
beacon | 0:d267b248eff4 | 91 | void turnRight(); |
beacon | 4:67d7177c213f | 92 | void turnRightS(); |
beacon | 0:d267b248eff4 | 93 | void turnAround(int left); |
beacon | 1:388c915756f5 | 94 | void stop(); |
beacon | 1:388c915756f5 | 95 | |
beacon | 4:67d7177c213f | 96 | //Functions that use the drive functions |
beacon | 4:67d7177c213f | 97 | void wallRight(int* counter, int* timer, int* lastAct); |
beacon | 4:67d7177c213f | 98 | void wallLeft(int* counter, int* timer, int* lastAct); |
beacon | 4:67d7177c213f | 99 | void wallFront(int* counter, int* timer, int* lastAct); |
beacon | 4:67d7177c213f | 100 | void counterMax(int* counter, int* timer, int* lastAct, int* rando); |
beacon | 4:67d7177c213f | 101 | |
beacon | 5:1aaf5de776ff | 102 | void legoFront(int* counter, int* timer, int* lastAct, int* legoFound, int* found); |
beacon | 4:67d7177c213f | 103 | void legoRight(int* counter, int* timer, int* lastAct, int* legoFound); |
beacon | 4:67d7177c213f | 104 | void legoLeft(int* counter, int* timer, int* lastAct, int* legoFound); |
beacon | 4:67d7177c213f | 105 | |
beacon | 4:67d7177c213f | 106 | void nothingFound(int* counter, int* timer, int* lastAct); |
beacon | 4:67d7177c213f | 107 | |
beacon | 4:67d7177c213f | 108 | void search(int* counter, int* timer, int* found); |
beacon | 4:67d7177c213f | 109 | void lego(int* counter, Timer* t); |
beacon | 0:d267b248eff4 | 110 | |
beacon | 0:d267b248eff4 | 111 | //DistanceSensors related: |
beacon | 4:67d7177c213f | 112 | DistanceSensors sensors[9]; |
beacon | 4:67d7177c213f | 113 | AnalogIn* frontS; |
beacon | 4:67d7177c213f | 114 | AnalogIn* leftS; |
beacon | 4:67d7177c213f | 115 | AnalogIn* rightS; |
beacon | 4:67d7177c213f | 116 | |
beacon | 1:388c915756f5 | 117 | |
beacon | 1:388c915756f5 | 118 | void initializeDistanceSensors(); |
beacon | 1:388c915756f5 | 119 | //void init(); |
beacon | 0:d267b248eff4 | 120 | |
beacon | 1:388c915756f5 | 121 | //LEDS related: |
beacon | 6:ba26dd3251b3 | 122 | DigitalOut* leds; |
beacon | 0:d267b248eff4 | 123 | |
beacon | 1:388c915756f5 | 124 | //Farbsensors related: |
beacon | 6:ba26dd3251b3 | 125 | Farbsensor FarbVoltage; |
beacon | 6:ba26dd3251b3 | 126 | |
beacon | 6:ba26dd3251b3 | 127 | //Arm related: |
beacon | 6:ba26dd3251b3 | 128 | Arm Arm; |
beacon | 0:d267b248eff4 | 129 | |
beacon | 0:d267b248eff4 | 130 | private: |
beacon | 0:d267b248eff4 | 131 | |
beacon | 0:d267b248eff4 | 132 | //Robot related: |
beacon | 0:d267b248eff4 | 133 | PwmOut* left; |
beacon | 0:d267b248eff4 | 134 | PwmOut* right; |
beacon | 0:d267b248eff4 | 135 | |
beacon | 0:d267b248eff4 | 136 | DigitalOut* powerSignal; |
beacon | 0:d267b248eff4 | 137 | DigitalIn* errorSignal; |
beacon | 0:d267b248eff4 | 138 | DigitalIn* overtemperatur; |
beacon | 0:d267b248eff4 | 139 | |
beacon | 4:67d7177c213f | 140 | Servo* arm; |
beacon | 4:67d7177c213f | 141 | |
beacon | 0:d267b248eff4 | 142 | |
beacon | 0:d267b248eff4 | 143 | }; |
beacon | 0:d267b248eff4 | 144 | |
beacon | 0:d267b248eff4 | 145 | #endif |