1
1
#include " OTOS.h"
2
2
3
+ using namespace Printer ;
4
+
3
5
void OpticalTrackingOdometrySensor::Initialisation ()
4
6
{
5
7
println (" Init QwiicOTOS" );
6
8
7
9
Wire.setPins (SDA, SCL);
8
- // Wire.begin();
9
10
Wire.begin (SDA, SCL, 400000UL );
10
11
11
12
// Normal speed is 100 000
12
13
// With higher speed, instructions on I2C take less time
13
- // Wire.setClock(400000UL);
14
+ // Wire.setClock(400000UL);
14
15
15
16
int retryConnect = 0 ;
16
17
// Attempt to begin the sensor
17
18
isConnected = myOtos.begin ();
18
- while (!isConnected && retryConnect < 3 )
19
+ while (!isConnected && retryConnect < 3 )
19
20
{
20
21
println (" OTOS not connected, check your wiring and I2C address!" );
21
22
delay (1000 );
22
23
isConnected = myOtos.begin ();
23
24
retryConnect++;
24
25
}
25
26
26
- if (isConnected)
27
+ if (isConnected)
27
28
{
28
29
println (" OTOS connected!" );
29
30
@@ -57,8 +58,8 @@ void OpticalTrackingOdometrySensor::Initialisation()
57
58
// multiple speeds to get an average, then set the linear scalar to the
58
59
// inverse of the error. For example, if you move the robot 100 inches and
59
60
// the sensor reports 103 inches, set the linear scalar to 100/103 = 0.971
60
- myOtos.setAngularScalar (0.992 );// 0.992
61
- myOtos.setLinearScalar (1.00 );// 1.035
61
+ myOtos.setAngularScalar (0.992 ); // 0.992
62
+ myOtos.setLinearScalar (1.00 ); // 1.035
62
63
63
64
// Set the desired units for linear and angular measurements. Can be either
64
65
// meters or inches for linear, and radians or degrees for angular. If not
@@ -68,7 +69,7 @@ void OpticalTrackingOdometrySensor::Initialisation()
68
69
myOtos.setLinearUnit (kSfeOtosLinearUnitMeters );
69
70
// myOtos.setLinearUnit(kSfeOtosLinearUnitInches);
70
71
myOtos.setAngularUnit (kSfeOtosAngularUnitRadians ); // /!\ OTOS in radians !
71
- // myOtos.setAngularUnit(kSfeOtosAngularUnitDegrees);
72
+ // myOtos.setAngularUnit(kSfeOtosAngularUnitDegrees);
72
73
73
74
// Assuming you've mounted your sensor to a robot and it's not centered,
74
75
// you can specify the offset for the sensor relative to the center of the
@@ -87,26 +88,26 @@ void OpticalTrackingOdometrySensor::Initialisation()
87
88
// Reset the tracking algorithm - this resets the position to the origin,
88
89
// but can also be used to recover from some rare tracking errors
89
90
myOtos.resetTracking ();
90
-
91
+
91
92
// After resetting the tracking, the OTOS will report that the robot is at
92
93
// the origin. If your robot does not start at the origin, or you have
93
94
// another source of location information (eg. vision odometry), you can set
94
95
// the OTOS location to match and it will continue to track from there.
95
96
sfe_otos_pose2d_t currentPose = {0 , 0 , 0 };
96
97
myOtos.setPosition (currentPose);
97
98
98
- sfeTkError_t error;
99
+ sfTkError_t error;
99
100
sfe_otos_signal_process_config_t config;
100
101
error = myOtos.getSignalProcessConfig (config);
101
102
if (error != 0 )
102
- print (" Error get Signal Process Config : " , (( int )( error)) );
103
+ print (" Error get Signal Process Config : " , error);
103
104
else
104
105
{
105
- // println("Signal Process Config :");
106
- // println("enVar : ", config.enVar);
107
- // println("enRot : ", config.enRot);
108
- // println("enAcc : ", config.enAcc);
109
- // println("enLut : ", config.enLut);
106
+ // println("Signal Process Config :");
107
+ // println("enVar : ", config.enVar);
108
+ // println("enRot : ", config.enRot);
109
+ // println("enAcc : ", config.enAcc);
110
+ // println("enLut : ", config.enLut);
110
111
}
111
112
}
112
113
}
@@ -115,7 +116,7 @@ void OpticalTrackingOdometrySensor::Update()
115
116
{
116
117
if (isConnected)
117
118
{
118
- sfeTkError_t error;
119
+ sfTkError_t error;
119
120
// Get the latest position, which includes the x and y coordinates, plus the
120
121
// heading angle
121
122
// sfe_otos_pose2d_t myPosition;
@@ -137,14 +138,14 @@ void OpticalTrackingOdometrySensor::Update()
137
138
// If Velocity and Acceleration are not needed, use getPosition to decrease blocking time
138
139
// currently blocking time of getPosVelAcc with 400 000 speed : 600µS
139
140
error = myOtos.getPosVelAcc (myPosition, myVelocity, myAcceleration);
140
- position.x = myPosition.x * 1000 ;
141
- position.y = myPosition.y * 1000 ;
141
+ position.x = myPosition.x * 1000 ;
142
+ position.y = myPosition.y * 1000 ;
142
143
position.h = myPosition.h ;
143
- velocity.x = myVelocity.x * 1000 ;
144
- velocity.y = myVelocity.y * 1000 ;
144
+ velocity.x = myVelocity.x * 1000 ;
145
+ velocity.y = myVelocity.y * 1000 ;
145
146
velocity.h = myVelocity.h ;
146
- acceleration.x = myAcceleration.x * 1000 ;
147
- acceleration.y = myAcceleration.y * 1000 ;
147
+ acceleration.x = myAcceleration.x * 1000 ;
148
+ acceleration.y = myAcceleration.y * 1000 ;
148
149
acceleration.h = myAcceleration.h ;
149
150
if (error != 0 )
150
151
print (" Error getPosVelAcc : " , error);
@@ -153,25 +154,25 @@ void OpticalTrackingOdometrySensor::Update()
153
154
154
155
void OpticalTrackingOdometrySensor::HandleCommand (Command cmd)
155
156
{
156
- // if (cmd.cmd == "Otos")
157
+ // if (cmd.cmd == "Otos")
157
158
// {
158
- // Otos:0;0
159
+ // Otos:0;0
159
160
// print("Otos : ", cmd.data[0]);
160
161
// }
161
162
}
162
163
163
- void OpticalTrackingOdometrySensor::PrintCommandHelp ()
164
+ const void OpticalTrackingOdometrySensor::PrintCommandHelp ()
164
165
{
165
166
Printer::println (" OTOS Command Help :" );
166
167
Printer::println (" ! No Command yet !" );
167
- // Printer::println(" > Otos:[int]");
168
- // Printer::println(" [int] ");
169
- // Printer::println();
168
+ // Printer::println(" > Otos:[int]");
169
+ // Printer::println(" [int] ");
170
+ // Printer::println();
170
171
}
171
172
172
173
void OpticalTrackingOdometrySensor::SetPose (float x, float y, float h)
173
174
{
174
- sfeTkError_t error;
175
+ sfTkError_t error;
175
176
// Reset the tracking algorithm - this resets the position to the origin,
176
177
// but can also be used to recover from some rare tracking errors
177
178
myOtos.resetTracking ();
@@ -180,18 +181,18 @@ void OpticalTrackingOdometrySensor::SetPose(float x, float y, float h)
180
181
// the origin. If your robot does not start at the origin, or you have
181
182
// another source of location information (eg. vision odometry), you can set
182
183
// the OTOS location to match and it will continue to track from there.
183
- sfe_otos_pose2d_t currentPose = {x/ 1000 , y/ 1000 , h};
184
-
184
+ sfe_otos_pose2d_t currentPose = {x / 1000 , y / 1000 , h};
185
+
185
186
int retrySetPose = 0 ;
186
187
error = myOtos.setPosition (currentPose);
187
- while (error !=0 && retrySetPose < 3 )
188
+ while (error != 0 && retrySetPose < 3 )
188
189
{
189
190
println (" OTOS Error SetPose : " , error);
190
191
delay (100 );
191
192
error = myOtos.setPosition (currentPose);
192
193
retrySetPose++;
193
194
}
194
- if (error != 0 || retrySetPose >= 3 )
195
+ if (error != 0 || retrySetPose >= 3 )
195
196
{
196
197
// Force position, but will be override when update occurs
197
198
myPosition.x = x;
@@ -203,16 +204,16 @@ void OpticalTrackingOdometrySensor::SetPose(float x, float y, float h)
203
204
204
205
void OpticalTrackingOdometrySensor::Teleplot ()
205
206
{
206
- // teleplot("X", myPosition.x*1000);
207
- // teleplot("Y", myPosition.y*1000);
208
- // teleplot("H", myPosition.h);
207
+ // teleplot("X", myPosition.x*1000);
208
+ // teleplot("Y", myPosition.y*1000);
209
+ // teleplot("H", myPosition.h);
209
210
210
- teleplot (" VX" , myVelocity.x * 1000 );
211
- teleplot (" VY" , myVelocity.y * 1000 );
211
+ teleplot (" VX" , myVelocity.x * 1000 );
212
+ teleplot (" VY" , myVelocity.y * 1000 );
212
213
teleplot (" VH" , myVelocity.h );
213
214
214
- teleplot (" AX" , myAcceleration.x * 1000 );
215
- teleplot (" AY" , myAcceleration.y * 1000 );
215
+ teleplot (" AX" , myAcceleration.x * 1000 );
216
+ teleplot (" AY" , myAcceleration.y * 1000 );
216
217
teleplot (" AH" , myAcceleration.h );
217
218
218
219
/*
0 commit comments