From 972ba2cb73d52e269a36de1542d15f9cc9dada4f Mon Sep 17 00:00:00 2001 From: MangaValk Date: Mon, 14 Nov 2016 13:07:00 +0100 Subject: [PATCH] Add CustomTimer and separate left/right leg handling Imported from the unarchived 'hexapod' sketch folder. The real date of this version is unknown; file dates were lost in a 2016-11-14 copy. --- .../processing-3d/hexapod/CustomTimer.pde | 19 ++++ .../processing-3d/hexapod/FootClass.pde | 98 ++++++++++++++----- .../processing-3d/hexapod/HexapodClass.pde | 47 +++++---- 3 files changed, 116 insertions(+), 48 deletions(-) create mode 100644 2012-simulation/processing-3d/hexapod/CustomTimer.pde diff --git a/2012-simulation/processing-3d/hexapod/CustomTimer.pde b/2012-simulation/processing-3d/hexapod/CustomTimer.pde new file mode 100644 index 0000000..b911496 --- /dev/null +++ b/2012-simulation/processing-3d/hexapod/CustomTimer.pde @@ -0,0 +1,19 @@ +class CustomTimer +{ + int time; + boolean start=true; + public boolean delay(int delay) + { + if (start) + { + time = millis(); + start = false; + } + if (millis() - time >= delay) + { + start = true; + return true; + } else + return false; + } +} diff --git a/2012-simulation/processing-3d/hexapod/FootClass.pde b/2012-simulation/processing-3d/hexapod/FootClass.pde index 5aa9321..8c5e0fe 100644 --- a/2012-simulation/processing-3d/hexapod/FootClass.pde +++ b/2012-simulation/processing-3d/hexapod/FootClass.pde @@ -188,40 +188,84 @@ class Foot Z = -1 * (Z - TranslateZ); } - double a = (90 - degrees((float)(O1()))); - double b = (180 - degrees((float)(T1()))); - double c = degrees((float)(T3())); + if (leftLegorRight) + { // right + double a = (90 - degrees((float)(O1()))); + double b = (180 - degrees((float)(T1()))); + double c = degrees((float)(T3())); - if ((a >= 15) & (a <= 165) - & (b >= 15) & (b <= 165) - & (c >= 15) & (c <= 165)) - { - error = false; + if ((a >= 15) & (a <= 165) + & (b >= 15) & (b <= 165) + & (c >= 15) & (c <= 165)) + { + error = false; - O1 = a; - O2 = b; - O3 = c; + O1 = a; + O2 = b; + O3 = c; - double d = sin((float)(b*(PI/180))); - if ( d != 0 ) - X2 = d * l1; - else - X2 = 0; + double d = sin((float)(b*(PI/180))); + if ( d != 0 ) + X2 = d * l1; + else + X2 = 0; - d = cos((float)(b*(PI/180))); - if ( d != 0 ) - Y2 = d * l1; - else - Y2 = 0; + d = cos((float)(b*(PI/180))); + if ( d != 0 ) + Y2 = d * l1; + else + Y2 = 0; - d = sin((float)((a-90)*(PI/180))); - if ( d != 0 ) - Z2 = d * abs((float)(X2)); - else - Z2 = 0; + d = sin((float)((a-90)*(PI/180))); + if ( d != 0 ) + Z2 = d * abs((float)(X2)); + else + Z2 = 0; + } else + { + error = true; + } } else { - error = true; + double a = (90 - degrees((float)(O1()))); + double b = degrees((float)(T1())); + double c = 180 - degrees((float)(T3())); + + if ((a >= 15) & (a <= 165) + & (b >= 15) & (b <= 165) + & (c >= 15) & (c <= 165)) + { + error = false; + + O1 = a; + O2 = b; + O3 = c; + + a = (90 - degrees((float)(O1()))); + b = (180 - degrees((float)(T1()))); + c = degrees((float)(T3())); + + double d = sin((float)(b*(PI/180))); + if ( d != 0 ) + X2 = d * l1; + else + X2 = 0; + + d = cos((float)(b*(PI/180))); + if ( d != 0 ) + Y2 = d * l1; + else + Y2 = 0; + + d = sin((float)((a-90)*(PI/180))); + if ( d != 0 ) + Z2 = d * abs((float)(X2)); + else + Z2 = 0; + } else + { + error = true; + } } } } diff --git a/2012-simulation/processing-3d/hexapod/HexapodClass.pde b/2012-simulation/processing-3d/hexapod/HexapodClass.pde index f22a215..36ead3f 100644 --- a/2012-simulation/processing-3d/hexapod/HexapodClass.pde +++ b/2012-simulation/processing-3d/hexapod/HexapodClass.pde @@ -12,6 +12,22 @@ Foot foot6 = new Foot(); // 10 // 10 +// LAYOUT HARDWARE +// _U_ +// 0==/ \==3 +// >***< +// 1===|---|===4 +// >***< +// 2==\___/==5 + +// LAYOUT SOFTWARE? +// _U_ +// 1==/ \==6 +// >***< +// 2===|---|===5 +// >***< +// 3==\___/==4 + PVector point1 = new PVector(4.75, 0, 10); PVector point2 = new PVector(7, 0, 0); PVector point3 = new PVector(4.75, 0, -10); @@ -161,26 +177,6 @@ void Vertex(double x, double y, double z) vertex((float)x, (float)y, (float)z); } -class CustomTimer -{ - int time; - boolean start=true; - public boolean delay(int delay) - { - if (start) - { - time = millis(); - start = false; - } - if (millis() - time >= delay) - { - start = true; - return true; - } else - return false; - } -} - void DrawFeet() { foot1.Translate(point1); @@ -215,13 +211,22 @@ void RobotWalk() animationRepeat = true; animationSpeed = 20; + /* foot1.SetFootCoordinates(Animation(walk1, 6, 2)); // BULLSHIT BUG foot1.SetFootCoordinates(Animation(walk1, 6, 2)); foot2.SetFootCoordinates(Animation(walk1, 6, 3)); foot3.SetFootCoordinates(Animation(walk1, 6, 4));// foot4.SetFootCoordinates(Animation(walk1, 6, 1));// foot5.SetFootCoordinates(Animation(walk1, 6, 0)); - foot6.SetFootCoordinates(Animation(walk1, 6, 5)); + foot6.SetFootCoordinates(Animation(walk1, 6, 5));*/ + foot1.SetFootCoordinates(Animation(walk1, 6, 1)); // BULLSHIT BUG + foot1.SetFootCoordinates(Animation(walk1, 6, 1)); + foot2.SetFootCoordinates(Animation(walk1, 6, 3)); + foot3.SetFootCoordinates(Animation(walk1, 6, 5));// + + foot4.SetFootCoordinates(Animation(walk1, 6, 0));// + foot5.SetFootCoordinates(Animation(walk1, 6, 2)); + foot6.SetFootCoordinates(Animation(walk1, 6, 4)); } }