aboutsummaryrefslogtreecommitdiff
path: root/Position
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 /Position
parent3c0afb53872c09e8cb2c1e5afb6d6a5184aab0fe (diff)
downloadRobot-Cable-9222bfc8a944a616996e404cb3dfbd29532bd56a.tar.xz
Robot-Cable-9222bfc8a944a616996e404cb3dfbd29532bd56a.zip
Rajout des programme de commande des treuils (Processing) et ceux du fonctionnement des treuils (Arduino)
Diffstat (limited to 'Position')
-rw-r--r--Position/Position.pde203
1 files changed, 203 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)));
+
+ }*/
+}
+