11#include < MycobotBasic.h>
22#include < ParameterList.h>
3-
4-
53MycobotBasic myCobot;
64
7-
85bool Servo_state = 1 ;
9-
106int power_pin = 2 ;
117int open_pin = 5 ;
128int out_state = 1 ;
13-
14- Coords pos_init_1 = {155.10 , -55.10 , 90.10 , -179.10 , 0.10 , -90.10 };
9+
10+ Coords pos_init_1 = {155.10 , -55.10 , 90.10 , -179.10 , 0.10 , -90.10 }; // 初始坐标
1511Coords data1;
12+ Angles angles_0 = {0 , 0 , 0 , 0 , 0 , 0 }; // 初始化角度
1613
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 );
14+ void move_coords (int dir = 0 , int num = 0 ); // 声明可调用函数,无实际意义。
2215
23- void setup () {
16+ void setup () { // 初始化函数
2417 myCobot.setup ();
2518 myCobot.powerOn ();
2619
@@ -33,20 +26,26 @@ void setup() {
3326 delay (100 );
3427 myCobot.writeAngles (angles_0,30 );
3528 delay (3000 );
29+ Serial.printf (" A键控制力矩开关 |" );
30+ Serial.println (" " );
31+ Serial.printf (" B键控制移动到初始坐标 |" );
32+ Serial.println (" " );
33+ Serial.printf (" C键控制前后左右上下移动 |" );
34+ Serial.println (" " );
3635}
3736
38- void loop () {
37+ void loop () { // 主函数
3938 // put your main code here, to run repeatedly:
4039 M5.update (); // need to call update()
4140 M5.Lcd .setCursor (0 ,0 );
4241 int j = 0 ;
43- if (M5.BtnA .wasReleased ()) {
42+ if (M5.BtnA .wasReleased ()) { // 控制上下电
4443 reless ();
4544 }
46- if (M5.BtnB .wasReleased ()) {
45+ if (M5.BtnB .wasReleased ()) { // 移动到初始角度
4746 myCobot.writeCoords (pos_init_1,30 );
4847 }
49- if (M5.BtnC .wasReleased ()) {
48+ if (M5.BtnC .wasReleased ()) { // 前后左右上下移动
5049 data1 = pos_init_1;
5150 delay (50 );
5251 move_coords (0 , 10 );
@@ -64,7 +63,7 @@ void loop() {
6463}
6564}
6665
67- void reless ()
66+ void reless () // 控制力矩开关
6867{
6968 for (int i = 1 ; i<7 ; i++){
7069 myCobot.setServoData (i, 40 , !Servo_state);
@@ -73,7 +72,7 @@ void reless()
7372 Servo_state = !Servo_state;
7473}
7574
76- Angles read_Angles ()
75+ Angles read_Angles () // 读取角度并输出
7776{
7877 Angles data2;
7978 data2 = myCobot.getAngles ();
@@ -86,7 +85,7 @@ Angles read_Angles()
8685 return data2;
8786}
8887
89- Coords read_pos ()
88+ Coords read_pos () // 读取坐标并输出
9089{
9190 Coords data1;
9291 data1 = myCobot.getCoords ();
@@ -99,7 +98,7 @@ Coords read_pos()
9998 return data1;
10099}
101100
102- void move_coords (int dir, int num)
101+ void move_coords (int dir, int num) // 控制移动方向和步数,一步等于10mm
103102{
104103 if (num > 0 ){
105104 for (int i = 0 ; i<num; i++){
@@ -110,7 +109,7 @@ void move_coords(int dir, int num)
110109 }
111110 Serial.println (" " );
112111 data1[dir] += 10 ;
113- delay (50 );
112+ delay (100 );
114113 }
115114 }else {
116115 num = 0 -num;
@@ -122,13 +121,12 @@ void move_coords(int dir, int num)
122121 }
123122 Serial.println (" " );
124123 data1[dir] -= 10 ;
125- delay (50 );
124+ delay (100 );
126125 }
127126 }
128127}
129128
130-
131- void set_pump (int out_state){
129+ void set_pump (int out_state){ // 吸泵开关
132130 digitalWrite (power_pin, out_state);
133131 digitalWrite (open_pin, out_state);
134132}
0 commit comments