void checkServo( void ) { const int MAX_PULSE = 1900 ; const int MIN_PULSE = 1000 ; const int BASE_PULSE = 50 ; const int NB_STEPS = 500 ; const unsigned char SERVO[] = "0" ; unsigned char trama[100] ; int deltaPulse ; unsigned char mvtStatus ; unsigned char *ind ; int pulse ; int refPulse ; int digitPulse ; static bool notInit = false ; refPulse = ( MIN_PULSE + MAX_PULSE ) / 2; deltaPulse = BASE_PULSE ; for ( int ic=0 ; ic= MAX_PULSE ) deltaPulse = -BASE_PULSE ; refPulse = refPulse + deltaPulse ; //codify reference ind = trama ; *ind = '#' ; ind++ ; *ind = SERVO[0] ; ind++ ; if ( SERVO[1] != '\0' ) { *ind = SERVO[1] ; ind++ ; } *ind = ' ' ; ind++ ; //codify pulse *ind = 'P' ; ind++ ; pulse = refPulse ; digitPulse = pulse / 1000 ; if ( digitPulse > 0 ) { *ind = '0' + (char)digitPulse ; ind++ ; } pulse = pulse - (digitPulse*1000) ; digitPulse = pulse / 100 ; *ind = '0' + (char)digitPulse ; *ind++ ; pulse = pulse - (digitPulse*100) ; digitPulse = pulse / 10 ; *ind = '0' + (char)digitPulse ; *ind++ ; pulse = pulse - (digitPulse*10) ; digitPulse = pulse ; *ind = '0' + (char)digitPulse ; ind++ ; *ind = ' ' ; ind++ ; //codify speed if ( notInit ) { *ind = 'S' ; ind++ ; *ind = '5' ; ind++ ; *ind = '0' ; ind++ ; *ind = '0' ; ind++ ; *ind = '0' ; ind++ ; } else { notInit = true ; } //*ind = '\0' ; //must finish with NULL //cout << "\nSSC32COMMANDFRAME<" << trama << "> " << endl ; *ind = '\r' ; ///BEHAVIOUR IS FINE WITH SPEED=5000 AND USLEEP=2X100000 AND WITHOUT QUERY usleep( 100000 ) ; usleep( 100000 ) ; rs232Port->send( trama, (ind - trama + 1) ) ; /**SAME CODE WITH QUERY (next cycle) : THE SERVO IS SLOWER AND STOPS FROM TIME TO TIME DURING A HALF SECOND : WHY ??? PROOF USED SERVOS HITECH HS-985MG AND HITECH HS-85MG **/ do { rs232Port->send( (unsigned char *)"Q\r", 2 ) ; //mvt query rs232Port->receive( &mvtStatus, sizeof(mvtStatus) ) ; //usleep( 2000 ) ; //cout << '.' ; } while ( mvtStatus != '.' ) ; //=='+' while mvt is not ended /**/ } }