Skip to content

Commit 3d6c2c4

Browse files
committed
updata change pid
1 parent c344ac1 commit 3d6c2c4

File tree

2 files changed

+110
-52
lines changed

2 files changed

+110
-52
lines changed

Arduino/MycobotBasic/examples/change-PID/change-PID.ino

Lines changed: 110 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,71 +6,129 @@
66

77
MycobotBasic myCobot;
88
int baundrate = 1000000;
9+
#define GREY 0x5AEB
910

1011
void setup() {
1112
myCobot.setup();
1213
myCobot.powerOn();
1314
Serial.begin(9600);
1415
delay(200);
16+
info();
17+
}
18+
void info(){
19+
M5.Lcd.clear(BLACK);
20+
M5.Lcd.setTextColor(BLACK);
21+
M5.Lcd.setTextColor(RED);
22+
M5.Lcd.setTextSize(3);
23+
M5.Lcd.setCursor(0, 10);
24+
M5.Lcd.printf("myCobot");
25+
M5.Lcd.setCursor(0, 40);
26+
M5.Lcd.drawFastHLine(0,70,320,GREY);
27+
M5.Lcd.setTextSize(3);
28+
M5.Lcd.println("Basic set PID");
29+
M5.Lcd.setTextSize(2);
30+
M5.Lcd.setTextColor(WHITE);
31+
M5.Lcd.setCursor(0, 100);
32+
M5.Lcd.println("Press A - Mode 1");
33+
M5.Lcd.println();
34+
M5.Lcd.println("Press B - Mode 2");
35+
M5.Lcd.println();
36+
M5.Lcd.println("Press C - READ PID");
1537
}
16-
1738
void loop() {
1839
M5.update();
1940
if (M5.BtnA.wasReleased()) {
20-
int P,I,D;
21-
for(int i = 1; i <7 ; i++)
22-
{
23-
if(i < 4){
24-
P = 5;
25-
I = 0;
26-
D = 15;
27-
}else{
28-
P = 8;
29-
I = 0;
30-
D = 24;
31-
}
32-
myCobot.setServoData(i, 21, P);//P
33-
delay(50);
34-
myCobot.setServoData(i, 22, D);//D
35-
delay(50);
36-
myCobot.setServoData(i, 23, I);//I
37-
delay(50);
38-
Serial.print("servo:");
39-
Serial.print(i);
40-
Serial.println(" CHANGE PID to Mode 1");
41-
}
41+
change_mode1();
42+
delay(3000);
43+
info();
4244
}else if (M5.BtnB.wasReleased()) {
43-
int P,I,D;
44-
P = 10;
45-
I = 1;
46-
D = 0;
47-
for(int i = 1; i <7 ; i++){
48-
myCobot.setServoData(i, 21, P);//P
49-
delay(50);
50-
myCobot.setServoData(i, 22, D);//D
51-
delay(50);
52-
myCobot.setServoData(i, 23, I);//I
53-
delay(50);
54-
Serial.print("servo:");
55-
Serial.print(i);
56-
Serial.println("CHANGE PID to Mode 2");
57-
}
45+
change_mode2();
46+
delay(3000);
47+
info();
5848
}
5949
else if (M5.BtnC.wasReleased()) {
60-
for(int i =1; i <7; i++)
61-
{
62-
Serial.print("servo: ");
63-
Serial.print(i);
64-
Serial.print(" P: ");
65-
Serial.print(myCobot.getServoData(i, 21));//P
66-
delay(50);
67-
Serial.print(" D: ");
68-
Serial.print(myCobot.getServoData(i, 22));//D
69-
delay(50);
70-
Serial.print(" I: ");
71-
Serial.print(myCobot .getServoData(i, 23));//I
72-
delay(50);
73-
Serial.println();
50+
read_pid();
51+
delay(3000);
52+
info();
53+
}
54+
}
55+
56+
void read_pid(){
57+
M5.Lcd.clear(BLACK);
58+
M5.Lcd.setCursor(0,10);
59+
M5.Lcd.setTextSize(2);
60+
M5.Lcd.println("Servo CHANGE PID is");
61+
for(int i =1; i <7; i++)
62+
{
63+
M5.Lcd.print("servo: ");
64+
M5.Lcd.print(i);
65+
M5.Lcd.print(" P: ");
66+
M5.Lcd.print(myCobot.getServoData(i, 21));//P
67+
delay(50);
68+
M5.Lcd.print(" D: ");
69+
M5.Lcd.print(myCobot.getServoData(i, 22));//D
70+
delay(50);
71+
M5.Lcd.print(" I: ");
72+
M5.Lcd.print(myCobot .getServoData(i, 23));//I
73+
delay(50);
74+
M5.Lcd.println();
75+
M5.Lcd.println();
7476
}
7577
}
78+
79+
void change_mode2(){
80+
M5.Lcd.clear(BLACK);
81+
M5.Lcd.setCursor(0,10);
82+
M5.Lcd.setTextSize(2);
83+
int P,I,D;
84+
P = 10;
85+
I = 1;
86+
D = 0;
87+
for(int i = 1; i <7 ; i++){
88+
myCobot.setServoData(i, 21, P);//P
89+
delay(50);
90+
myCobot.setServoData(i, 22, D);//D
91+
delay(50);
92+
myCobot.setServoData(i, 23, I);//I
93+
delay(50);
94+
}
95+
M5.Lcd.println("CHANGE PID to Mode 2");
96+
M5.Lcd.println();
97+
M5.Lcd.println("Serco 1-6 :");
98+
M5.Lcd.println();
99+
M5.Lcd.println("P = 10, I = 1, D = 0");
100+
}
101+
void change_mode1(){
102+
M5.Lcd.clear(BLACK);
103+
M5.Lcd.setCursor(0,10);
104+
M5.Lcd.setTextSize(2);
105+
int P,I,D;
106+
for(int i = 1; i <7 ; i++)
107+
{
108+
if(i < 4){
109+
P = 5;
110+
I = 0;
111+
D = 15;
112+
}else{
113+
P = 8;
114+
I = 0;
115+
D = 24;
116+
}
117+
myCobot.setServoData(i, 21, P);//P
118+
delay(50);
119+
myCobot.setServoData(i, 22, D);//D
120+
delay(50);
121+
myCobot.setServoData(i, 23, I);//I
122+
delay(50);
123+
124+
}
125+
M5.Lcd.println("Servo CHANGE PID to Mode 1");
126+
M5.Lcd.println();
127+
M5.Lcd.println("Serco 1-3 :");
128+
M5.Lcd.println();
129+
M5.Lcd.println("P = 5, I = 0, D = 15");
130+
M5.Lcd.println();
131+
M5.Lcd.println("Serco 4-6 :");
132+
M5.Lcd.println();
133+
M5.Lcd.println("P = 8, I = 0, D = 24");
76134
}
Binary file not shown.

0 commit comments

Comments
 (0)