Mode 3: Pas à pas

This commit is contained in:
Samuel 2026-06-11 08:14:43 +02:00
parent 13098e9112
commit 9366379d23
2 changed files with 15 additions and 8 deletions

View File

@ -81,11 +81,18 @@ int SCSerial::writeSCS(unsigned char *nDat, int nLen)
if(nDat==NULL){
return 0;
}
for(int i=0; i<nLen; i++){
Serial.print(nDat[i], DEC);
Serial.print(" ");
}
Serial.println();
return pSerial->write(nDat, nLen);
}
int SCSerial::writeSCS(unsigned char bDat)
{
Serial.print(bDat, DEC);Serial.println();
return pSerial->write(&bDat, 1);
}

View File

@ -49,7 +49,7 @@ void gestion_servo(){
switch(etat_gestion_servo){
case PING_SERVO:
if(test_ping() == TERMINE){
etat_gestion_servo = CONFIG_SERVO;
// etat_gestion_servo = CONFIG_SERVO;
}
break;
@ -101,10 +101,10 @@ enum etat_t configure_servomoteur(){
sms_sts.writeByte(SERVO_ID, SMS_STS_MODE, 3);
sms_sts.writeByte(SERVO_ID, 0x09, 0); // Butée min à 0
sms_sts.writeByte(SERVO_ID, 0x0A, 0); // Butée min à 0
sms_sts.writeByte(SERVO_ID, 4095 & 0xFF, 0); // Buté max à 4095
sms_sts.writeByte(SERVO_ID, (4095>>8) & 0xFF, 0); // Buté max à 4095
sms_sts.writeByte(SERVO_ID, 0x0B, 0); // Buté max à 0, désactivation de la butée
sms_sts.writeByte(SERVO_ID, 0x0C, 0); // Buté max à 0, désactivation de la butée
sms_sts.writeByte(SERVO_ID, 0x1E, 1);
sms_sts.writeByte(SERVO_ID, 0x1E, 3);
sms_sts.writeByte(SERVO_ID, 0x12, 0x6C); // Registre de "Phase", valeur par défaut 108 (0x6C)
@ -115,17 +115,17 @@ enum etat_t mouvement_servomoteur(){
static int position=0;
static int temps_pas_ms = 0;
static int temps_aff_ms = 0;
static int pas_servo = 512;
static int pas_servo = 2048;
int position_lue;
char tampon[200];
/// Toutes les 500 ms
if(millis() - temps_pas_ms > 500 ){
if(millis() - temps_pas_ms > 5000 ){
temps_pas_ms = millis();
// On avance ou recule de d'un pas
position += pas_servo;
sms_sts.WritePosEx(SERVO_ID, pas_servo, 4800);
sms_sts.WritePosEx(SERVO_ID, pas_servo, 2000);
// si position > 5000 ou position < 0
if(position > 40100 || position < 0){
if(position > 35100 || position < 0){
pas_servo = -pas_servo;
}