a
Dependencies: Servo ServoArm mbed
Fork of PES_Official-TestF by
Headers/Robot.h@17:4e1be70bdedb, 2017-05-18 (annotated)
- Committer:
- beacon
- Date:
- Thu May 18 14:27:09 2017 +0000
- Revision:
- 17:4e1be70bdedb
- Parent:
- 15:915f8839fe48
Si compila.
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 | 10:f76476943a6c | 7 | #include "ServoArm.h" |
beacon | 17:4e1be70bdedb | 8 | #include <Ultraschall.h> |
beacon | 0:d267b248eff4 | 9 | |
beacon | 0:d267b248eff4 | 10 | #include "mbed.h" |
beacon | 0:d267b248eff4 | 11 | |
beacon | 0:d267b248eff4 | 12 | |
beacon | 0:d267b248eff4 | 13 | /* Declarations for the Motors in the Robot in order to drive -------- */ |
beacon | 1:388c915756f5 | 14 | |
beacon | 1:388c915756f5 | 15 | class DistanceSensors |
beacon | 1:388c915756f5 | 16 | { |
beacon | 1:388c915756f5 | 17 | public: |
beacon | 1:388c915756f5 | 18 | |
beacon | 4:67d7177c213f | 19 | DistanceSensors(AnalogIn* sensorVoltage, AnalogIn* frontS, AnalogIn* leftS, AnalogIn* rightS, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number); |
beacon | 1:388c915756f5 | 20 | DistanceSensors(); |
beacon | 1:388c915756f5 | 21 | |
beacon | 4:67d7177c213f | 22 | void init(AnalogIn* sensorVoltage, AnalogIn* frontS, AnalogIn* leftS, AnalogIn* rightS, DigitalOut* bit0, DigitalOut* bit1, DigitalOut* bit2, int number); |
beacon | 1:388c915756f5 | 23 | virtual ~DistanceSensors(); |
beacon | 1:388c915756f5 | 24 | float read(); |
beacon | 1:388c915756f5 | 25 | |
beacon | 1:388c915756f5 | 26 | operator float(); //Is here to constantly return the value of read. |
beacon | 1:388c915756f5 | 27 | |
beacon | 1:388c915756f5 | 28 | private: |
beacon | 1:388c915756f5 | 29 | |
beacon | 1:388c915756f5 | 30 | AnalogIn* sensorVoltage; |
beacon | 4:67d7177c213f | 31 | AnalogIn* frontS; |
beacon | 4:67d7177c213f | 32 | AnalogIn* leftS; |
beacon | 4:67d7177c213f | 33 | AnalogIn* rightS; |
beacon | 4:67d7177c213f | 34 | |
beacon | 1:388c915756f5 | 35 | DigitalOut* bit0; |
beacon | 1:388c915756f5 | 36 | DigitalOut* bit1; |
beacon | 1:388c915756f5 | 37 | DigitalOut* bit2; |
beacon | 1:388c915756f5 | 38 | |
beacon | 1:388c915756f5 | 39 | int number; |
beacon | 1:388c915756f5 | 40 | |
beacon | 1:388c915756f5 | 41 | }; |
beacon | 1:388c915756f5 | 42 | |
beacon | 1:388c915756f5 | 43 | class Farbsensor |
beacon | 1:388c915756f5 | 44 | { |
beacon | 1:388c915756f5 | 45 | public: |
beacon | 1:388c915756f5 | 46 | |
beacon | 1:388c915756f5 | 47 | Farbsensor(); |
beacon | 1:388c915756f5 | 48 | Farbsensor(AnalogIn* FarbVoltage); |
beacon | 1:388c915756f5 | 49 | |
beacon | 1:388c915756f5 | 50 | void init(AnalogIn* FarbVoltage); |
beacon | 1:388c915756f5 | 51 | int read(); |
beacon | 1:388c915756f5 | 52 | operator int(); |
beacon | 1:388c915756f5 | 53 | |
beacon | 1:388c915756f5 | 54 | private: |
beacon | 1:388c915756f5 | 55 | |
beacon | 17:4e1be70bdedb | 56 | AnalogIn* FarbVoltage; |
beacon | 1:388c915756f5 | 57 | }; |
beacon | 6:ba26dd3251b3 | 58 | |
beacon | 4:67d7177c213f | 59 | class Arm{ |
beacon | 4:67d7177c213f | 60 | |
beacon | 4:67d7177c213f | 61 | public: |
beacon | 6:ba26dd3251b3 | 62 | |
beacon | 4:67d7177c213f | 63 | Arm(); |
beacon | 10:f76476943a6c | 64 | Arm(ServoArm* servoArm); |
beacon | 4:67d7177c213f | 65 | |
beacon | 10:f76476943a6c | 66 | void init(ServoArm* servoArm); |
beacon | 6:ba26dd3251b3 | 67 | |
beacon | 11:292bdbd85a9c | 68 | int collectToDown(); |
beacon | 11:292bdbd85a9c | 69 | int downToCollect(); |
beacon | 11:292bdbd85a9c | 70 | int collectToBack(); |
beacon | 11:292bdbd85a9c | 71 | int backToCollect(); |
beacon | 4:67d7177c213f | 72 | |
beacon | 4:67d7177c213f | 73 | private: |
beacon | 10:f76476943a6c | 74 | ServoArm* arm; |
beacon | 6:ba26dd3251b3 | 75 | float angle; |
beacon | 4:67d7177c213f | 76 | |
beacon | 4:67d7177c213f | 77 | }; |
beacon | 1:388c915756f5 | 78 | |
EpicG10 | 14:b61fbd13a7c9 | 79 | class Leiste{ |
EpicG10 | 14:b61fbd13a7c9 | 80 | |
EpicG10 | 14:b61fbd13a7c9 | 81 | public: |
EpicG10 | 14:b61fbd13a7c9 | 82 | |
EpicG10 | 14:b61fbd13a7c9 | 83 | Leiste(); |
EpicG10 | 14:b61fbd13a7c9 | 84 | Leiste(Servo* servoLeiste); |
EpicG10 | 14:b61fbd13a7c9 | 85 | |
EpicG10 | 14:b61fbd13a7c9 | 86 | void init(Servo* servoLeiste); |
EpicG10 | 14:b61fbd13a7c9 | 87 | |
beacon | 17:4e1be70bdedb | 88 | int upToDown(); |
beacon | 17:4e1be70bdedb | 89 | int downToUp(); |
EpicG10 | 14:b61fbd13a7c9 | 90 | |
EpicG10 | 14:b61fbd13a7c9 | 91 | |
EpicG10 | 14:b61fbd13a7c9 | 92 | private: |
EpicG10 | 14:b61fbd13a7c9 | 93 | Servo* leiste; |
EpicG10 | 14:b61fbd13a7c9 | 94 | |
EpicG10 | 14:b61fbd13a7c9 | 95 | |
EpicG10 | 14:b61fbd13a7c9 | 96 | }; |
EpicG10 | 14:b61fbd13a7c9 | 97 | |
beacon | 10:f76476943a6c | 98 | class Greifer |
beacon | 10:f76476943a6c | 99 | { |
beacon | 10:f76476943a6c | 100 | |
beacon | 10:f76476943a6c | 101 | public: |
beacon | 10:f76476943a6c | 102 | |
beacon | 10:f76476943a6c | 103 | Greifer(Servo* greifer); |
beacon | 10:f76476943a6c | 104 | Greifer(); |
beacon | 10:f76476943a6c | 105 | |
beacon | 10:f76476943a6c | 106 | void init(Servo* greifer); |
beacon | 11:292bdbd85a9c | 107 | int take(); |
beacon | 11:292bdbd85a9c | 108 | int leave(); |
EpicG10 | 15:915f8839fe48 | 109 | void nullPos(); |
beacon | 10:f76476943a6c | 110 | |
beacon | 10:f76476943a6c | 111 | private: |
beacon | 10:f76476943a6c | 112 | Servo* greifer; |
beacon | 10:f76476943a6c | 113 | |
beacon | 10:f76476943a6c | 114 | }; |
beacon | 10:f76476943a6c | 115 | |
beacon | 17:4e1be70bdedb | 116 | class USsensor |
beacon | 17:4e1be70bdedb | 117 | { |
beacon | 17:4e1be70bdedb | 118 | public: |
beacon | 17:4e1be70bdedb | 119 | |
beacon | 17:4e1be70bdedb | 120 | USsensor(); |
beacon | 17:4e1be70bdedb | 121 | USsensor(Ultraschall* Usensor); |
beacon | 17:4e1be70bdedb | 122 | void init(Ultraschall* Usensor); |
beacon | 17:4e1be70bdedb | 123 | float read(); |
beacon | 17:4e1be70bdedb | 124 | operator float(); |
beacon | 17:4e1be70bdedb | 125 | |
beacon | 17:4e1be70bdedb | 126 | private: |
beacon | 17:4e1be70bdedb | 127 | Ultraschall* Usensor; |
beacon | 17:4e1be70bdedb | 128 | }; |
beacon | 17:4e1be70bdedb | 129 | |
beacon | 0:d267b248eff4 | 130 | class Robot |
beacon | 0:d267b248eff4 | 131 | { |
beacon | 0:d267b248eff4 | 132 | |
beacon | 0:d267b248eff4 | 133 | public: |
beacon | 0:d267b248eff4 | 134 | |
beacon | 0:d267b248eff4 | 135 | //Robot related: |
beacon | 17:4e1be70bdedb | 136 | Robot(PwmOut* left, PwmOut* right, DigitalOut* powerSignal, DigitalOut* leds, AnalogIn* FarbVoltage, AnalogIn* frontS, AnalogIn* leftS, AnalogIn* rightS, ServoArm* Arm, Servo* Greifer, Servo* Leiste, Ultraschall* USsensor ); |
beacon | 4:67d7177c213f | 137 | |
beacon | 4:67d7177c213f | 138 | //Drive Functions |
beacon | 0:d267b248eff4 | 139 | void drive(); |
beacon | 4:67d7177c213f | 140 | void driveB(); |
beacon | 4:67d7177c213f | 141 | |
beacon | 0:d267b248eff4 | 142 | void turnLeft(); |
beacon | 4:67d7177c213f | 143 | void turnLeftS(); |
beacon | 0:d267b248eff4 | 144 | void turnRight(); |
beacon | 4:67d7177c213f | 145 | void turnRightS(); |
beacon | 0:d267b248eff4 | 146 | void turnAround(int left); |
beacon | 1:388c915756f5 | 147 | void stop(); |
beacon | 1:388c915756f5 | 148 | |
beacon | 4:67d7177c213f | 149 | //Functions that use the drive functions |
beacon | 17:4e1be70bdedb | 150 | void driveSlowly(); |
beacon | 17:4e1be70bdedb | 151 | void driveBackSlowly();/* |
beacon | 4:67d7177c213f | 152 | void wallRight(int* counter, int* timer, int* lastAct); |
beacon | 4:67d7177c213f | 153 | void wallLeft(int* counter, int* timer, int* lastAct); |
beacon | 4:67d7177c213f | 154 | void wallFront(int* counter, int* timer, int* lastAct); |
beacon | 4:67d7177c213f | 155 | void counterMax(int* counter, int* timer, int* lastAct, int* rando); |
beacon | 4:67d7177c213f | 156 | |
beacon | 5:1aaf5de776ff | 157 | void legoFront(int* counter, int* timer, int* lastAct, int* legoFound, int* found); |
beacon | 4:67d7177c213f | 158 | void legoRight(int* counter, int* timer, int* lastAct, int* legoFound); |
beacon | 4:67d7177c213f | 159 | void legoLeft(int* counter, int* timer, int* lastAct, int* legoFound); |
beacon | 4:67d7177c213f | 160 | |
beacon | 4:67d7177c213f | 161 | void nothingFound(int* counter, int* timer, int* lastAct); |
beacon | 17:4e1be70bdedb | 162 | */ |
beacon | 11:292bdbd85a9c | 163 | int search(int* timer); |
beacon | 10:f76476943a6c | 164 | |
beacon | 17:4e1be70bdedb | 165 | float see(int sensor); |
beacon | 10:f76476943a6c | 166 | int getErrorMotor(); |
beacon | 0:d267b248eff4 | 167 | |
beacon | 0:d267b248eff4 | 168 | //DistanceSensors related: |
beacon | 4:67d7177c213f | 169 | DistanceSensors sensors[9]; |
beacon | 17:4e1be70bdedb | 170 | USsensor USsensor; |
beacon | 4:67d7177c213f | 171 | AnalogIn* frontS; |
beacon | 4:67d7177c213f | 172 | AnalogIn* leftS; |
beacon | 4:67d7177c213f | 173 | AnalogIn* rightS; |
beacon | 4:67d7177c213f | 174 | |
beacon | 1:388c915756f5 | 175 | |
beacon | 1:388c915756f5 | 176 | void initializeDistanceSensors(); |
beacon | 1:388c915756f5 | 177 | //void init(); |
beacon | 0:d267b248eff4 | 178 | |
beacon | 1:388c915756f5 | 179 | //LEDS related: |
beacon | 6:ba26dd3251b3 | 180 | DigitalOut* leds; |
beacon | 0:d267b248eff4 | 181 | |
beacon | 1:388c915756f5 | 182 | //Farbsensors related: |
beacon | 6:ba26dd3251b3 | 183 | Farbsensor FarbVoltage; |
beacon | 17:4e1be70bdedb | 184 | DigitalOut* led; |
beacon | 6:ba26dd3251b3 | 185 | |
beacon | 6:ba26dd3251b3 | 186 | //Arm related: |
beacon | 6:ba26dd3251b3 | 187 | Arm Arm; |
beacon | 0:d267b248eff4 | 188 | |
beacon | 10:f76476943a6c | 189 | //Greifer related: |
beacon | 10:f76476943a6c | 190 | Greifer Greifer; |
beacon | 10:f76476943a6c | 191 | |
EpicG10 | 15:915f8839fe48 | 192 | //Leiste related: |
EpicG10 | 15:915f8839fe48 | 193 | Leiste Leiste; |
EpicG10 | 15:915f8839fe48 | 194 | |
beacon | 0:d267b248eff4 | 195 | private: |
beacon | 0:d267b248eff4 | 196 | |
beacon | 0:d267b248eff4 | 197 | //Robot related: |
beacon | 0:d267b248eff4 | 198 | PwmOut* left; |
beacon | 0:d267b248eff4 | 199 | PwmOut* right; |
beacon | 10:f76476943a6c | 200 | DigitalIn* errorMotor; |
beacon | 0:d267b248eff4 | 201 | |
beacon | 0:d267b248eff4 | 202 | DigitalOut* powerSignal; |
beacon | 0:d267b248eff4 | 203 | DigitalIn* errorSignal; |
beacon | 0:d267b248eff4 | 204 | DigitalIn* overtemperatur; |
beacon | 0:d267b248eff4 | 205 | |
beacon | 10:f76476943a6c | 206 | Servo* greifer; |
EpicG10 | 15:915f8839fe48 | 207 | Servo* leiste; |
beacon | 10:f76476943a6c | 208 | ServoArm* arm; |
beacon | 0:d267b248eff4 | 209 | }; |
beacon | 0:d267b248eff4 | 210 | |
beacon | 0:d267b248eff4 | 211 | #endif |