aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeodarZ <neodarz@neodarz-K53SV.com>2015-04-29 23:20:14 +0200
committerNeodarZ <neodarz@neodarz-K53SV.com>2015-04-29 23:20:14 +0200
commit9222bfc8a944a616996e404cb3dfbd29532bd56a (patch)
tree9c35225ee94a56fc7cb35cf1b1d2922b7b2f38a4
parent3c0afb53872c09e8cb2c1e5afb6d6a5184aab0fe (diff)
downloadRobot-Cable-9222bfc8a944a616996e404cb3dfbd29532bd56a.zip
Robot-Cable-9222bfc8a944a616996e404cb3dfbd29532bd56a.tar.xz
Rajout des programme de commande des treuils (Processing) et ceux du fonctionnement des treuils (Arduino)
-rw-r--r--Position/Position.pde203
-rw-r--r--pilotage_moteur_v2/pilotage_moteur_v2.ino140
2 files changed, 343 insertions, 0 deletions
diff --git a/Position/Position.pde b/Position/Position.pde
new file mode 100644
index 0000000..38967d7
--- /dev/null
+++ b/Position/Position.pde
@@ -0,0 +1,203 @@
+// longeur/largeur du tableau. changer a votre convenance ;)
+int Lx=900; //default: 900
+int Ly=600; //default: 600
+
+import processing.serial.*;
+
+Serial monPortamoi;
+Serial monPortamoi2;
+Serial monPortamoi3;
+Serial monPortamoi4;
+
+int x;
+int y;
+int clicX;
+int clicY;
+
+int coeff=10; // <1 multiplie, >1 divise, 1 inchangé.
+
+float l1=0;
+float l2;
+float l3;
+float l4;
+
+
+float savel1=540;
+float savel2=540;
+float savel3=540;
+float savel4=540;
+
+float calcull1;
+float calcull3;
+
+void setup()
+{
+ size(Lx+500,Ly); //taille du tableau. a definir plus haut
+ println(Serial.list());
+ String arduinoPort = Serial.list()[1];
+ //String arduinoPort2 = Serial.list()[0];
+ String arduinoPort3 = Serial.list()[0];
+ //String arduinoPort4 = Serial.list()[1];
+ monPortamoi = new Serial(this, arduinoPort, 9600);
+ //monPortamoi2 = new Serial(this, arduinoPort2, 9600);
+ monPortamoi3 = new Serial(this, arduinoPort3, 9600);
+ //monPortamoi4 = new Serial(this, arduinoPort4, 9600);
+}
+
+
+
+
+void draw()
+{
+ background(0); //fond noir
+ fill(0,0,0); //remplir en noir
+ stroke(0,200,200); //contour bleu
+ rect(Lx,0,200,Ly); //boite
+ rect(Lx,0,200,180); //boite
+ //ellipse(x, height-y, 10,10);
+ ellipse(x, mouseY, 10,10);
+
+ x=mouseX; //x=position x de la souris
+ y=height-mouseY; // y=hauteur-position y de la souris
+ x=constrain(x,0,Lx); //contrainte de la souris. pour pas qu'elle ne se ballade dans les stats
+ //traçage des lignes l1 l2 l3 l4
+ line(0,0,x,height-y);
+ line(Lx,Ly,x,height-y);
+ line(Lx,0,x,height-y);
+ line(0,Ly,x,height-y);
+
+
+
+
+
+texte();
+}
+
+void mouseClicked ()
+{
+ if( mouseX<Lx) // la souris est à gauche du bandeau
+ {
+ calculLongeurs();
+ calculDeplacement();
+
+ savel1=l1;
+ savel2=l2;
+ savel3=l3;
+ savel4=l4;
+
+ clicX=x;
+ clicY=y;
+
+ envoiMessageXbee();
+ }
+}
+
+void texte()
+{
+ fill(255,255,255);
+ //affichage X et Y
+ text("X= "+x, Lx+40,50);
+ text("Y= "+y, Lx+120,50);
+ //affichage
+ text("L1= "+nf(l1,3,2), Lx+40,130);
+ text("L2= "+nf(l2,3,2), Lx+40,140);
+ text("L3= "+nf(l3,3,2), Lx+40,150);
+ text("L4= "+nf(l4,3,2), Lx+40,160);
+
+ //affichage du nom des cables a proximité de ceux ci
+ text("L2", x-100, height-y-100);
+ text("L4", x+100, height-y+100);
+ text("L3", x+100, height-y-100);
+ text("L1", x-100, height-y+100);
+}
+
+void calculLongeurs()
+{
+ l1=sqrt( sq(x) + sq(y) );
+ l2=sqrt( sq(x) + sq(Ly-y) );
+ l3=sqrt( sq(Lx-x) + sq(Ly-y) );
+ l4=sqrt( sq(Lx-x) + sq(y) );
+}
+
+void calculDeplacement()
+{
+ println(coeff);
+ calcull1=(l1-savel1)/coeff;
+ print("l1= ");
+ println(calcull1);
+ calcull3=(l3-savel3)/coeff;
+ print("l3= ");
+ println(calcull3);
+}
+
+
+
+
+void envoiMessageXbee()
+{
+ /*******************MESSAGE TREUIL1*******************************/
+ if (calcull1>0)
+ {
+ monPortamoi.write("cmdH"+int(calcull1)+"\r");
+ print("envoi message : ");
+ println("cmdH"+int(calcull1));
+
+
+ }
+ if (calcull1<0)
+ {
+ monPortamoi.write("cmdT"+int(abs(calcull1))+"\r");
+ print("envoi message : ");
+ println("cmdT"+int(abs(calcull1)));
+
+ }
+ /*******************MESSAGE TREUIL2******************************* /
+ if (calcull2>0)
+ {
+ monPortamoi2.write("cmdH"+int(calcull2)+"\r");
+ print("envoi message : ");
+ println("cmdH"+int(calcull2));
+
+
+ }
+ if (calcull2<0)
+ {
+ monPortamoi2.write("cmdT"+int(abs(calcull2))+"\r");
+ print("envoi message : ");
+ println("cmdT"+int(abs(calcull2)));
+
+ }
+ /*******************MESSAGE TREUIL3*******************************/
+ if (calcull3>0)
+ {
+ monPortamoi3.write("cmdH"+int(calcull3)+"\r");
+ print("envoi message : ");
+ println("cmdH"+int(calcull3));
+
+
+ }
+ if (calcull3<0)
+ {
+ monPortamoi3.write("cmdT"+int(abs(calcull3))+"\r");
+ print("envoi message : ");
+ println("cmdT"+int(abs(calcull3)));
+
+ }
+ /*******************MESSAGE TREUIL4******************************* /
+ if (calcull4>0)
+ {
+ monPortamoi4.write("cmdH"+int(calcull4)+"\r");
+ print("envoi message : ");
+ println("cmdH"+int(calcull4));
+
+
+ }
+ if (calcull4<0)
+ {
+ monPortamoi4.write("cmdT"+int(abs(calcull4))+"\r");
+ print("envoi message : ");
+ println("cmdT"+int(abs(calcull4)));
+
+ }*/
+}
+
diff --git a/pilotage_moteur_v2/pilotage_moteur_v2.ino b/pilotage_moteur_v2/pilotage_moteur_v2.ino
new file mode 100644
index 0000000..2910422
--- /dev/null
+++ b/pilotage_moteur_v2/pilotage_moteur_v2.ino
@@ -0,0 +1,140 @@
+
+
+String chaine_nbr = ""; // valeur numérique
+String chaine_cmd = ""; // valeur commande
+
+int delaylegnth = 4; //durée du delai.
+
+void setup()
+{
+ //establish motor direction toggle pins
+ pinMode(12, OUTPUT); //CH A -- HIGH = forwards and LOW = backwards???
+ pinMode(13, OUTPUT); //CH B -- HIGH = forwards and LOW = backwards???
+
+ //establish motor brake pins //etablir les pin du frein du moteur
+ pinMode(9, OUTPUT); //brake (disable) CH A
+ pinMode(8, OUTPUT); //brake (disable) CH B
+
+ Serial.begin(9600);
+}
+
+void loop()
+{
+ while (Serial.available() > 0) // si buffer liaison serie non vide // quand on reçoit data
+ {
+ int inChar = Serial.read(); //lecture des octets rentrants
+ if (isDigit(inChar))
+ {
+ // convert the incoming byte to a char and add it to the string: //convertir les octets rentrant en nombre et les ajoute a la chaine de charactere.
+ chaine_nbr += (char)inChar;
+ }
+ //if (!isDigit(inChar)&&(inChar != 0x0D)&&(inChar != 0x0A)) // si octet PAS nbr ET octet PAS 0x0D (cr) ET octet PAS 0x0A (nl)
+ if (!isDigit(inChar)&&(inChar != 0x0D)&&(inChar != 0x0A))
+ {
+ chaine_cmd += (char)inChar; // valeur commande
+ }
+ // if you get a newline, print the string,
+ // then the string's value:
+ if (inChar == '\r')
+ {
+ Serial.print("Nom commande : ");
+ Serial.print(chaine_cmd);
+ Serial.print(" Valeur nombre : ");
+ Serial.println(chaine_nbr.toInt()); // valeur après conversion en entier
+
+
+ if (chaine_cmd=="cmdH") //commande pour avancer
+ {
+ for (int cpt=0; cpt<chaine_nbr.toInt(); cpt++)
+ {
+ actionA(); //effectuer A
+ Serial.println("actionA 4pas");
+ }
+ }
+ if (chaine_cmd=="cmdT") //commande pour reculer
+ {
+ for (int cpt=0; cpt<chaine_nbr.toInt(); cpt++)
+ {
+ actionB(); //effectuer B
+ Serial.println("actionB 4pas");
+ }
+ }
+
+ // effacement des chaines nbr et cmd
+ chaine_nbr = "";
+ chaine_cmd = "";
+ } // fin si fin de ligne
+
+ } // fin while
+} // fin loop
+
+
+/////////////////////////////////
+
+void actionA()
+{
+ digitalWrite(9, LOW); //ENABLE CH A
+ digitalWrite(8, HIGH); //DISABLE CH B
+ digitalWrite(12, HIGH); //Sets direction of CH A
+ analogWrite(3, 128); //Moves CH A /Entre 0 et 255
+
+ delay(delaylegnth);
+
+ digitalWrite(9, HIGH); //DISABLE CH A
+ digitalWrite(8, LOW); //ENABLE CH B
+ digitalWrite(13, LOW); //Sets direction of CH B
+ analogWrite(11, 128); //Moves CH B /Entre 0 et 255
+
+ delay(delaylegnth);
+
+ digitalWrite(9, LOW); //ENABLE CH A
+ digitalWrite(8, HIGH); //DISABLE CH B
+ digitalWrite(12, LOW); //Sets direction of CH A
+ analogWrite(3, 128); //Moves CH A /Entre 0 et 255
+
+ delay(delaylegnth);
+
+ digitalWrite(9, HIGH); //DISABLE CH A
+ digitalWrite(8, LOW); //ENABLE CH B
+ digitalWrite(13, HIGH); //Sets direction of CH B
+ analogWrite(11, 128); //Moves CH B /Entre 0 et 255
+
+ delay(delaylegnth);
+}
+
+void actionB()
+{
+
+
+ digitalWrite(9, LOW); //ENABLE CH A
+ digitalWrite(8, HIGH); //DISABLE CH B
+ digitalWrite(12, LOW); //Sets direction of CH A
+ analogWrite(3, 128); //Moves CH A /Entre 0 et 255
+
+ delay(delaylegnth);
+
+ digitalWrite(9, HIGH); //DISABLE CH A
+ digitalWrite(8, LOW); //ENABLE CH B
+ digitalWrite(13, LOW); //Sets direction of CH B
+ analogWrite(11, 128); //Moves CH B /Entre 0 et 255
+
+ delay(delaylegnth);
+
+ digitalWrite(9, LOW); //ENABLE CH A
+ digitalWrite(8, HIGH); //DISABLE CH B
+ digitalWrite(12, HIGH); //Sets direction of CH A
+ analogWrite(3, 128); //Moves CH A /Entre 0 et 255
+
+ delay(delaylegnth);
+
+ digitalWrite(9, HIGH); //DISABLE CH A
+ digitalWrite(8, LOW); //ENABLE CH B
+ digitalWrite(13, HIGH); //Sets direction of CH B
+ analogWrite(11, 128); //Moves CH B /coefficient Entre 0 et 255 de le tension envoyée.
+
+ delay(delaylegnth);
+}
+
+
+
+