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