@@ -29,7 +29,6 @@ uint8_t label;
29
29
uint8_t control_type;
30
30
uint8_t msg_size;
31
31
uint8_t ack_required=0 ;
32
- int ack_counter=0 ;
33
32
bool ack_check=false ;
34
33
uint8_t ack_code=0 ;
35
34
@@ -169,25 +168,24 @@ void loop(){
169
168
alvik.disablePositionControl ();
170
169
alvik.move (value);
171
170
ack_required=MOVEMENT_MOVE;
172
- ack_counter=5 ;
173
171
ack_check=true ;
174
172
break ;
175
173
176
174
case ' Z' :
177
175
packeter.unpacketC3F (code, x, y, theta);
178
176
alvik.resetPose (x, y, theta);
179
177
break ;
178
+
180
179
case ' X' :
181
180
packeter.unpacketC1B (code, ack_code);
182
- Serial.print (" Ack received " );
183
- Serial.println (ack_code);
184
181
if (ack_code == ' K' ) {
185
182
ack_check = false ;
186
183
}
187
184
break ;
188
185
}
189
186
}
190
187
188
+ // sensors publish
191
189
if (millis ()-tsensor>10 ){
192
190
tsensor=millis ();
193
191
switch (sensor_id){
@@ -223,6 +221,7 @@ void loop(){
223
221
}
224
222
}
225
223
224
+ // motors update & publish
226
225
if (millis ()-tmotor>20 ){
227
226
tmotor=millis ();
228
227
alvik.updateMotors ();
@@ -239,58 +238,27 @@ void loop(){
239
238
// pose
240
239
msg_size = packeter.packetC3F (' z' , alvik.getX (), alvik.getY (), alvik.getTheta ());
241
240
alvik.serial ->write (packeter.msg , msg_size);
242
- /*
243
- if (ack_required!=0){
244
- //if (alvik.getKinematicsMovement()!=MOVEMENT_DISABLED){
245
- if (alvik.isTargetReached()){
246
- Serial.print(alvik.isTargetReached());
247
- Serial.print("\t");
248
-
249
-
250
- if (ack_required==MOVEMENT_ROTATE){
251
- msg_size = packeter.packetC1B('x', 'R');
252
- Serial.println("R");
253
- }
254
- if (ack_required==MOVEMENT_MOVE){
255
- msg_size = packeter.packetC1B('x', 'M');
256
- Serial.println("M");
257
- }
258
- alvik.serial->write(packeter.msg, msg_size);
259
- //alvik.disableKinematicsMovement();
260
- ack_required=0;
261
- }
262
241
263
- }
264
- */
265
242
}
266
243
267
- if (millis ()-tack>100 ){
268
- tack=millis ();
269
- msg_size = packeter.packetC1B (' x' , 0 );
270
-
271
- if (ack_check&&alvik.isTargetReached ()){
272
- if (ack_required==MOVEMENT_ROTATE){
244
+ // acknowledge
245
+ if (millis ()-tack > 100 ){
246
+ tack = millis ();
247
+ if (ack_check && alvik.isTargetReached ()){
248
+ if (ack_required == MOVEMENT_ROTATE){
273
249
msg_size = packeter.packetC1B (' x' , ' R' );
274
- // ack_counter--;
275
- Serial.println (" R" );
276
250
}
277
- if (ack_required== MOVEMENT_MOVE){
251
+ if (ack_required == MOVEMENT_MOVE){
278
252
msg_size = packeter.packetC1B (' x' , ' M' );
279
- // ack_counter--;
280
- Serial.println (" M" );
281
253
}
282
- // ack_check=false;
283
254
}
284
-
285
-
286
- if (ack_counter<=0 ){
287
- ack_counter=0 ;
288
- ack_required=MOVEMENT_DISABLED;
255
+ else {
256
+ msg_size = packeter.packetC1B (' x' , 0 );
289
257
}
290
-
291
258
alvik.serial ->write (packeter.msg , msg_size);
292
259
}
293
260
261
+ // imu update
294
262
if (millis ()-timu>10 ){
295
263
timu=millis ();
296
264
alvik.updateImu ();
0 commit comments