Statistics
| Branch: | Tag: | Revision:

amiro-os / devices / DiWheelDrive / userthread.hpp @ 019224ff

History | View | Annotate | Download (2.316 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 019224ff galberding
#define MAX_CORRECTION_STEPS 260
13 181f2892 galberding
// 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 019224ff galberding
#define RING_PROX_FRONT_THRESH 20000
26
#define PROX_MAX_VAL 65530
27 58fe0e0b Thomas Schöpping
28
namespace amiro {
29
30 181f2892 galberding
31 58fe0e0b Thomas Schöpping
class UserThread : public chibios_rt::BaseStaticThread<USER_THREAD_STACK_SIZE>
32
{
33 181f2892 galberding
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 019224ff galberding
      RELEASE_TO_CORRECT,
52 181f2892 galberding
      CHARGING,
53
      DETECT_STATION,
54
      CORRECT_POSITIONING,
55
      REVERSE,
56
      CHECK_POSITIONING,
57 ba75ee1d galberding
      CHECK_VOLTAGE,
58 181f2892 galberding
      IDLE
59
    };
60
61
62
63 58fe0e0b Thomas Schöpping
  explicit UserThread();
64
65
  virtual ~UserThread();
66
67
  virtual msg_t main();
68 181f2892 galberding
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 e2002d0e galberding
  uint16_t getProxyRingSum();
81 181f2892 galberding
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 58fe0e0b Thomas Schöpping
};
92
93
} // end of namespace amiro
94
95
#endif // AMIRO_USERTHREAD_H_