diff --git a/sketch_nov29b.ino b/sketch_nov29b.ino new file mode 100644 index 0000000..277d33a --- /dev/null +++ b/sketch_nov29b.ino @@ -0,0 +1,73 @@ +#include +#include + +Servo s6,s5,s4,s3,s2; +int v6,v5,v4,v3,v2; + +void setup() { + + //s6.attach(6); + s5.attach(5); + s4.attach(4); + s3.attach(3); + // s2.attach(2); + + Serial.begin(9600); + // Setup the lengths and rotation limits for each link + Link base, upperarm, forearm, hand; + + base.init(16, b2a(0), b2a(180.0)); + upperarm.init(74, b2a(0.0), b2a(180.0)); + forearm.init(42, b2a(0.0), b2a(180.0)); + hand.init(40, b2a(0.0), b2a(180.0)); + + InverseK.attach(base, upperarm, forearm, hand); + + float a0, a1, a2, a3; + + if(InverseK.solve(120, 0, 70, a0, a1, a2, a3)) { + Serial.print(a2b(a0)); Serial.print(','); + Serial.print(a2b(a1)); Serial.print(','); + Serial.print(a2b(a2)); Serial.print(','); + Serial.println(a2b(a3)); + } else { + Serial.println("No solution found!"); + } + //s6.write(a0); + s5.write(a2b(a1)); + s4.write(a2b(a2)); + s3.write(a2b(convertServo(a3))); + + + //s3.write(90); + //writeZero(); +} + +void writeZero(){ + s5.write(90); + s4.write(10); + s3.write(convertServo(90)); +} + +void loop() { + // put your main code here, to run repeatedly: + + +} + +float b2a(float b){ + return b / 180.0 * PI - HALF_PI; +} + +// Quick conversion from radians to the Braccio angle system +float a2b(float a) { + return (a + HALF_PI) * 180 / PI; +} + +long convertServo(long l){ + + long ret = map(l, 0, 170 , 180 , 10); + + return ret; + +}