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