Skip to content

Commit

Permalink
Logging ne se fait qu'en mode DEBUG
Browse files Browse the repository at this point in the history
* ajout d'une direction de compilation DEBUG
* variations autour du logging
* nettoyage des PI existants en M_PI
* renommage de log en logging pour ne pas écraser <math.h>

Signed-off-by: Yoan Blanc <[email protected]>
  • Loading branch information
greut committed Dec 2, 2016
1 parent ddf3d20 commit 9dad2ce
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 67 deletions.
77 changes: 33 additions & 44 deletions src/programme/cinematique.h
Original file line number Diff line number Diff line change
@@ -1,61 +1,44 @@

bool isInside(float x, float y){
if( x<MIN_X+COR_X ){
Serial.print("OUT X");
Serial.print(x);
Serial.print("<");
Serial.print(MIN_X+COR_X);
Serial.println();
if( x < MIN_X+COR_X ){
LOG("OUT X", x, "<", MIN_X + COR_X);
return false;
}
if( x>MAX_X+COR_X ){
Serial.print("OUT X");
Serial.print(x);
Serial.print(">");
Serial.print(MAX_X+COR_X);
Serial.println();
if( x > MAX_X+COR_X ){
LOG("OUT X", x, ">", MAX_X + COR_X);
return false;
}
if( y<MIN_Y + COR_Y ){
Serial.print("OUT Y");
Serial.print(y);
Serial.print("<");
Serial.print(MIN_Y);
Serial.println();
if( y < MIN_Y+COR_Y ){
LOG("OUT Y", y, "<", MIN_Y + COR_Y);
return false;
}
if( y>MAX_Y + COR_Y){
Serial.print("OUT Y");
Serial.print(y);
Serial.print(">");
Serial.print(MAX_Y+ COR_Y);
Serial.println();
if( y > MAX_Y + COR_Y){
LOG("OUT Y", y, ">", MAX_Y + COR_Y);
return false;
}
return true;

if ( (x>MIN_X)&&(x<MAX_X)&&(y>MIN_Y)&&(y<MAX_Y) ) return true;
else return false;
}

bool toAngle(float x, float y){
// Merci Julien Marchand et François Tièche !!!
float r, t, alpha, beta, gamma, halfPerimeter, angleR1, angleR2;
float r, t, alpha, beta, gamma, halfPerimeter, angleR1, angleR2;
bool lefty = false; // pas utile avec la config mécanique choisie

old1 = angle1;
old2 = angle2;

x+=COR_X;y+=COR_Y; // Application correctifs translation
// Application correctifs translation
x+=COR_X;
y+=COR_Y;

r = sqrt(x*x+y*y);
r = sqrt(x*x + y*y);
alpha = atan2(y, x);
halfPerimeter = (lg1+lg2+r)/2;
halfPerimeter = (lg1+lg2+r) / 2.;

// sin(beta/2)
t = (halfPerimeter-lg1)*(halfPerimeter-r)/(lg1*r);
if (t < 0.0) {
Serial.println("INACESSIBLE");
LOG("INACCESSIBLE\n");

return false;
}
Expand All @@ -65,7 +48,7 @@ bool toAngle(float x, float y){
// sin(gamma/2)
t = (halfPerimeter-lg1)*(halfPerimeter-lg2)/(lg1*lg2);
if (t < 0.0) {
Serial.println("INACCESSIBLE");
LOG("INACCESSIBLE\n");
return false;
}

Expand All @@ -78,15 +61,21 @@ bool toAngle(float x, float y){
if (isInside(x,y)) {
angle1 = angleR1 * 180 / M_PI;
angle2 = angleR2 * 180 / M_PI;
angle1+=COR_S1;angle2+=COR_S2; // Application correctifs angles
if (angle2<ANGLE_MIN) angle2 = ANGLE_MIN; // Evite les collisionsq
}
else {
Serial.println("HORS DE LA FEUILLE");
return false;
// Application correctifs angles
angle1 += COR_S1;
angle2 += COR_S2;

if (angle2<ANGLE_MIN) {
// Evite les collisions
angle2 = ANGLE_MIN;
}

LOG(x, y);
return true;
}
if (debug) log(x,y);
return true;

LOG("HORS DE LA FEUILLE\n");
return false;
}

void moveServos()
Expand Down Expand Up @@ -152,8 +141,8 @@ void initServos()
s1.write(angle1);
s2.write(angle2);
delay(20);
if (debug) Serial.print(".");
LOG(".");
}
if (debug) Serial.println("INIT");
LOG("INIT\n");
}

40 changes: 31 additions & 9 deletions src/programme/declarations.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,37 @@ float par = M_PI/180; // angle en radians entre deux calculs de points (1°)
bool microsec = true; // Mode précis (0.1°) si true
bool debug = true; // Affiche les déplacements dans le moniteur série

void log(char msg[], float t, float x, float y){
Serial.print(msg);Serial.print(" - t:");Serial.print(t);Serial.print(":(");Serial.print(x);
Serial.print(","); Serial.print(y);Serial.println(")");
}
// DEBOGGAGE

void log(float x, float y){
Serial.print("angles: S1:");Serial.print(angle1);Serial.print(" S2:");Serial.println(angle2);
Serial.print(" (x,y) : (");Serial.print(x);Serial.print(",");Serial.print(y);Serial.println(")\n");
}
#define DEBUG

#ifdef DEBUG
#define LOG(...) logging(__VA_ARGS__)

// Variations autour du logging.
void logging(char const msg[], float t, float x, float y){
Serial.print(msg);Serial.print(" - t:");Serial.print(t);Serial.print(":(");Serial.print(x);Serial.print(","); Serial.print(y);Serial.println(")");
Serial.println();
}

void logging(float x, float y){
Serial.print("angles: S1:");Serial.print(angle1);Serial.print(" S2:");Serial.println(angle2);
Serial.print(" (x,y) : (");Serial.print(x);Serial.print(",");Serial.print(y);Serial.println(")");
Serial.println();
}

void logging(char const msg[], float x, char const op[], float y) {
Serial.print("info: ");Serial.print(msg);Serial.print(x);Serial.print(op);Serial.print(y);Serial.println();
Serial.println();
}

void logging(char const msg[]) {
Serial.print(msg);
}

#else
#define LOG
#endif

void lectureCorrectif(){
delay(500);
Expand All @@ -58,4 +80,4 @@ void lectureCorrectif(){
Serial.print("), Cor en degrés : (");Serial.print(COR_S1);Serial.print(",");Serial.print(COR_S2); Serial.print(")");
// Serial.println("ok");Serial.println("ok");Serial.println("ok");Serial.println("ok");Serial.println("ok");Serial.println("ok");
}

28 changes: 14 additions & 14 deletions src/programme/dessins.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ void etoile(float cx, float cy, float r) // étoile à 5 branches
{
float x,y;
float r1=r, r2=r*3/5, d=r;
for (float t = 0; t<6*PI; t+=par) {
for (float t = 0; t<6*M_PI; t+=par) {
x = cx + (r1-r2)*cos(t) + d*cos((r1-r2)/r2 * t);
y = cy + (r1-r2)*sin(t) - d*sin((r1-r2)/r2 * t);
toAngle(x,y);
moveServos();
if (debug) log("HYPO", t, x, y);
LOG("HYPO", t, x, y);
}
}

Expand All @@ -21,12 +21,12 @@ void fleur(float cx, float cy, float rTotal, float k) // rosace
float rCircleOut=rTotal/(k+1.0);
float rCircleIn=rCircleOut*k;
float x,y;
for (float t = 0; t<2*PI; t+=par) {
for (float t = 0; t<2*M_PI; t+=par) {
x = cx+(rCircleIn + rCircleOut)*cos(t) - rCircleOut*cos((rCircleIn/rCircleOut + 1)* t);
y = cy + (rCircleIn + rCircleOut)*sin(t) - rCircleOut*sin((rCircleIn/rCircleOut + 1)*t);
toAngle(x,y);
moveServos();
if (debug) log("EPI", t, x, y);
LOG("EPI", t, x, y);
}
}

Expand All @@ -39,12 +39,12 @@ void coeur(float cx, float cy, float r)
float x,y;
float taille=50;
cy=cy+2.0*r*1.5/5.0;
for (float t = 0; t<2*PI; t+=par) {
for (float t = 0; t<2*M_PI; t+=par) {
x = cx + r*(sin(t)*sin(t)*sin(t));
y = cy + r*cos(t) - r*(cos(t)*cos(t)*cos(t)*cos(t));
toAngle(x,y);
moveServos();
if (debug) log("COEUR", t, x, y);
LOG("COEUR", t, x, y);
}
}

Expand All @@ -53,12 +53,12 @@ void coeur() { coeur(0, 130, 40); }
void cercle(float cx, float cy, float r)
{
float x,y;
for (float t = 0; t<2*PI; t+=par) {
for (float t = 0; t<2*M_PI; t+=par) {
x = r * cos(t) + cx;
y = r * sin(t) + cy;
toAngle(x,y);
moveServos();
if (debug) log("CERCLE", t, x, y);
LOG("CERCLE", t, x, y);
}
}

Expand All @@ -76,7 +76,7 @@ void spirale(float cx, float cy, float cr, float pas)
moveServos();
cr-=ppd;
if (cr<1) break;
if (debug) log("SPIRALE", t, x, y);
LOG("SPIRALE", t, x, y);
}
}
}
Expand All @@ -96,7 +96,7 @@ void droite(float x1, float y1, float x2, float y2){
moveServos();
x = x + dx;
y = y + dy;
if (debug) log("DROITE", i, x, y);
LOG("DROITE", i, x, y);
}
}

Expand Down Expand Up @@ -142,22 +142,22 @@ void dessineListe() {
y = (int)pgm_read_word(liste+i+1/100);
toAngle(x, y);
moveServos();
if (debug) log("LISTE", 0, x, y);
LOG("LISTE", 0, x, y);
}
}

void mire(){
float x,y;
float cx=0, cy=lg1-20, r=lg2;
// arc
for (float t = -PI/8; t<PI/8; t+=par) {
for (float t = -M_PI/8; t<M_PI/8; t+=par) {
x = r * cos(t) + cx;
y = r * sin(t) + cy;
toAngle(x,y);
moveServos();
if (debug) log("CALIBRAGE", t, x, y);
LOG("CALIBRAGE", t, x, y);
}
// retour et segment

}

0 comments on commit 9dad2ce

Please sign in to comment.