Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (2.229 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 ba75ee1d galberding
      CHECK_VOLTAGE,
55 181f2892 galberding
      IDLE
56
    };
57
58
59
60 58fe0e0b Thomas Schöpping
  explicit UserThread();
61
62
  virtual ~UserThread();
63
64
  virtual msg_t main();
65 181f2892 galberding
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 e2002d0e galberding
  uint16_t getProxyRingSum();
78 181f2892 galberding
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 58fe0e0b Thomas Schöpping
};
89
90
} // end of namespace amiro
91
92
#endif // AMIRO_USERTHREAD_H_