-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainfile.ino
66 lines (45 loc) · 1.13 KB
/
mainfile.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
#include <Servo.h>
#include <SPI.h>
// This is the main Pixy object
Servo base;
Servo shoulder;
Servo elbow;
float alphaoffset = 10;
float betaoffset = 35;
float thetaoffset = 0;
float alpha, beta, theta, beta_;
float x_target, y_target, z_target;
float x_offset, y_offset, z_offset;
float x, y, z;
float L3_, L3;
float L1 = 148;
float L2 = 160;
void setup() {
base.attach(3, 700, 2250);
shoulder.attach(10, 700, 2250);
elbow.attach(9, 700, 2250);
Serial.begin(9600);
x_offset = 30;
y_offset = 0;
z_offset = 80;
x_target = 0;
y_target = 150;
z_target = 150;
}
void loop() {
x = x_target - x_offset;
y = y_target - y_offset;
z = z_target - z_offset;
L3_ = sqrt(x*x + y*y);
theta = acos(x/L3_);
theta = theta * 180 / 3.1415;
L3 = sqrt(x*x + y*y + z*z);
beta = 3.1415 - acos(((L1*L1 + L2*L2 - L3*L3)/(2 * L1 * L2)));
beta = beta * 180 / 3.1415;
alpha = (acos((L1*L1+L3*L3-L2*L2)/(2*L1*L3)) + asin(z/L3)) *180 / 3.1415;
beta_ = beta - alpha;
base.write(theta + thetaoffset);
shoulder.write(alpha + alphaoffset);
elbow.write(beta_ + betaoffset);
delay(50);
}