Skip to content

Commit e1eeb34

Browse files
committed
Create CoordsControl.ino
1 parent f24a388 commit e1eeb34

File tree

1 file changed

+134
-0
lines changed

1 file changed

+134
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#include <MycobotBasic.h>
2+
#include <ParameterList.h>
3+
4+
5+
MycobotBasic myCobot;
6+
7+
8+
bool Servo_state = 1;
9+
10+
int power_pin = 2;
11+
int open_pin = 5;
12+
int out_state = 1;
13+
14+
Coords pos_init_1 = {155.10, -55.10, 90.10, -179.10, 0.10, -90.10};
15+
Coords data1;
16+
17+
Angles angles_0 = {0, 0, 0, 0, 0, 0};
18+
Angles angles_1 = {-90.01, -45, -90.30, 45.09, 90.70, 90.63};
19+
Angles angles_2 = {-0, -45, -90.30, 45.09, 90.70, 90.63};
20+
Angles angles_3 = {-0, -45, -90.30, 45.09, 90.70, 90.63};
21+
void move_coords(int dir = 0, int num = 0);
22+
23+
void setup() {
24+
myCobot.setup();
25+
myCobot.powerOn();
26+
27+
pinMode(power_pin, OUTPUT);
28+
pinMode(open_pin, OUTPUT);
29+
30+
set_pump(1);
31+
32+
myCobot.setLEDRGB(0, 0, 255);
33+
delay(100);
34+
myCobot.writeAngles(angles_0,30);
35+
delay(3000);
36+
}
37+
38+
void loop() {
39+
// put your main code here, to run repeatedly:
40+
M5.update(); // need to call update()
41+
M5.Lcd.setCursor(0,0);
42+
int j = 0;
43+
if (M5.BtnA.wasReleased()) {
44+
reless();
45+
}
46+
if (M5.BtnB.wasReleased()) {
47+
myCobot.writeCoords(pos_init_1,30);
48+
}
49+
if (M5.BtnC.wasReleased()) {
50+
data1 = pos_init_1;
51+
delay(50);
52+
move_coords(0, 10);
53+
delay(2000);
54+
move_coords(0, -10);
55+
delay(2000);
56+
move_coords(1, 10);
57+
delay(2000);
58+
move_coords(1, -10);
59+
delay(2000);
60+
move_coords(2, 10);
61+
delay(2000);
62+
move_coords(2, -10);
63+
delay(2000);
64+
}
65+
}
66+
67+
void reless()
68+
{
69+
for(int i = 1; i<7; i++){
70+
myCobot.setServoData(i, 40, !Servo_state);
71+
delay(30);
72+
}
73+
Servo_state = !Servo_state;
74+
}
75+
76+
Angles read_Angles()
77+
{
78+
Angles data2;
79+
data2 = myCobot.getAngles();
80+
delay(50);
81+
for(int i = 0; i<6; i++){
82+
Serial.print(data2[i]);
83+
Serial.print(", ");
84+
}
85+
Serial.println();
86+
return data2;
87+
}
88+
89+
Coords read_pos()
90+
{
91+
Coords data1;
92+
data1 = myCobot.getCoords();
93+
delay(50);
94+
for(int i = 0; i<6; i++){
95+
Serial.print(data1[i]);
96+
Serial.print(", ");
97+
}
98+
Serial.println();
99+
return data1;
100+
}
101+
102+
void move_coords(int dir, int num)
103+
{
104+
if (num > 0){
105+
for(int i = 0; i<num; i++){
106+
myCobot.writeCoords(data1,15);
107+
for(int i=0; i<6; i++){
108+
Serial.print(data1[i]);
109+
Serial.print(", ");
110+
}
111+
Serial.println("");
112+
data1[dir] += 10;
113+
delay(50);
114+
}
115+
}else{
116+
num = 0-num;
117+
for(int i = 0; i<num; i++){
118+
myCobot.writeCoords(data1,15);
119+
for(int i=0; i<6; i++){
120+
Serial.print(data1[i]);
121+
Serial.print(", ");
122+
}
123+
Serial.println("");
124+
data1[dir] -= 10;
125+
delay(50);
126+
}
127+
}
128+
}
129+
130+
131+
void set_pump(int out_state){
132+
digitalWrite(power_pin, out_state);
133+
digitalWrite(open_pin, out_state);
134+
}

0 commit comments

Comments
 (0)