amiro-os / include / amiro / Odometry.h @ 3f899f5d
History | View | Annotate | Download (2.294 KB)
1 | 58fe0e0b | Thomas Schöpping | #ifndef AMIRO_ODOMETRY_H_
|
---|---|---|---|
2 | #define AMIRO_ODOMETRY_H_
|
||
3 | |||
4 | #include <amiro/MotorControl.h> |
||
5 | |||
6 | #include <Types.h> // types::position |
||
7 | |||
8 | namespace amiro { |
||
9 | |||
10 | class Odometry : public chibios_rt::BaseStaticThread<512> {
|
||
11 | public:
|
||
12 | /**
|
||
13 | * Constructor
|
||
14 | *
|
||
15 | * @param mi object for retrieving the motor increments of the qei
|
||
16 | */
|
||
17 | Odometry(MotorIncrements* mi); |
||
18 | |||
19 | /**
|
||
20 | * Set the position of the roboter
|
||
21 | *
|
||
22 | * @param pX Position x in meter
|
||
23 | * @param pY Position y in meter
|
||
24 | * @param pPhi Orientation phi in radiant
|
||
25 | */
|
||
26 | void setPosition(float pX, float pY, float pPhi); |
||
27 | |||
28 | /**
|
||
29 | * Reset the position to [0,0,0]
|
||
30 | */
|
||
31 | void resetPosition();
|
||
32 | |||
33 | /**
|
||
34 | * Set the position of the roboter
|
||
35 | *
|
||
36 | * @param *Cp
|
||
37 | */
|
||
38 | void setError(float* Cp); |
||
39 | |||
40 | /**
|
||
41 | * Reset the error to [0,0,0;0,0,0;0,0,0]
|
||
42 | */
|
||
43 | void resetError();
|
||
44 | |||
45 | /**
|
||
46 | * Updates the wheelBaseDistance variable,
|
||
47 | * because it may change after an calibration.
|
||
48 | */
|
||
49 | void updateWheelBaseDistance();
|
||
50 | |||
51 | /**
|
||
52 | * Get the current position
|
||
53 | * @return position
|
||
54 | */
|
||
55 | types::position getPosition(); |
||
56 | |||
57 | chibios_rt::EvtSource* getEventSource(); |
||
58 | |||
59 | protected:
|
||
60 | virtual msg_t main(void);
|
||
61 | |||
62 | private:
|
||
63 | |||
64 | /**
|
||
65 | * Calculate the actual distance of both wheels
|
||
66 | */
|
||
67 | void updateDistance();
|
||
68 | |||
69 | /**
|
||
70 | * This is th PID controller for controling
|
||
71 | * the speed. It gets the new duty cicle for the pwm
|
||
72 | * and saves it to this->pwmPercentage to reach the
|
||
73 | * target speed this->targetSpeed
|
||
74 | */
|
||
75 | void updateOdometry();
|
||
76 | |||
77 | MotorIncrements* motorIncrements; |
||
78 | chibios_rt::EvtSource eventSource; |
||
79 | const unsigned int period; |
||
80 | int incrementsPerRevolution;
|
||
81 | int updatesPerMinute;
|
||
82 | float wheelCircumference; // wheel circumference in meter |
||
83 | float wheelBaseDistanceSI; // Base width in meter |
||
84 | float distance[2]; // Moved distance per wheel in meter left:0 right:1 |
||
85 | float wheelError[2]; // error for left:0 and right:1 wheel |
||
86 | float pX, pY; // Position in meter |
||
87 | float pPhi; // Orientation in Rad |
||
88 | float Cp3x3[9]; // Covariance (position error) (3x3 matrix) |
||
89 | int32_t increment[2]; // Absolute number of difference since last update |
||
90 | float incrementDifference[2]; // Difference between old and current absolute increments |
||
91 | }; |
||
92 | |||
93 | } |
||
94 | |||
95 | #endif /* AMIRO_ODOMETRY_ */ |