-
Notifications
You must be signed in to change notification settings - Fork 0
/
try1.ino
124 lines (82 loc) · 2.17 KB
/
try1.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <HardwareSerial.h>
#include <AccelStepper.h>
HardwareSerial SerialPort(2);
String msg = "0";
#define dirPin1 14
#define stepPin1 12
#define dirPin2 4
#define stepPin2 2
#define dirPin3 15
#define stepPin3 13
#define motorInterfaceType 1
AccelStepper stepper1(motorInterfaceType, stepPin1, dirPin1);
AccelStepper stepper2(motorInterfaceType, stepPin2, dirPin2);
AccelStepper stepper3(motorInterfaceType, stepPin3, dirPin3);
String number, x, y, z,velx ,vely ,velz;
void velocity(float vf, float vr, float vl) {
/* Serial.println(vf);
Serial.println(vr);
Serial.println(vl);*/
//Serial.println("Vel pub");
stepper1.setSpeed(vf);
stepper1.runSpeed();
stepper2.setSpeed(vr);
stepper2.runSpeed();
stepper3.setSpeed(-vl);
stepper3.runSpeed();
}
void setup() {
// initialize digital pin LED_BUILTIN as an output.
//Serial.begin(9600);
SerialPort.begin(115200, SERIAL_8N1, 16, 17);
stepper1.setMaxSpeed(500);
stepper2.setMaxSpeed(500);
stepper3.setMaxSpeed(500);
}
// the loop function runs over and over again forever
void loop() {
//Serial.println(SerialPort.available());
if (SerialPort.available()) {
number = SerialPort.readStringUntil('\n');
char buf[40];
//Serial.println(number);
number.toCharArray(buf, 30);
int i = 0;
x = "";
y = "";
z = "";
while (i < 30) {
if (buf[i] == 'x') {
i = i + 2;
while (buf[i] != ' ') {
x = x + buf[i];
i = i + 1;
}
}
else if (buf[i] == 'y') {
i = i + 2;
while (buf[i] != ' ') {
y = y + buf[i];
i = i + 1;
}
}
else if (buf[i] == 'z') {
i = i + 2;
while (buf[i] != ' ') {
z = z + buf[i];
i = i + 1;
}
}
i += 1 ;
}
//velocity(x.toFloat(), y.toFloat(), z.toFloat());
}
else
{
//Serial.println("Not connected");
velx=x;
vely=y;
velz=z;
velocity(velx.toFloat(), vely.toFloat(), velz.toFloat());
}
}