@@ -24,13 +24,9 @@ class Kinematics{
24
24
float wheel_diameter;
25
25
float wheel_radius;
26
26
float wheel_circumference;
27
- float rads_to_rpm;
28
- float rpm_to_rads;
29
- float rads_to_degs;
30
- float degs_to_rads;
31
- float rotations_to_rads;
32
- float rads_to_rotations;
33
- float w;
27
+
28
+ float v, w;
29
+ float left_vel, right_vel;
34
30
35
31
float theta, delta_theta;
36
32
float x, y;
@@ -40,6 +36,38 @@ class Kinematics{
40
36
float travel;
41
37
42
38
39
+ float mm_to_m (const float mm){
40
+ return mm*0.001 ;
41
+ }
42
+
43
+ float m_to_mm (const float m){
44
+ return m*1000.0 ;
45
+ }
46
+
47
+ float rads_to_degs (const float rads){
48
+ return rads*180.0 /PI;
49
+ }
50
+
51
+ float degs_to_rads (const float degs){
52
+ return degs*PI/180.0 ;
53
+ }
54
+
55
+ float rads_to_rpm (const float rads){
56
+ return rads*60.0 /(2.0 *PI);
57
+ }
58
+
59
+ float rpm_to_rads (const float rpm){
60
+ return rpm*2.0 *PI/60.0 ;
61
+ }
62
+
63
+ float rads_to_rotations (const float rads){
64
+ return rads/(2.0 *PI);
65
+ }
66
+
67
+ float rotations_to_rads (const float rotations){
68
+ return rotations*2.0 *PI;
69
+ }
70
+
43
71
44
72
public:
45
73
Kinematics (const float _wheel_track, const float _wheel_diameter){
@@ -48,19 +76,12 @@ class Kinematics{
48
76
right_velocity=0.0 ;
49
77
linear_velocity=0.0 ;
50
78
angular_velocity=0.0 ;
51
- wheel_track=_wheel_track;
52
- wheel_diameter=_wheel_diameter;
53
- wheel_radius=wheel_diameter/2.0 ;
54
- wheel_circumference=wheel_diameter*PI;
55
79
56
- rads_to_rpm= 60.0 /( 2.0 *PI );
57
- rpm_to_rads= 2.0 *PI/ 60.0 ;
80
+ wheel_track= mm_to_m (_wheel_track );
81
+ wheel_diameter= mm_to_m (_wheel_diameter) ;
58
82
59
- rads_to_degs=180.0 /PI;
60
- degs_to_rads=PI/180.0 ;
61
-
62
- rads_to_rotations=1 /(2.0 *PI);
63
- rotations_to_rads=2.0 *PI;
83
+ wheel_radius=wheel_diameter/2.0 ;
84
+ wheel_circumference=wheel_diameter*PI;
64
85
65
86
theta=0.0 ;
66
87
x=0.0 ;
@@ -77,51 +98,69 @@ class Kinematics{
77
98
}
78
99
79
100
void forward (const float linear, const float angular){
80
- w = angular*degs_to_rads ;
81
- left_velocity=( 2 *linear-w*wheel_track)/(wheel_diameter );
82
- left_velocity=rads_to_rpm*left_velocity;
83
- right_velocity =(2 *linear+ w*wheel_track)/(wheel_diameter);
84
- right_velocity=rads_to_rpm*right_velocity ;
101
+ v = mm_to_m (linear) ;
102
+ w = degs_to_rads (angular );
103
+
104
+ left_velocity =(2 *v- w*wheel_track)/(wheel_diameter);
105
+ right_velocity=( 2 *v+w*wheel_track)/(wheel_diameter) ;
85
106
}
86
107
87
- void inverse (const float left_vel, const float right_vel){
108
+ void inverse (const float left, const float right){
109
+ left_vel=rpm_to_rads (left);
110
+ right_vel=rpm_to_rads (right);
111
+
88
112
linear_velocity=(left_vel+right_vel)*wheel_radius/2.0 ;
89
113
angular_velocity=(-left_vel+right_vel)*wheel_radius/wheel_track;
90
114
}
91
115
92
116
float getLeftVelocity (){
93
- return left_velocity;
117
+ return rads_to_rpm ( left_velocity) ;
94
118
}
95
119
96
120
float getRightVelocity (){
97
- return right_velocity;
121
+ return rads_to_rpm ( right_velocity) ;
98
122
}
99
123
100
124
float getLinearVelocity (){
101
- return linear_velocity;
125
+ return m_to_mm ( linear_velocity) ;
102
126
}
103
127
104
128
float getAngularVelocity (){
105
- return angular_velocity;
129
+ return rads_to_degs ( angular_velocity) ;
106
130
}
107
131
132
+ /*
108
133
void updatePose(const float left_rotation, const float right_rotation){
109
134
delta_left=left_rotation*wheel_circumference;
110
135
delta_right=right_rotation*wheel_circumference;
111
136
delta_travel=(delta_left+delta_right)/2.0;
112
- delta_theta=(-delta_left+delta_right)/(2.0 *wheel_track);
137
+ delta_theta=(-delta_left+delta_right)/(wheel_track);
138
+
113
139
delta_x=delta_travel*cos(theta+delta_theta/2.0);
114
140
delta_y=delta_travel*sin(theta+delta_theta/2.0);
141
+
142
+ delta_x=delta_travel*cos(delta_theta);
143
+ delta_y=delta_travel*sin(delta_theta);
144
+ x+=delta_x;
145
+ y+=delta_y;
146
+ theta+=delta_theta;
147
+ travel+=delta_travel;
148
+ }
149
+ */
150
+
151
+ void updatePose (){
152
+ delta_theta=angular_velocity*0.02 ;
153
+ delta_x=linear_velocity*cos (theta)*0.02 ;
154
+ delta_y=linear_velocity*sin (theta)*0.02 ;
115
155
x+=delta_x;
116
156
y+=delta_y;
117
157
theta+=delta_theta;
118
- travel+=delta_travel;
119
158
}
120
159
121
160
void resetPose (const float initial_x=0.0 , const float initial_y=0.0 , const float initial_theta=0.0 ){
122
- x=initial_x;
123
- y=initial_y;
124
- theta=degs_to_rads* initial_theta;
161
+ x=mm_to_m ( initial_x) ;
162
+ y=mm_to_m ( initial_y) ;
163
+ theta=degs_to_rads ( initial_theta) ;
125
164
travel=0.0 ;
126
165
delta_x=0.0 ;
127
166
delta_y=0.0 ;
@@ -141,7 +180,7 @@ class Kinematics{
141
180
}
142
181
143
182
float getTheta (){
144
- return rads_to_degs* theta;
183
+ return rads_to_degs ( theta) ;
145
184
}
146
185
147
186
float getTravel (){
@@ -157,7 +196,7 @@ class Kinematics{
157
196
}
158
197
159
198
float getDeltaTheta (){
160
- return rads_to_degs* delta_theta;
199
+ return rads_to_degs ( delta_theta) ;
161
200
}
162
201
163
202
0 commit comments