Actionneur: I2C (non testé) + nouvelle butée ascenseur

This commit is contained in:
Samuel 2025-05-25 13:59:01 +02:00
parent b405fbdb76
commit 75ea97fdd5
2 changed files with 104 additions and 63 deletions

View File

@ -39,6 +39,8 @@ struct position_t{
uint position;
} cible_haute, cible_basse, actuelle;
enum etat_action_t Actionneur_deplacement(void);
enum etat_action_t Actionneur_prise_initiale(void);
enum etat_action_t Actionneur_empile(void);
void setup()
@ -228,38 +230,31 @@ void loop()
case 2:
// Position de déplacement
// Fourche levée pour ne pas géner les capteurs
Servo_set(FOURCHE_LEVEE);
// Ascenseur en bas
Ascenseur_descend();
// Pinces internes fermées
Servo_set(DOIGT_PINCE_DROIT_FERME);
Servo_set(DOIGT_PINCE_GAUCHE_FERME);
// Aimant rentrés
Servo_set(AIMANT_PINCE_DROIT_LACHE);
Servo_set(AIMANT_PINCE_GAUCHE_LACHE);
// Translateur à l'arrière
Translateur_recule();
I2C_memory[I2C_DCE_REALISE] = 2;
if(Actionneur_deplacement() == ACTION_TERMINEE){
I2C_memory[I2C_DCE_REALISE] = I2C_memory[I2C_CDE_DEMANDE];
}
break;
case 3:
// Prise initiale
// Fourche en position de prise
Servo_set(FOURCHE_PRISE);
// Ascenseur en bas
Ascenseur_descend();
// Pinces internes fermées
Servo_set(DOIGT_PINCE_DROIT_FERME);
Servo_set(DOIGT_PINCE_GAUCHE_FERME);
// Aimant rentrés
Servo_set(AIMANT_PINCE_DROIT_TIENT);
Servo_set(AIMANT_PINCE_GAUCHE_TIENT);
// Translateur à l'arrière
Translateur_recule();
I2C_memory[I2C_DCE_REALISE] = 3;
if(Actionneur_prise_initiale() == ACTION_TERMINEE){
I2C_memory[I2C_DCE_REALISE] = I2C_memory[I2C_CDE_DEMANDE];
}
break;
case 4:
// Position de transport
// Utile ? - n'est-ce pas la position après la prise initiale ?
break;
case 5:
// Empile
if(Actionneur_empile() == ACTION_TERMINEE){
I2C_memory[I2C_DCE_REALISE] = I2C_memory[I2C_CDE_DEMANDE];
}
break;
}
}
@ -269,6 +264,27 @@ void loop()
// get incoming byte:
int inByte = 0;
inByte = Serial.read();
if(inByte == '?'){
// Affiche le menu
Serial.println("d: Ascenseur step down");
Serial.println("u: Ascenseur step up");
Serial.println("m: Ascenseur monte");
Serial.println("l: Ascenseur descend");
Serial.println("a: Translateur avance");
Serial.println("z: Translateur recule");
Serial.println("w: Doigt pince ouvre");
Serial.println("x: Doigt pince ferme");
Serial.println("1: Reglage servo 8");
Serial.println("2: Reglage servo 9");
Serial.println("3: Reglage servo fourche (5)");
Serial.println("v: Cycle ascenseur");
Serial.println("c: Cycle translateur");
Serial.println("h: Actionneur, position de déplacement");
Serial.println("j: Actionneur, prise initiale");
Serial.println("k: Actionneur, empile");
}
if(inByte == 'd'){
Ascenseur_step_down();
}
@ -284,15 +300,15 @@ void loop()
if(inByte == 'a'){
Translateur_avance();
}
if(inByte == 'z'){
Translateur_recule();
}
if(inByte == 'w'){
Servo_set(DOIGT_PINCE_GAUCHE_OUVRE);
}
if(inByte == 'x'){
Servo_set(DOIGT_PINCE_GAUCHE_FERME);
}
if(inByte == 'z'){
Translateur_recule();
}
if(inByte == '1'){
reglage_servo(8);
}
@ -302,9 +318,21 @@ void loop()
if(inByte == '3'){
reglage_servo(5);
}
if(inByte == 'u'){
if(inByte == 'h'){
while(Actionneur_deplacement() == ACTION_EN_COURS);
}
if(inByte == 'j'){
while(Actionneur_prise_initiale() == ACTION_EN_COURS);
}
if(inByte == 'k'){
while(Actionneur_empile() == ACTION_EN_COURS);
}
/*
if(inByte == 'u'){
while(Actionneur_deplacement() == ACTION_EN_COURS);
while(Actionneur_prise_initiale() == ACTION_EN_COURS);
while(Actionneur_empile() == ACTION_EN_COURS);
}*/
if(inByte == 'v'){
Ascenseur_cycle();
}
@ -385,44 +413,33 @@ void Servo_set(int servo, int position){
}
}
enum etat_action_t Actionneur_deplacement(void){
Servo_set(FOURCHE_LEVEE);
// Ascenseur en bas
Ascenseur_descend();
// Pinces internes fermées
Servo_set(DOIGT_PINCE_DROIT_FERME);
Servo_set(DOIGT_PINCE_GAUCHE_FERME);
// Aimant rentrés
Servo_set(AIMANT_PINCE_DROIT_LACHE);
Servo_set(AIMANT_PINCE_GAUCHE_LACHE);
// Translateur à l'arrière
Translateur_recule();
enum etat_action_t Actionneur_empile(){
return ACTION_TERMINEE;
}
enum etat_action_t Actionneur_prise_initiale(void){
static enum etat_actionneur_t{
ACTIONNEUR_DEPLACEMENT,
ACTIONNEUR_PRISE_EXTERNE,
ACTIONNEUR_DEPILE,
ACTIONNEUR_PRISE_INTERNE_1,
ACTIONNEUR_PRISE_INTERNE_2,
ACTIONNEUR_RECULE_PRISE_INTERNE_1,
ACTIONNEUR_RECULE_PRISE_INTERNE_2,
ACTIONNEUR_LEVE,
ACTIONNEUR_AVANCE_PRISE_INTERNE,
ACTIONNEUR_DEPOSE_PRISE_INTERNE,
ACTIONNEUR_RANGE_TRANSLATEUR,
ACTIONNEUR_DESCEND
} etat_actionneur=ACTIONNEUR_DEPLACEMENT;
ACTIONNEUR_RECULE_PRISE_INTERNE_2
} etat_actionneur=ACTIONNEUR_DEPILE;
switch(etat_actionneur){
case ACTIONNEUR_DEPLACEMENT:
Servo_set(FOURCHE_TRANSPORT);
Translateur_recule();
Servo_set(DOIGT_PINCE_GAUCHE_FERME);
Servo_set(DOIGT_PINCE_DROIT_FERME);
Servo_set(AIMANT_PINCE_DROIT_LACHE);
Servo_set(AIMANT_PINCE_GAUCHE_LACHE);
delay(5000);
etat_actionneur = ACTIONNEUR_PRISE_EXTERNE;
break;
case ACTIONNEUR_PRISE_EXTERNE:
Servo_set(FOURCHE_PRISE);
Servo_set(AIMANT_PINCE_DROIT_LACHE);
Servo_set(AIMANT_PINCE_GAUCHE_LACHE);
// Attente avance
delay(2000);
etat_actionneur = ACTIONNEUR_DEPILE;
break;
case ACTIONNEUR_DEPILE:
Servo_set(FOURCHE_LEVEE);
etat_actionneur = ACTIONNEUR_PRISE_INTERNE_1;
@ -457,13 +474,36 @@ enum etat_action_t Actionneur_empile(){
case ACTIONNEUR_RECULE_PRISE_INTERNE_2:
Serial.println("ACTIONNEUR_RECULE_PRISE_INTERNE_2");
if(Translateur_etat() == ACTION_TERMINEE){
etat_actionneur = ACTIONNEUR_LEVE;
Ascenseur_monte();
Servo_set(FOURCHE_TRANSPORT);
etat_actionneur=ACTIONNEUR_DEPILE;
return ACTION_TERMINEE;
}
break;
}
Ascenseur_gestion();
return ACTION_EN_COURS;
}
enum etat_action_t Actionneur_empile(){
static enum etat_actionneur_t{
ACTIONNEUR_LEVE,
ACTIONNEUR_LEVE_1,
ACTIONNEUR_AVANCE_PRISE_INTERNE,
ACTIONNEUR_DEPOSE_PRISE_INTERNE,
ACTIONNEUR_RANGE_TRANSLATEUR,
ACTIONNEUR_DESCEND
} etat_actionneur=ACTIONNEUR_LEVE;
switch(etat_actionneur){
case ACTIONNEUR_LEVE:
Serial.println("ACTIONNEUR_LEVE");
etat_actionneur = ACTIONNEUR_LEVE_1;
Ascenseur_monte();
break;
case ACTIONNEUR_LEVE_1:
Serial.println("ACTIONNEUR_LEVE_1");
if(Ascenseur_get_etat() == ACTION_TERMINEE){
etat_actionneur = ACTIONNEUR_AVANCE_PRISE_INTERNE;
Translateur_avance();
@ -503,8 +543,7 @@ enum etat_action_t Actionneur_empile(){
case ACTIONNEUR_DESCEND:
Serial.println("ACTIONNEUR_DESCEND");
if(Ascenseur_get_etat() == ACTION_TERMINEE){
etat_actionneur = ACTIONNEUR_DEPLACEMENT;
Servo_set(FOURCHE_TRANSPORT);
etat_actionneur = ACTIONNEUR_LEVE;
return ACTION_TERMINEE;
}
break;

View File

@ -1,3 +1,5 @@
#include <Wire.h>
#define TAILLE_MEMOIRE_I2C 256
#define TAILLE_MESSAGE_ENVOI_MAX 32
byte memoire_I2C[TAILLE_MEMOIRE_I2C];