-
Notifications
You must be signed in to change notification settings - Fork 2
/
Zarvan_PRIMCOMP_Modularisation.ino
293 lines (192 loc) · 5.68 KB
/
Zarvan_PRIMCOMP_Modularisation.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
////////////////////////////////////////////////
////////////////////////////////////////////
/*
Zarvan Movdawalla
Version 0.2
________________________________________
DEVELOPED AT MPSTME, INDIA.
PART OF ASLS (Air Sea Land Space) initiative by Zarvan Movdawalla.
RP2040
PRIMARY COMPUTER
DUAL CORE COMPATIBLE
STRICTLY not for commercial use.
STRICTLY not for safety-critical/unsafe/hazardous applications.
Licensed under: CC BY-NC-SA
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Special thanks to Joop Brokking (for IMU CF methodology), Earle F. Philhower III (for RP2040 Arduino Core). This ADCS is based off of their pioneering work.
MISSION FORMAT (ZarSAT V1) **massively WIP**
[TYPE] [DURATION] [DATA1] [DATA2] [DATA3] [DATA4] [DATA5]
[ 0 ] [ 0 ] [ 0 ] [ 0 ] [ 0 ] [ 0 ] [ 0 ] //shutdown adcs
[ 1 ] [ 0 ] [ 0 ] [ 0 ] [ 0 ] [ 0 ] [ 0 ] //disable adcs
[ 2 ] [ seconds] [ 0 ] [ 0 ] [ 0 ] [ 0 ] [ 0 ] //adcs magneto-observer mode ON (return X,Y,Z and BDOT values)
[ 3 ] [ 0 ] [move1] [move2] [move3] [move4] [move5] //raw reaction wheel driver (P, Y, R), MOTIONS WILL BE CLEARLY ONE AFTER ANOTHER, NOT PARALLEL. NO OFFSET >90 Degrees
[ 4 ] [seconds ] [XAXIS] [YAXIS] [ZAXIS] [ 0 ] [ 0 ] //raw magnetorquer driving (x,y,z) MAGNITUDE BASED
STATUS TABLE:
-1 = INVALID
0 = PHOENIX MODE
1 = SAFE
2 = MISSION MODE
MISSION COMPLETION STATUS:
0 = INCOMPLETE
1 = COMPLETED
ONBOARD HEALTH STATUS:
OHS_ADCS:
0 = NO FAULT
1 = IMU FAIL
2 = TOTAL ADCS FAILURE
OHS_EPS:
0 = NO FAULT
1 = TOTAL EPS FAILURE
*///////////////////////////////////////////////
////////////////////////////////////////////////
#include <Wire.h>
#include "RTClib.h"
#include "SparkFun_External_EEPROM.h" // Click here to get the library: http://librarymanager/All#SparkFun_External_EEPROM
ExternalEEPROM eeprom;
RTC_DS3231 rtc;
int16_t missionplan1[7][7] =
{
{1, 0, 0, 0, 1, 2, 3}, //1
{2, 0, 0, 0, 1, 2, 3}, //2
{3, 0, 0, 0, 1, 2, 3}, //3
{4, 0, 0, 0, 1, 2, 3}, //4
{5, 0, 0, 0, 1, 2, 3}, //5
{6, 0, 0, 0, 1, 2, 3}, //6
{7, 0, 0, 0, 1, 2, 3} //7
};
int16_t dataToSend[] = {0,0,0,0,0,0,0};
const int dataLength = sizeof(dataToSend) / sizeof(dataToSend[0]);
int pointofmission = 0;
int opfreq = 0;
int adcscommand = 14;
int adcsfinish = 15;
int loop_timer = 0;
int wooftimer = 1500; //watchdog
int done = 0 ;
int adcsfinishState = 0;
int lastadcsfinishState=0;
int16_t type = 0;
int16_t duration = 0;
int16_t data1 = 0;
int16_t data2 = 0;
int16_t data3 = 0;
void setup()
{
Serial.begin(115200);
/* while (!Serial)
{
delay(1); // Avoids WEIRD serial garbage and bugginess. Remove SERIAL usage once done debugging. No one has USB in space...
}
*/
for (int row = 0; row < 7; row++)
{
for (int col = 0; col < 7; col++) {
Serial.print(missionplan1[row][col]);
Serial.print(" "); // Print a space between elements
}
Serial.println(); // Move to the next line after each row
}
eeprom.setMemoryType(32);
begini2c();
eeprom.begin(0b1010111, Wire);
Serial.println("Memory detected!");
rtc.begin(&Wire);
//PIN DECLARATION
pinMode (0, OUTPUT);
digitalWrite(0,HIGH);
pinMode (25, OUTPUT);
pinMode (adcscommand, OUTPUT);
pinMode (adcsfinish, INPUT_PULLDOWN);
//EEPROM OPS (32Byte)
//EEPROM writing (PRE-LAUNCH)
int16_t membankID = 1;
int16_t status = -1;
eeprom.put(0, 0); //PHOENIX (MODE)
eeprom.put(10, 1); //COMPLETION STATUS
// eeprom.get(0, read1); //(location, data)
// eeprom.get(10, read2); //(location, data)
rp2040.wdt_begin(wooftimer);
loop_timer = millis();
}
void loop()
{
checkadcsstatus();
prepforADCS();
sendtoADCS(dataToSend, 7);
while(millis() - loop_timer < 100)
{
aux_work();
}
rp2040.wdt_reset();
loop_timer = millis();
}
void begini2c()
{
Wire.setSDA(4);
Wire.setSCL(5);
Wire.begin(); //for sensors
Wire1.setSDA(6);
Wire1.setSCL(7);
Wire1.begin(); //for adcs<->prim
}
void checkadcsstatus()
{
adcsfinishState = digitalRead(adcsfinish);
if (adcsfinishState == HIGH && lastadcsfinishState == LOW && pointofmission < 7)
{
pointofmission++;
Serial.print(" ADCS SAYS FINISHED, POM = ");
Serial.println(pointofmission);
}
lastadcsfinishState = adcsfinishState;
if (pointofmission == 7)
{
Serial.println("DONE!");
mission1done();
}
}
void mission1done()
{
delay(20000);
}
void aux_work()
{
}
void prepforADCS()
{
DateTime now = rtc.now();
for(int i = 0; i < 7 ; i++)
{
dataToSend[i] = missionplan1[pointofmission][i];
}
Serial.print(":");
Serial.print(pointofmission);
Serial.print(" ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
}
void sendtoADCS(int16_t *array, int length)
{
Wire1.beginTransmission(9);
for (int i = 0; i < length; i++) {
Wire1.write((uint8_t)(array[i] >> 8)); // Send the high byte
Wire1.write((uint8_t)(array[i] & 0xFF)); // Send the low byte
}
Wire1.endTransmission();
for (int i = 0; i < 7; i++)
{
Serial.print(dataToSend[i]);
Serial.print(",");
}
Serial.println(" ");
}