amiro-os / devices / DiWheelDrive / userthread.hpp @ c9fa414d
History | View | Annotate | Download (2.438 KB)
| 1 | 58fe0e0b | Thomas Schöpping | #ifndef AMIRO_USERTHREAD_H_
|
|---|---|---|---|
| 2 | #define AMIRO_USERTHREAD_H_
|
||
| 3 | |||
| 4 | #include <ch.hpp> |
||
| 5 | #include <amiroosconf.h> |
||
| 6 | 181f2892 | galberding | #include <amiro/Color.h> |
| 7 | 05d54823 | galberding | |
| 8 | 181f2892 | galberding | |
| 9 | // Speed when driving towards the docking station
|
||
| 10 | #define CHARGING_SPEED 5 |
||
| 11 | 61544eee | galberding | #define DETECTION_SPEED 10 |
| 12 | #define DIST_THRESH 100 |
||
| 13 | #define RELEASE_COUNT 200 |
||
| 14 | 181f2892 | galberding | // Thresh to determain how much update steps should pass while alining
|
| 15 | 61544eee | galberding | #define MAX_CORRECTION_STEPS 300 |
| 16 | 181f2892 | galberding | // Thresh for wheel proxy sensors, when summed values fall below the state changes
|
| 17 | #define PROXY_WHEEL_THRESH 18000 |
||
| 18 | e2002d0e | galberding | // Thresh for detecting obsticles
|
| 19 | 61544eee | galberding | #define PROXY_RING_THRESH 15000 |
| 20 | 181f2892 | galberding | // Thresh for how long (update steps) the front sensors are allowed to detect white
|
| 21 | 61544eee | galberding | #define WHITE_COUNT_THRESH 150 |
| 22 | 181f2892 | galberding | // Rotation around 180 degrees in microradian
|
| 23 | #define ROTATION_180 3141592 |
||
| 24 | // Rotation around -20 degrees in microradian
|
||
| 25 | #define ROTATION_20 -349065 |
||
| 26 | #define ROTATION_DURATION 10000 |
||
| 27 | |||
| 28 | 61544eee | galberding | #define RING_PROX_FRONT_THRESH 18000 |
| 29 | #define PROX_MAX_VAL 65430 |
||
| 30 | 58fe0e0b | Thomas Schöpping | |
| 31 | namespace amiro {
|
||
| 32 | |||
| 33 | 181f2892 | galberding | |
| 34 | 58fe0e0b | Thomas Schöpping | class UserThread : public chibios_rt::BaseStaticThread<USER_THREAD_STACK_SIZE> |
| 35 | {
|
||
| 36 | 181f2892 | galberding | |
| 37 | // Messages which can be received and trigger state changes
|
||
| 38 | public:
|
||
| 39 | enum msg_content{
|
||
| 40 | STOP, |
||
| 41 | START, |
||
| 42 | EDGE_LEFT, |
||
| 43 | EDGE_RIGHT, |
||
| 44 | FUZZY, |
||
| 45 | DOCK, |
||
| 46 | UNDOCK, |
||
| 47 | CHARGE |
||
| 48 | }; |
||
| 49 | |||
| 50 | // States of user thread state machine
|
||
| 51 | enum states{
|
||
| 52 | FOLLOW_LINE, |
||
| 53 | RELEASE, |
||
| 54 | 019224ff | galberding | RELEASE_TO_CORRECT, |
| 55 | 181f2892 | galberding | CHARGING, |
| 56 | DETECT_STATION, |
||
| 57 | CORRECT_POSITIONING, |
||
| 58 | REVERSE, |
||
| 59 | CHECK_POSITIONING, |
||
| 60 | ba75ee1d | galberding | CHECK_VOLTAGE, |
| 61 | 181f2892 | galberding | IDLE |
| 62 | }; |
||
| 63 | |||
| 64 | |||
| 65 | |||
| 66 | 58fe0e0b | Thomas Schöpping | explicit UserThread();
|
| 67 | |||
| 68 | virtual ~UserThread();
|
||
| 69 | |||
| 70 | virtual msg_t main();
|
||
| 71 | 181f2892 | galberding | |
| 72 | private:
|
||
| 73 | void setRpmSpeed(const int (&rpmSpeed)[2]); |
||
| 74 | c9fa414d | galberding | void setRpmSpeedFuzzy(const int (&rpmSpeed)[2]); |
| 75 | 181f2892 | galberding | void lightOneLed(Color color, int idx); |
| 76 | void lightAllLeds(Color color);
|
||
| 77 | /**
|
||
| 78 | * Uses light ring indicate the state of charge.
|
||
| 79 | */
|
||
| 80 | void showChargingState();
|
||
| 81 | void checkForMotion();
|
||
| 82 | bool checkPinVoltage();
|
||
| 83 | bool checkPinEnabled();
|
||
| 84 | c9fa414d | galberding | int getProxyRingSum();
|
| 85 | |||
| 86 | 181f2892 | galberding | |
| 87 | /**
|
||
| 88 | * Check if current position changes when the wheel are deactivated.
|
||
| 89 | *
|
||
| 90 | * When AMiRo drives towards the loading station, it stops when a specific marker is reached.
|
||
| 91 | * In order to validate that the AMiRo is correctly positioned in the loading station
|
||
| 92 | * the wheels are turned off. When the position remains the same the docking procedure
|
||
| 93 | * was successful (return 1) otherwise a correction is needed (return 0).
|
||
| 94 | */
|
||
| 95 | int checkDockingSuccess();
|
||
| 96 | 58fe0e0b | Thomas Schöpping | }; |
| 97 | |||
| 98 | } // end of namespace amiro
|
||
| 99 | |||
| 100 | #endif // AMIRO_USERTHREAD_H_ |