amiro-os / devices / DiWheelDrive / userthread.hpp @ 0f37fb41
History | View | Annotate | Download (2.94 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 | 27d4e1fa | galberding | |
21 | #define PUSH_BACK_COUNT 50 |
||
22 | 181f2892 | galberding | // Thresh for how long (update steps) the front sensors are allowed to detect white
|
23 | 61544eee | galberding | #define WHITE_COUNT_THRESH 150 |
24 | 181f2892 | galberding | // Rotation around 180 degrees in microradian
|
25 | #define ROTATION_180 3141592 |
||
26 | // Rotation around -20 degrees in microradian
|
||
27 | #define ROTATION_20 -349065 |
||
28 | #define ROTATION_DURATION 10000 |
||
29 | |||
30 | 61544eee | galberding | #define RING_PROX_FRONT_THRESH 18000 |
31 | #define PROX_MAX_VAL 65430 |
||
32 | 58fe0e0b | Thomas Schöpping | |
33 | 27d4e1fa | galberding | // Threshold for failing to dock
|
34 | #define DOCKING_ERROR_THRESH 4 |
||
35 | |||
36 | 58fe0e0b | Thomas Schöpping | namespace amiro {
|
37 | |||
38 | 181f2892 | galberding | |
39 | 58fe0e0b | Thomas Schöpping | class UserThread : public chibios_rt::BaseStaticThread<USER_THREAD_STACK_SIZE> |
40 | { |
||
41 | 181f2892 | galberding | |
42 | // Messages which can be received and trigger state changes
|
||
43 | public:
|
||
44 | enum msg_content{
|
||
45 | STOP, |
||
46 | START, |
||
47 | EDGE_LEFT, |
||
48 | EDGE_RIGHT, |
||
49 | FUZZY, |
||
50 | DOCK, |
||
51 | UNDOCK, |
||
52 | CHARGE |
||
53 | }; |
||
54 | |||
55 | // States of user thread state machine
|
||
56 | 27d4e1fa | galberding | enum states : uint8_t{
|
57 | IDLE = 0,
|
||
58 | FOLLOW_LINE = 1,
|
||
59 | DETECT_STATION = 2,
|
||
60 | REVERSE = 3,
|
||
61 | PUSH_BACK = 4,
|
||
62 | CHECK_POSITIONING = 5,
|
||
63 | CHECK_VOLTAGE = 6,
|
||
64 | CHARGING = 7,
|
||
65 | RELEASE = 8,
|
||
66 | RELEASE_TO_CORRECT = 9,
|
||
67 | CORRECT_POSITIONING = 10,
|
||
68 | ERROR = 11
|
||
69 | 181f2892 | galberding | }; |
70 | |||
71 | 27d4e1fa | galberding | struct ut_counter{
|
72 | int whiteCount = 0; |
||
73 | int proxyCount = 0; |
||
74 | int reverseCount = 0; |
||
75 | int correctionCount = 0; |
||
76 | int errorCount = 0; |
||
77 | }; |
||
78 | 181f2892 | galberding | |
79 | 27d4e1fa | galberding | // static const struct ut_counter emptyUtCount;
|
80 | ut_counter utCount; |
||
81 | 181f2892 | galberding | |
82 | 58fe0e0b | Thomas Schöpping | explicit UserThread();
|
83 | |||
84 | virtual ~UserThread();
|
||
85 | |||
86 | virtual msg_t main();
|
||
87 | 181f2892 | galberding | |
88 | private:
|
||
89 | void setRpmSpeed(const int (&rpmSpeed)[2]); |
||
90 | c9fa414d | galberding | void setRpmSpeedFuzzy(const int (&rpmSpeed)[2]); |
91 | 181f2892 | galberding | void lightOneLed(Color color, int idx); |
92 | void lightAllLeds(Color color);
|
||
93 | /**
|
||
94 | * Uses light ring indicate the state of charge.
|
||
95 | */
|
||
96 | void showChargingState();
|
||
97 | void checkForMotion();
|
||
98 | bool checkPinVoltage();
|
||
99 | bool checkPinEnabled();
|
||
100 | c9fa414d | galberding | int getProxyRingSum();
|
101 | |||
102 | 181f2892 | galberding | |
103 | 27d4e1fa | galberding | |
104 | 181f2892 | galberding | /**
|
105 | * Check if current position changes when the wheel are deactivated.
|
||
106 | *
|
||
107 | * When AMiRo drives towards the loading station, it stops when a specific marker is reached.
|
||
108 | * In order to validate that the AMiRo is correctly positioned in the loading station
|
||
109 | * the wheels are turned off. When the position remains the same the docking procedure
|
||
110 | * was successful (return 1) otherwise a correction is needed (return 0).
|
||
111 | */
|
||
112 | int checkDockingSuccess();
|
||
113 | 58fe0e0b | Thomas Schöpping | }; |
114 | |||
115 | } // end of namespace amiro
|
||
116 | |||
117 | #endif // AMIRO_USERTHREAD_H_ |