- Robot Maker
- → Contenu de huntor
Contenu de huntor
Il y a 4 élément(s) pour huntor (recherche limitée depuis 17-juin 13)
Par type de contenu
Voir pour ce membre
#47428 VBnette
Posté par huntor sur 09 août 2012 - 03:07 dans Robots roulants, chars à chenilles et autres machines sur roues
#47423 VBnette
Posté par huntor sur 09 août 2012 - 01:56 dans Robots roulants, chars à chenilles et autres machines sur roues
//#include <SabertoothSimplified.h> //SabertoothSimplified ST(Serial1); //Created Objet sabertooth using serial1 char commande[40]; int gSpeed,dSpeed; int gSens, dSens; boolean allData; int indice=0; int mode=0; char c; /* Protocol de communication : Bit de start 'S' + Choix du moteur 'G'ou'D' + sens '-' pour marche arrière ou rien pour marche avant + vitesse du moteur en % + bit de fin 'E' Exemple = "SG67D-56E" Moteur gauche à 67% en marche avant et Moteur droit à 56% en marche arrière */ void setup() { Serial.begin(9600);// port série de communication pc//Arduino //Serial1.begin(38400); // This is the baud rate (SERIAL1) you chose with the sabertooth's DIP switches. } void loop() { if (Serial.available())// si réception de donnée { // read the incoming byte: c = Serial.read(); commande[indice++]=c;// incrémentation du buffer // say what you got: // Serial.print("I received: "); //Serial.println(c); if(c=='E')//Réception du bit de fin { allData=true; } } if(allData && indice) { for(int i=0; i<indice; i++)// analyse du buffer { switch (commande[i]) { case 'S': Serial.println("Reception des donnees"); break; case 'G': mode=1; break; case 'D': mode=2; break; default: break; } if(mode==1)//Réception des données du moteur gauche { //Serial.println("mode1"); if(commande[i]=='-')// caractère '-' pour indiquer la marche arrière { gSens=2; }else gSens=1; if (commande[i] >= '0' && commande[i] <= '9') { gSpeed = gSpeed * 10 + (commande[i]-'0');// "(commande[i]-'0')" converti le Char en Int } } if(mode==2)//Réception des données du moteur droit { //Serial.println("mode2"); if(commande[i]=='-')// caractère '-' pour indiquer la marche arrière { dSens=2; }else dSens=1; if (commande[i] >= '0' && commande[i] <= '9') { dSpeed = dSpeed * 10 + (commande[i]-'0');// "(commande[i]-'0')" converti le Char en Int } } }//fin analyse //ST.motor(gSens, gSpeed); Serial.print("Moteur gauche : "); if(gSens==1)Serial.print("Marche avant "); else if(gSens==2) Serial.print("Marche arriere "); Serial.print(gSpeed,DEC); Serial.println (" %"); //ST.motor(dSens, dSpeed); Serial.print("Moteur droit : "); if(dSens==1)Serial.print("Marche avant "); else if(dSens==2) Serial.print("Marche arriere "); Serial.print(dSpeed,DEC); Serial.println (" %"); gSpeed=0; dSpeed=0; indice=0; allData=false; } }
Si tu ne comprend pas quelque chose n’hésite pas à demander. Après je ne connais pas la librairie que tu utilise pour commander tes moteurs, j'ai donc mis en commentaire cette partie.
#47417 VBnette
Posté par huntor sur 09 août 2012 - 10:02 dans Robots roulants, chars à chenilles et autres machines sur roues
Apres si ça ne marche pas, affiche la chaîne de caractère que tu reçoit pour vérifier qu'elle est bonne.
#include <SabertoothSimplified.h> SabertoothSimplified ST(Serial1); //Created Objet sabertooth using serial1 /** * Command Line Interface for Arduino * * Julien Holtzer for www.pobot.org * * 18 mars 2009, late in the night */ // numerical value to be decoded after specific commands int value = 0; // where we currently are in the sequence construction or decoding int indice = 0; // the sequence of characters where is stored what the user wants char commande[40]; // reduce the length to save memory (if necessary) int sensg=0; int sensd=0; int tempg; int tempd; /** * */ void setup() { Serial.begin(9600); Serial1.begin(38400); // This is the baud rate (SERIAL1) you chose with the sabertooth's DIP switches. } /** * */ void loop() { // Start a new reception, reinit the browser index of the array indice = 0; // Fill-in the sequence of chars with all received characters while (Serial.available()) { commande[indice++] = Serial.read(); } // End the array with a specific character (E=End) // (means that you can't choose 'E' as a user meaning command commande[indice] = 'E'; // Don't continue the loop if no command (adapt to your own code) if (indice == 0) return; // DEBUG Display that a new sequence has been found //Serial.print("> Received command, length="); //Serial.println(indice); // Start parsing the sequence array indice = 0; while (commande[indice] != 'E') { // Reinit the numerical value value = 0; // switch (commande[indice]) { case 'S': Serial.println("> Start command."); break; case 'G': // Continue to the next char (could contain the numerical value indice++; if(commande[indice]=='-') { sensg=2; indice++; }else sensg=1; while (commande[indice] >= 48 && commande[indice] <= 57) { value = value * 10 + (commande[indice]-48); // next digit indice++; } // Back if no more digit to be added to numerical value indice--; // Serial.print("sensg= "); // Serial.println(sensg); tempg=value; ST.motor(sensg, tempg); Serial.print("> servo gauche : "); if(sensg==1)Serial.print("Marche avant "); else if(sensg==2) Serial.print("Marche arriere "); Serial.print(tempg,DEC); Serial.println (" %"); break; case 'D': // Continue to the next char (could contain the numerical value indice++; if(commande[indice]=='-') { sensd=2; indice++; }else sensd=1; while (commande[indice] >= 48 && commande[indice] <= 57) { value = value * 10 + (commande[indice]-48); // next digit indice++; } // Back if no more digit to be added to numerical value indice--; //Serial.print("sensd= "); // Serial.println(sensd); tempd=value; ST.motor(sensd, tempd); Serial.print("> servo droit : "); if(sensd==1)Serial.print("Marche avant "); else if(sensd==2) Serial.print("Marche arriere "); Serial.print(tempd,DEC); Serial.println (" %"); break; default: //Serial.print("> unrecognized command : "); //Serial.println(commande[indice]); break; } indice++; } }
#47410 VBnette
Posté par huntor sur 09 août 2012 - 08:37 dans Robots roulants, chars à chenilles et autres machines sur roues
Juste en regardant vite fait le code on peut voir:
// End the array with a specific character (E=End) // (means that you can't choose 'E' as a user meaning command commande[indice] = 'E';
Donc si tu n'as pas le caractère 'E' à la fin de ta chaîne de caractère le programme risque de ne pas marcher.
- Robot Maker
- → Contenu de huntor
- Privacy Policy