3/26/16 12:25 am JJ

Dependents:   steppertest R5 2016 Robotics Team 1

Fork of scanner by David Vasquez

Committer:
j_j205
Date:
Mon Feb 27 11:56:43 2017 +0000
Revision:
21:bbadc0b8ed9f
Parent:
20:08bad292c737
uncommented code section

Who changed what in which revision?

UserRevisionLine numberNew contents of line
j_j205 20:08bad292c737 1 #ifndef SCANNER_H
j_j205 0:999bb8fcd0b2 2 #define SCANNER_H
j_j205 0:999bb8fcd0b2 3 #include "mbed.h"
j_j205 4:6a8d80954323 4 #include "LongRangeSensor.h"
j_j205 8:32a445ae1d72 5 #include "ShortRangeSensor.h"
Hellkite85 7:52c4be3bfc1b 6 #include "StepperDrive.h"
Hellkite85 9:bae63bc84829 7 #include "Gripper.h"
Hellkite85 9:bae63bc84829 8 #include <stack>
j_j205 0:999bb8fcd0b2 9
j_j205 0:999bb8fcd0b2 10 class Scanner
j_j205 0:999bb8fcd0b2 11 {
j_j205 2:b281034eda86 12 public:
Hellkite85 7:52c4be3bfc1b 13 Scanner(Serial &pc1, StepperDrive &_drive, PinName _servoL, PinName _servoR,
j_j205 8:32a445ae1d72 14 ShortRangeSensor &_shortRangeL, ShortRangeSensor &_shortRangeR,
j_j205 4:6a8d80954323 15 LongRangeSensor &_longRangeL, LongRangeSensor &_longRangeR,
Hellkite85 18:f5c46fb2cd31 16 Gripper &_robotGrip, float _period = 0.2, ColorSensor colorSensor);
j_j205 3:992558a021d7 17 void huntMode();
Hellkite85 7:52c4be3bfc1b 18 void hunt();
j_j205 3:992558a021d7 19 void avoidMode();
j_j205 3:992558a021d7 20 void localize();
j_j205 6:5e24ff86b743 21 void localizeRight();
j_j205 6:5e24ff86b743 22 void localizeLeft();
j_j205 14:d327852dafd1 23 void localizeRightMode();
j_j205 14:d327852dafd1 24 void localizeLeftMode();
j_j205 3:992558a021d7 25 float getDistLeft() {return distLeft;}
j_j205 3:992558a021d7 26 float getDistRight() {return distRight;}
j_j205 6:5e24ff86b743 27 float getDistForwardL() {return distForwardL;}
j_j205 6:5e24ff86b743 28 float getDistForwardR() {return distForwardR;}
j_j205 12:514544a4014f 29 void setLocalizeRightFlag(bool value) {localizeRightFlag = value;}
j_j205 12:514544a4014f 30 void setLocalizeLeftFlag(bool value) {localizeLeftFlag = value;}
j_j205 12:514544a4014f 31 bool getYellowFlag() {return yellowFlag;}
j_j205 12:514544a4014f 32 bool getObjectFound() {return objectFound;}
j_j205 2:b281034eda86 33
j_j205 0:999bb8fcd0b2 34 private:
j_j205 12:514544a4014f 35 static const int YELLOW = 1;
j_j205 12:514544a4014f 36 static const int RED = 0;
j_j205 2:b281034eda86 37 static const int MIN_DUTY = 0;
j_j205 6:5e24ff86b743 38 static const int MAX_DUTY = 6;
j_j205 6:5e24ff86b743 39 static const int HALF_DUTY = 3;
j_j205 2:b281034eda86 40 static const float DELTA_DUTY = 4.2e-3;
j_j205 2:b281034eda86 41 float DUTY[13]; // {0.0500, 0.0542, 0.0583, 0.0625, 0.0667, 0.0708,
j_j205 2:b281034eda86 42 // 0.0750, 0.0792, 0.0833, 0.0875, 0.0917, 0.0958,
j_j205 2:b281034eda86 43 // 0.1000};
j_j205 2:b281034eda86 44 bool pitEnable;
j_j205 2:b281034eda86 45 int invertL;
j_j205 2:b281034eda86 46 int invertR;
j_j205 2:b281034eda86 47 int dutyL;
j_j205 2:b281034eda86 48 int dutyR;
j_j205 3:992558a021d7 49 float distLeft;
j_j205 3:992558a021d7 50 float distRight;
j_j205 6:5e24ff86b743 51 float distForwardL;
j_j205 6:5e24ff86b743 52 float distForwardR;
j_j205 0:999bb8fcd0b2 53 Serial &pc;
Hellkite85 7:52c4be3bfc1b 54 StepperDrive &drive;
j_j205 0:999bb8fcd0b2 55 PwmOut servoL;
j_j205 0:999bb8fcd0b2 56 PwmOut servoR;
j_j205 8:32a445ae1d72 57 ShortRangeSensor &shortRangeL;
j_j205 8:32a445ae1d72 58 ShortRangeSensor &shortRangeR;
j_j205 4:6a8d80954323 59 LongRangeSensor &longRangeL;
j_j205 4:6a8d80954323 60 LongRangeSensor &longRangeR;
j_j205 12:514544a4014f 61 Gripper &robotGrip;
j_j205 0:999bb8fcd0b2 62 float period;
j_j205 3:992558a021d7 63 bool obstacle;
j_j205 3:992558a021d7 64 bool huntFlag;
j_j205 6:5e24ff86b743 65 bool avoidFlag;
j_j205 6:5e24ff86b743 66 bool objectFound;
j_j205 12:514544a4014f 67 bool localizeRightFlag;
j_j205 12:514544a4014f 68 bool localizeLeftFlag;
j_j205 12:514544a4014f 69 bool yellowFlag;
Hellkite85 9:bae63bc84829 70
Hellkite85 9:bae63bc84829 71 struct huntMove
Hellkite85 9:bae63bc84829 72 {
Hellkite85 9:bae63bc84829 73 float distance;
Hellkite85 9:bae63bc84829 74 float angle;
Hellkite85 9:bae63bc84829 75 };
j_j205 2:b281034eda86 76
j_j205 3:992558a021d7 77 Ticker scanPit; // periodic interrupt timer
j_j205 2:b281034eda86 78
j_j205 2:b281034eda86 79 void scan();
j_j205 2:b281034eda86 80
Hellkite85 9:bae63bc84829 81 std::stack<huntMove> myStack;
j_j205 0:999bb8fcd0b2 82 };
j_j205 0:999bb8fcd0b2 83
j_j205 20:08bad292c737 84 #endif // SCANNER_H