-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathexample_2DOFMoveUpAndDown.ino
80 lines (67 loc) · 2.07 KB
/
example_2DOFMoveUpAndDown.ino
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
/********************************************************
* FABRIK2D 2DOF example
* Creating the FABRIK object and moving the end effector up and down.
* You can use whichever unit you want for coordinates, lengths and tolerances as long as you are consistent.
* Default unit is millimeters.
********************************************************/
#include <FABRIK2D.h>
int lengths[] = {225, 150}; // 2DOF arm where shoulder to elbow is 225mm and elbow to end effector is 150mm.
Fabrik2D fabrik2D(3, lengths); // This arm has 3 joints; one in the origin, the elbow and the end effector.
float y = 0;
int toggle_y = 0;
void setup() {
Serial.begin(9600);
Serial.print("ang0");
Serial.print("\t");
Serial.print("ang1");
Serial.print("\t");
Serial.print("x0");
Serial.print("\t");
Serial.print("y0");
Serial.print("\t");
Serial.print("x1");
Serial.print("\t");
Serial.print("y1");
Serial.print("\t");
Serial.print("x2");
Serial.print("\t");
Serial.println("y2");
// Set tolerance to 0.5mm. If reachable, the end effector will approach
// the target with this tolerance
fabrik2D.setTolerance(0.5);
}
void loop() {
// Move from -30 to 40 in the y axis
if (y < 10) {
toggle_y = 0;
y = 10;
} else if (y > 100) {
toggle_y = 1;
y = 100;
}
// Solve inverse kinematics given the coordinates x and y and the list of lengths for the arm.
fabrik2D.solve(200,y,lengths);
// Angles are printed in degrees.
// The function calls below shows how easy it is to get the results from the inverse kinematics solution.
Serial.print(fabrik2D.getAngle(0)* 57296 / 1000);
Serial.print("\t");
Serial.print(fabrik2D.getAngle(1)* 57296 / 1000);
Serial.print("\t");
Serial.print(fabrik2D.getX(0));
Serial.print("\t");
Serial.print(fabrik2D.getY(0));
Serial.print("\t");
Serial.print(fabrik2D.getX(1));
Serial.print("\t");
Serial.print(fabrik2D.getY(1));
Serial.print("\t");
Serial.print(fabrik2D.getX(2));
Serial.print("\t");
Serial.println(fabrik2D.getY(2));
if (toggle_y == 0) {
y++;
} else {
y--;
}
delay(50);
}