-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRoArm-M2_example.ino
181 lines (143 loc) · 4.43 KB
/
RoArm-M2_example.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <ArduinoJson.h>
StaticJsonDocument<256> jsonCmdReceive;
StaticJsonDocument<256> jsonInfoSend;
StaticJsonDocument<256> jsonInfoHttp;
#include <SCServo.h>
#include <Preferences.h>
#include <nvs_flash.h>
#include <esp_system.h>
#include <LittleFS.h>
#include <WiFi.h>
#include <esp_wifi.h>
#include <WebServer.h>
#include <esp_now.h>
#include <nvs_flash.h>
// functions for oled.
#include "oled_ctrl.h"
// functions for RoArm-M2 ctrl.
#include "RoArm-M2_module.h"
// functions for pneumatic modules and lights ctrl.
#include "switch_module.h"
// define json cmd.
#include "json_cmd.h"
// functions for editing the files in flash.
#include "files_ctrl.h"
// advance functions for RoArm-M2 ctrl.
#include "RoArm-M2_advance.h"
// functions for wifi ctrl.
#include "wifi_ctrl.h"
// functions for esp-now.
#include "esp_now_ctrl.h"
// functions for uart json ctrl.
#include "uart_ctrl.h"
// functions for http & web server.
#include "http_server.h"
void setup() {
Serial.begin(115200);
Wire.begin(S_SDA, S_SCL);
while(!Serial) {}
delay(1200);
initOLED();
screenLine_0 = "RoArm-M2";
screenLine_1 = "version: 0.84";
screenLine_2 = "starting...";
screenLine_3 = "";
oled_update();
// init the littleFS funcs in files_ctrl.h
screenLine_2 = screenLine_3;
screenLine_3 = "Initialize LittleFS";
oled_update();
if(InfoPrint == 1){Serial.println("Initialize LittleFS for Flash files ctrl.");}
initFS();
// init the funcs in switch_module.h
screenLine_2 = screenLine_3;
screenLine_3 = "Initialize 12V-switch ctrl";
oled_update();
if(InfoPrint == 1){Serial.println("Initialize the pins used for 12V-switch ctrl.");}
switchPinInit();
// servos power up
screenLine_2 = screenLine_3;
screenLine_3 = "Power up the servos";
oled_update();
if(InfoPrint == 1){Serial.println("Power up the servos.");}
delay(500);
// init servo ctrl functions.
screenLine_2 = screenLine_3;
screenLine_3 = "ServoCtrl init UART2TTL...";
oled_update();
if(InfoPrint == 1){Serial.println("ServoCtrl init UART2TTL...");}
RoArmM2_servoInit();
// check the status of the servos.
screenLine_2 = screenLine_3;
screenLine_3 = "Bus servos status check...";
oled_update();
if(InfoPrint == 1){Serial.println("Bus servos status check...");}
RoArmM2_initCheck(false);
if(InfoPrint == 1 && RoArmM2_initCheckSucceed){
Serial.println("All bus servos status checked.");
}
if(RoArmM2_initCheckSucceed) {
screenLine_2 = "Bus servos: succeed";
} else {
screenLine_2 = "Bus servos: " +
servoFeedback[BASE_SERVO_ID - 11].status +
servoFeedback[SHOULDER_DRIVING_SERVO_ID - 11].status +
servoFeedback[SHOULDER_DRIVEN_SERVO_ID - 11].status +
servoFeedback[ELBOW_SERVO_ID - 11].status +
servoFeedback[GRIPPER_SERVO_ID - 11].status;
}
screenLine_3 = ">>> Moving to init pos...";
oled_update();
RoArmM2_resetPID();
RoArmM2_moveInit();
screenLine_3 = "Reset joint torque to ST_TORQUE_MAX";
oled_update();
if(InfoPrint == 1){Serial.println("Reset joint torque to ST_TORQUE_MAX.");}
RoArmM2_dynamicAdaptation(0, ST_TORQUE_MAX, ST_TORQUE_MAX, ST_TORQUE_MAX, ST_TORQUE_MAX);
screenLine_3 = "WiFi init";
oled_update();
if(InfoPrint == 1){Serial.println("WiFi init.");}
initWifi();
screenLine_3 = "http & web init";
oled_update();
if(InfoPrint == 1){Serial.println("http & web init.");}
initHttpWebServer();
screenLine_3 = "ESP-NOW init";
oled_update();
if(InfoPrint == 1){Serial.println("ESP-NOW init.");}
initEspNow();
screenLine_3 = "RoArm-M2 started";
oled_update();
if(InfoPrint == 1){Serial.println("RoArm-M2 started.");}
getThisDevMacAddress();
updateOledWifiInfo();
screenLine_2 = String("MAC:") + macToString(thisDevMac);
oled_update();
if(InfoPrint == 1){Serial.println("Application initialization settings.");}
createMission("boot", "these cmds run automatically at boot.");
missionPlay("boot", 1);
RoArmM2_handTorqueCtrl(300);
}
void loop() {
serialCtrl();
server.handleClient();
unsigned long curr_time = millis();
if (curr_time - prev_time >= 10){
constantHandle();
prev_time = curr_time;
}
RoArmM2_getPosByServoFeedback();
// esp-now flow ctrl as a flow-leader.
switch(espNowMode) {
case 1: espNowGroupDevsFlowCtrl();break;
case 2: espNowSingleDevFlowCtrl();break;
}
if (InfoPrint == 2) {
RoArmM2_infoFeedback();
}
if(runNewJsonCmd) {
jsonCmdReceiveHandler();
jsonCmdReceive.clear();
runNewJsonCmd = false;
}
}