Filtrage des erreurs de lecture (position à 32769) et ajout de la documentation

This commit is contained in:
Samuel 2025-08-10 17:29:53 +02:00
parent fb94f7981b
commit 6d42195b45
3 changed files with 105 additions and 79 deletions

View File

@ -0,0 +1,9 @@
Fonctionnement en mode Servo "Classique"
========================================
En faisant varier la consigne de position de -512 à 5120, nous observons des butées logicielles à 0 et à 4093. Notons aussi que la position renvoyée peut reboucler à 0 comme indiqué sur le graphique. Nous avons globalement le fonctionnement d'un servomoteur classique, sauf que nous avons le retour de position et que nous pouvons régler également la vitesse.
Voici le graphique obtenu à partir du comportement du servomoteur.
![](/doc/ModeServo_normal.png)

BIN
doc/ModeServo_normal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -1,85 +1,23 @@
#include <Arduino.h> #include <Arduino.h>
#include "SCServo.h" #include "SCServo.h"
#define SERVO_ID 1
SMS_STS sms_sts; SMS_STS sms_sts;
void test_ping(); enum etat_t{
void lire_tous_les_registres(int servo_id); EN_COURS,
TERMINE,
ECHEC
char registre_description[70][100]={
"Version majeure du firmware",
"Version mineure du firmware",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
}; };
void gestion_servo(void);
enum etat_t test_ping(void);
enum etat_t configure_servomoteur(void);
enum etat_t mouvement_servomoteur(void);
void lire_tous_les_registres(int servo_id);
// the setup routine runs once when you press reset: // the setup routine runs once when you press reset:
void setup() { void setup() {
// initialize the digital pin as an output. // initialize the digital pin as an output.
@ -93,12 +31,51 @@ void setup() {
// the loop routine runs over and over again forever: // the loop routine runs over and over again forever:
void loop() { void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
test_ping(); gestion_servo();
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
test_ping(); gestion_servo();
} }
void test_ping() void gestion_servo(){
static enum {
PING_SERVO,
CONFIG_SERVO,
MOUVEMENT_SERVO
} etat_gestion_servo = PING_SERVO;
enum etat_t etat_action;
switch(etat_gestion_servo){
case PING_SERVO:
if(test_ping() == TERMINE){
etat_gestion_servo = CONFIG_SERVO;
}
break;
case CONFIG_SERVO:
etat_action = configure_servomoteur();
if(etat_action == TERMINE){
etat_gestion_servo = MOUVEMENT_SERVO;
}
if(etat_action == ECHEC){
etat_gestion_servo = PING_SERVO;
}
break;
case MOUVEMENT_SERVO:
etat_action = mouvement_servomoteur();
if(etat_action == ECHEC){
etat_gestion_servo = PING_SERVO;
}
break;
}
}
enum etat_t test_ping()
{ {
int ID = sms_sts.Ping(1); int ID = sms_sts.Ping(1);
static int found = 0; static int found = 0;
@ -108,6 +85,7 @@ void test_ping()
if(found == 0){ if(found == 0){
found = 1; found = 1;
lire_tous_les_registres(ID); lire_tous_les_registres(ID);
return TERMINE;
} }
delay(100); delay(100);
}else{ }else{
@ -115,6 +93,45 @@ void test_ping()
found = 0; found = 0;
delay(2000); delay(2000);
} }
return EN_COURS;
}
enum etat_t configure_servomoteur(){
sms_sts.ServoMode(SERVO_ID);
return TERMINE;
}
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;
int position_lue;
char tampon[200];
/// Toutes les 500 ms
if(millis() - temps_pas_ms > 500 ){
temps_pas_ms = millis();
// On avance ou recule de d'un pas
position += pas_servo;
// si position > 5000 ou position < 0
if(position > 5000 || position < 0){
pas_servo = -pas_servo;
}
sms_sts.WritePosEx(SERVO_ID, position, 4800);
}
if(millis() - temps_aff_ms > 10 ){
temps_aff_ms = millis();
sprintf(tampon, ">pos_consigne:%d\n", position);
Serial.print(tampon);
position_lue = sms_sts.ReadPos(SERVO_ID);
if(position_lue != 32769){
sprintf(tampon, ">pos_actuelle:%d\n", position_lue);
}
Serial.print(tampon);
}
return EN_COURS;
} }
int lire_registre(int servo_id, int registre_adresse){ int lire_registre(int servo_id, int registre_adresse){
@ -124,7 +141,7 @@ int lire_registre(int servo_id, int registre_adresse){
void lire_tous_les_registres(int servo_id){ void lire_tous_les_registres(int servo_id){
char message[200]=""; char message[200]="";
for (int i=0; i<0x46; i++){ for (int i=0; i<0x46; i++){
sprintf(message, "registre 0x%x: %d\t\t%s\n", i, lire_registre(servo_id, i), registre_description[i]); sprintf(message, "registre 0x%x: %d\n", i, lire_registre(servo_id, i));
Serial.print(message); Serial.print(message);
} }