Aller au contenu


Photo
- - - - -

Robot explorateur


43 réponses à ce sujet

#41 Mike118

Mike118

    Staff Robot Maker

  • Administrateur
  • PipPipPipPipPip
  • 9 934 messages
  • Gender:Male
  • Location:Anglet
  • Interests:Robotique, Entrepreneuriat, Innovation, Programmation, Résolution de problème, Recherche de solutions, Mécanique, Electronique, Créer, Concevoir

Posté 11 décembre 2019 - 05:24

dernière astuce, si jamais ton neutre sur ton joystick et pas bien centré ou autre au lieu de faire un simple map tu peux découper en 3 morceaux du genre :
si ta valeur est entre 0 et neutreMin  => map( valeur , 0, neutreMin, -255, 0 ); 
si ta valeur est entre netureMin et neutreMax => 0 
si ta valeur est entre neutreMax et 1023 => map( valeur , neutreMax, 1023, 0, 255); 


Si mon commentaire vous a plus laissez nous un avis  !  :thank_you:

Nouveau sur Robot Maker ? 

Jetez un oeil aux blogs, aux tutoriels, aux ouvrages, au robotscope  aux articles,  à la boutique  et aux différents services disponible !
En attendant qu'une bibliothèque de fichiers 3D soit mise en place n'hésitez pas à demander si vous avez besoin du fichier 3D d'un des produits de la boutique... On l'a peut être ! 
Si vous souhaitez un robot pilotable par internet n'hésitez pas à visiter www.vigibot.com et à lire le sous forum dédié à vigibot!

 

Les réalisations de Mike118  

 

 

 


#42 Vinchator

Vinchator

    Habitué

  • Membres
  • PipPip
  • 210 messages
  • Gender:Male
  • Location:Swiss
  • Interests:Bidouillage

Posté 11 décembre 2019 - 05:38

dernière astuce, si jamais ton neutre sur ton joystick et pas bien centré ou autre au lieu de faire un simple map tu peux découper en 3 morceaux du genre :
si ta valeur est entre 0 et neutreMin  => map( valeur , 0, neutreMin, -255, 0 ); 
si ta valeur est entre netureMin et neutreMax => 0 
si ta valeur est entre neutreMax et 1023 => map( valeur , neutreMax, 1023, 0, 255);


Oui effectivement ces joysticks sont jamais vraiment parfaits... merci du tuyau

#43 Vinchator

Vinchator

    Habitué

  • Membres
  • PipPip
  • 210 messages
  • Gender:Male
  • Location:Swiss
  • Interests:Bidouillage

Posté 11 décembre 2019 - 11:29



void drive2WDrobot(int linearspeed, int angularspeed) { // avec linearspeed et angularspeed compris entre -255 et 255
  int rightspeed = constrain(linearspeed - angularspeed, -255, 255); 
  int leftspeed = constrain(linearspeed + angularspeed, -255, 255); 
  driveRightMotor( rightspeed );
  driveLeftMotor( leftspeed );
}


et pour obtenir tes vitesse de consigne linéaire et angulaire tu fais ton map entre de ton entré qui va de 0 et 1023 pour que ça sorte en -255 255 =)

 

 

Linearspeed ca correspond à l'axe vertical de mon joystick et angularspeed à l'axe horizontale pour la direction ?



#44 Vinchator

Vinchator

    Habitué

  • Membres
  • PipPip
  • 210 messages
  • Gender:Male
  • Location:Swiss
  • Interests:Bidouillage

Posté 12 décembre 2019 - 12:46

Voila ce que j'ai écrit et ce que j'ai compris

Je recois par le port série du hc12 les valeur de mon joystick qui sont gaz ( axe verticale ) et direction ( axe horizontale)

Ensuite je map ces deux valeurs de 0,1023 à -255,255 pour obtenir vitesse et angle

int rightspeed = constrain(vitesse - angle, -255, 255); 
int leftspeed = constrain(angle + vitesse, -255, 255); 

Avec ces lignes on les contraint dans l'intervalle qui nous interesse et on obtient les vitesses pour les moteurs gauche et droit et on les utilisent dans sa fonction respective pour chaque moteur...

 

Au final j'ai ce code :

//Code du récepteur  ( Arduino Mega + HC12 + 5x Servo + 1x L298D avec 2 moteurs 12V DC + 1 relai )

#include <SoftwareSerial.h>
#include <Wire.h>
#include <Servo.h>

const int Pwm_Mot1 = 1;
const int Dig1_Mot1 = 2;
const int Dig2_Mot1 = 3;
const int Pwm_Mot2 = 4 ;
const int Dig1_Mot2 = 5;
const int Dig2_Mot2 = 6;
const int Relai = 7;

Servo Rotation_Cam;
Servo Inclinaison_Cam;
Servo Bras1_Pince;
Servo Bras2_Pince;
Servo Serrage_Pince;
              
SoftwareSerial HC12(10, 11);

int Gaz;
int Direction;
int Cam1;
int Cam2;
int Pince1;
int Pince2;
int Pince3;
int Phare;
String input;
int boundLow;
int boundHigh;
const char delimiter = ',';
int leftspeed;
int rightspeed;
int vitesse;
int angle;

void setup() {

pinMode(Pwm_Mot1, OUTPUT);
pinMode(Dig1_Mot1, OUTPUT);
pinMode(Dig2_Mot1, OUTPUT);
pinMode(Pwm_Mot2, OUTPUT);
pinMode(Dig1_Mot2, OUTPUT);
pinMode(Dig2_Mot2, OUTPUT);

Rotation_Cam.attach(8);
Inclinaison_Cam.attach(9);
Bras1_Pince.attach(10);
Bras2_Pince.attach(11);
Serrage_Pince.attach(12);
    
Serial.begin(9600);
HC12.begin(9600);

}

void loop() {

  if(HC12.available())
  {
  input = HC12.readStringUntil('\n');
  if (input.length() > 0)
      {
        Serial.println(input);
       
       boundLow = input.indexOf(delimiter);
        Gaz = input.substring(0, boundLow).toInt();
    
        boundHigh = input.indexOf(delimiter, boundLow+1);
        Direction = input.substring(boundLow+1, boundHigh).toInt();
    
        boundLow = input.indexOf(delimiter, boundHigh+1);
        Cam1 = input.substring(boundHigh+1, boundLow).toInt();

        boundHigh = input.indexOf(delimiter, boundLow+1);
        Cam2 = input.substring(boundLow+1, boundHigh).toInt();

        boundLow = input.indexOf(delimiter, boundHigh+1);
        Cam2 = input.substring(boundHigh+1, boundLow).toInt();

        boundHigh = input.indexOf(delimiter, boundLow+1);
        Pince1 = input.substring(boundLow+1, boundHigh).toInt();

        boundLow = input.indexOf(delimiter, boundHigh+1);
        Pince2 = input.substring(boundHigh+1, boundLow).toInt();

        boundHigh = input.indexOf(delimiter, boundLow+1);
        Pince3 = input.substring(boundLow+1, boundHigh).toInt();
    
        Phare = input.substring(boundHigh+1).toInt();
  
        delay(10); 
  
        }

vitesse=map(Gaz,0,1023,-255,255);
angle=map(Direction,0,1023,-255,255);
rightspeed = constrain(vitesse - angle, -255, 255); 
leftspeed = constrain(angle + vitesse, -255, 255); 

Moteur_Droit();
Moteur_Gauche();
Eclairage();
Bras();
Vision();
 
}}

  
  void Moteur_Droit(){
  if(vitesse > 0 ) {
  digitalWrite(Dig1_Mot1, LOW);
  digitalWrite(Dig2_Mot1, HIGH);
  analogWrite(Pwm_Mot1, rightspeed);  
  } 
  else if(vitesse < 0 ) {
  digitalWrite(Dig1_Mot1, HIGH);
  digitalWrite(Dig2_Mot1, LOW);
  analogWrite(Pwm_Mot1, -rightspeed);
  } 
  else {
  digitalWrite(Dig1_Mot1, LOW);
  digitalWrite(Dig2_Mot1, LOW);
  analogWrite(Pwm_Mot1, 0);
 }   
 }
 
  void Moteur_Gauche(){
  if(vitesse > 0 ) {
  digitalWrite(Dig1_Mot2, LOW);
  digitalWrite(Dig2_Mot2, HIGH);
  analogWrite(Pwm_Mot2, leftspeed);  
  } 
  else if(vitesse < 0 ) {
  digitalWrite(Dig1_Mot2, HIGH);
  digitalWrite(Dig2_Mot2, LOW);
  analogWrite(Pwm_Mot2, -leftspeed);
  } 
  else {
  digitalWrite(Dig1_Mot2, LOW);
  digitalWrite(Dig2_Mot2, LOW);
  analogWrite(Pwm_Mot2, 0);
 }   
 }

 

void Eclairage()
{
if(Phare == 1) {
digitalWrite(Relai, HIGH);
}
else{
digitalWrite(Relai, LOW);
}
}


void Bras()
{
int Angle_Bras1 = map(Pince1, 0, 1023, 10, 180);   
Bras1_Pince.write(Angle_Bras1); 
int Angle_Bras2 = map(Pince2, 0, 1023, 10, 180);   
Bras2_Pince.write(Angle_Bras2); 
int Angle_Bras3 = map(Pince3, 0, 1023, 10, 180);   
Serrage_Pince.write(Angle_Bras1); 
}

void Vision()
{
int Angle_Cam1 = map(Cam1, 0, 1023, 10, 180);   
Rotation_Cam.write(Angle_Cam1); 
int Angle_Cam2 = map(Cam2, 0, 1023, 10, 180);   
Inclinaison_Cam.write(Angle_Cam2); 
}

 





Répondre à ce sujet



  


0 utilisateur(s) li(sen)t ce sujet

0 members, 0 guests, 0 anonymous users