aboutsummaryrefslogtreecommitdiff
path: root/Position/Position.pde
blob: 38967d7b78e68557fc0a3da2cc857358d2e634c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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)));
    
  }*/
}