@@ -29,7 +29,6 @@ uint8_t label;
2929uint8_t control_type;
3030uint8_t msg_size;
3131uint8_t ack_required=0 ;
32- int ack_counter=0 ;
3332bool ack_check=false ;
3433uint8_t ack_code=0 ;
3534
@@ -169,25 +168,24 @@ void loop(){
169168 alvik.disablePositionControl ();
170169 alvik.move (value);
171170 ack_required=MOVEMENT_MOVE;
172- ack_counter=5 ;
173171 ack_check=true ;
174172 break ;
175173
176174 case ' Z' :
177175 packeter.unpacketC3F (code, x, y, theta);
178176 alvik.resetPose (x, y, theta);
179177 break ;
178+
180179 case ' X' :
181180 packeter.unpacketC1B (code, ack_code);
182- Serial.print (" Ack received " );
183- Serial.println (ack_code);
184181 if (ack_code == ' K' ) {
185182 ack_check = false ;
186183 }
187184 break ;
188185 }
189186 }
190187
188+ // sensors publish
191189 if (millis ()-tsensor>10 ){
192190 tsensor=millis ();
193191 switch (sensor_id){
@@ -223,6 +221,7 @@ void loop(){
223221 }
224222 }
225223
224+ // motors update & publish
226225 if (millis ()-tmotor>20 ){
227226 tmotor=millis ();
228227 alvik.updateMotors ();
@@ -239,58 +238,27 @@ void loop(){
239238 // pose
240239 msg_size = packeter.packetC3F (' z' , alvik.getX (), alvik.getY (), alvik.getTheta ());
241240 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- }
262241
263- }
264- */
265242 }
266243
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){
273249 msg_size = packeter.packetC1B (' x' , ' R' );
274- // ack_counter--;
275- Serial.println (" R" );
276250 }
277- if (ack_required== MOVEMENT_MOVE){
251+ if (ack_required == MOVEMENT_MOVE){
278252 msg_size = packeter.packetC1B (' x' , ' M' );
279- // ack_counter--;
280- Serial.println (" M" );
281253 }
282- // ack_check=false;
283254 }
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 );
289257 }
290-
291258 alvik.serial ->write (packeter.msg , msg_size);
292259 }
293260
261+ // imu update
294262 if (millis ()-timu>10 ){
295263 timu=millis ();
296264 alvik.updateImu ();
0 commit comments