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