amiro-os / include / amiro / Odometry.h @ 2af9778e
History | View | Annotate | Download (2.568 KB)
1 | 58fe0e0b | Thomas Schöpping | #ifndef AMIRO_ODOMETRY_H_
|
---|---|---|---|
2 | #define AMIRO_ODOMETRY_H_
|
||
3 | |||
4 | #include <amiro/MotorControl.h> |
||
5 | b4885314 | Thomas Schöpping | #include <amiro/gyro/l3g4200d.hpp> |
6 | 58fe0e0b | Thomas Schöpping | |
7 | #include <Types.h> // types::position |
||
8 | |||
9 | namespace amiro { |
||
10 | |||
11 | f336542d | Timo Korthals | class Odometry : public chibios_rt::BaseStaticThread<512> {
|
12 | 58fe0e0b | Thomas Schöpping | public:
|
13 | /**
|
||
14 | * Constructor
|
||
15 | *
|
||
16 | * @param mi object for retrieving the motor increments of the qei
|
||
17 | b4885314 | Thomas Schöpping | * @param gyro object for retrieving the gyroscope data
|
18 | * @param mc object for retrieving calibration parameters
|
||
19 | 58fe0e0b | Thomas Schöpping | */
|
20 | b4885314 | Thomas Schöpping | Odometry(MotorIncrements* mi, L3G4200D* gyroscope); |
21 | 58fe0e0b | Thomas Schöpping | |
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 | 9090cc7e | galberding | |
32 | |||
33 | void setPositionXY(float pX, float pY); |
||
34 | |||
35 | |||
36 | 58fe0e0b | Thomas Schöpping | /**
|
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 | b4885314 | Thomas Schöpping | MotorIncrements* motorIncrements; // QEI driver
|
86 | L3G4200D* gyro; // Gyroscope driver
|
||
87 | 58fe0e0b | Thomas Schöpping | 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_ */ |