amiro-os / devices / DiWheelDrive / userthread.hpp @ ba75ee1d
History | View | Annotate | Download (2.23 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 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 |
|
26 |
namespace amiro {
|
27 |
|
28 |
|
29 |
class UserThread : public chibios_rt::BaseStaticThread<USER_THREAD_STACK_SIZE> |
30 |
{ |
31 |
|
32 |
// Messages which can be received and trigger state changes
|
33 |
public:
|
34 |
enum msg_content{
|
35 |
STOP, |
36 |
START, |
37 |
EDGE_LEFT, |
38 |
EDGE_RIGHT, |
39 |
FUZZY, |
40 |
DOCK, |
41 |
UNDOCK, |
42 |
CHARGE |
43 |
}; |
44 |
|
45 |
// States of user thread state machine
|
46 |
enum states{
|
47 |
FOLLOW_LINE, |
48 |
RELEASE, |
49 |
CHARGING, |
50 |
DETECT_STATION, |
51 |
CORRECT_POSITIONING, |
52 |
REVERSE, |
53 |
CHECK_POSITIONING, |
54 |
CHECK_VOLTAGE, |
55 |
IDLE |
56 |
}; |
57 |
|
58 |
|
59 |
|
60 |
explicit UserThread();
|
61 |
|
62 |
virtual ~UserThread();
|
63 |
|
64 |
virtual msg_t main();
|
65 |
|
66 |
private:
|
67 |
void setRpmSpeed(const int (&rpmSpeed)[2]); |
68 |
void lightOneLed(Color color, int idx); |
69 |
void lightAllLeds(Color color);
|
70 |
/**
|
71 |
* Uses light ring indicate the state of charge.
|
72 |
*/
|
73 |
void showChargingState();
|
74 |
void checkForMotion();
|
75 |
bool checkPinVoltage();
|
76 |
bool checkPinEnabled();
|
77 |
uint16_t getProxyRingSum(); |
78 |
|
79 |
/**
|
80 |
* Check if current position changes when the wheel are deactivated.
|
81 |
*
|
82 |
* When AMiRo drives towards the loading station, it stops when a specific marker is reached.
|
83 |
* In order to validate that the AMiRo is correctly positioned in the loading station
|
84 |
* the wheels are turned off. When the position remains the same the docking procedure
|
85 |
* was successful (return 1) otherwise a correction is needed (return 0).
|
86 |
*/
|
87 |
int checkDockingSuccess();
|
88 |
}; |
89 |
|
90 |
} // end of namespace amiro
|
91 |
|
92 |
#endif // AMIRO_USERTHREAD_H_ |