-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADCS_pico.ino
100 lines (82 loc) · 2.12 KB
/
ADCS_pico.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
#include "Main.h"
float M_speed=0.0;
int seconds;
//=======================================================
void setup() {
Serial.begin(115200);
ADCS.Pins_init();
//SD card Initialization
ADCS.SD_cardModule_init();
Motor1_Controller.kp=55;//2.75
Motor1_Controller.ki=0.06;//0.4
Motor1_Controller.SetPoint=0;
Get_speed();
delay(5000);
ADCS.Led_on();
}
//=========================================================
void loop() {
Get_speed();
//Motor1_Controller.Calculate_pid(rpm,Motor1_Controller.SetPoint,180.0,90.0);
ESC.write(Motor1_Controller.Calculate_pid(rpm,Motor1_Controller.SetPoint,180.0,90.0));
//ESC.write(Motor1_Controller.SetPoint);
get_data();
delay(1);
}
//==========================================================
void get_data()
{
currT2= millis();
if(currT2-prevT2>=500){
//Serial.print("Battery:"+String(Get_batteryV()));
//Serial.print("PID:"+String(Motor1_Controller.pid_value));
Serial.print("SetPoint:"+String(Motor1_Controller.SetPoint));
Serial.println(",MeaSpeed:"+String(rpm));
// Calculate RPM
if (Serial.available() > 0)
{
M_speed = Serial.readStringUntil('\n').toFloat();
/*if(M_speed==0||M_speed<90)M_speed=90;
if(M_speed==500)
{
save_data();
delay(100);
Serial.println("File saved");
M_speed=90;
while(1);
}*/
Motor1_Controller.SetPoint=M_speed;
}
prevT2=currT2;
}
}
//==========================================================
void Get_Data_Record()
{
if(currT2-prevT3>=1000){
seconds+=1.0;
log_data(seconds,rpm,Get_batteryV());
prevT3=currT2;
Serial.println("Saving...");
if(seconds>180)
{ save_data();
delay(100);
Serial.println("File saved");
M_speed=90;
while(1);
}
}
}
//=======================================================
//=====================Second Core=======================
//=======================================================
/*
//This is the Second core
void setup1() {
Serial.println("Core 2 activated");
Server_init();
delay(1000);
}
void loop1() {
run_client();
}*/