Statistics
| Branch: | Tag: | Revision:

amiro-os / devices / DiWheelDrive / userthread.hpp @ e2002d0e

History | View | Annotate | Download (2.208 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
// 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 e2002d0e galberding
// Thresh for detecting obsticles
16
#define PROXY_RING_THRESH 20000
17 181f2892 galberding
// 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 58fe0e0b Thomas Schöpping
26
namespace amiro {
27
28 181f2892 galberding
29 58fe0e0b Thomas Schöpping
class UserThread : public chibios_rt::BaseStaticThread<USER_THREAD_STACK_SIZE>
30
{
31 181f2892 galberding
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
      IDLE
55
    };
56
57
58
59 58fe0e0b Thomas Schöpping
  explicit UserThread();
60
61
  virtual ~UserThread();
62
63
  virtual msg_t main();
64 181f2892 galberding
65
private:
66
  void setRpmSpeed(const int (&rpmSpeed)[2]);
67
  void lightOneLed(Color color, int idx);
68
  void lightAllLeds(Color color);
69
  /**
70
   * Uses light ring indicate the state of charge.
71
   */
72
  void showChargingState();
73
  void checkForMotion();
74
  bool checkPinVoltage();
75
  bool checkPinEnabled();
76 e2002d0e galberding
  uint16_t getProxyRingSum();
77 181f2892 galberding
78
  /**
79
   * Check if current position changes when the wheel are deactivated.
80
   * 
81
   * When AMiRo drives towards the loading station, it stops when a specific marker is reached.
82
   * In order to validate that the AMiRo is correctly positioned in the loading station
83
   * the wheels are turned off. When the position remains the same the docking procedure
84
   * was successful (return 1) otherwise a correction is needed (return 0). 
85
   */
86
  int checkDockingSuccess();
87 58fe0e0b Thomas Schöpping
};
88
89
} // end of namespace amiro
90
91
#endif // AMIRO_USERTHREAD_H_