Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Power failure #1

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed Teensey Code/mux_multi_sensor.zip
Binary file not shown.
Binary file added archive/.DS_Store
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ String experimenta_log = "";
unsigned int whichsensor = 0;

#define SECONDS_IN_DAY 86400
//#define DELAY_SECONDS_PER_EXPERIMENT SECONDS_IN_DAY
#define DELAY_SECONDS_PER_EXPERIMENT 120 // 2 mins for the functional testing
#define DELAY_SECONDS_PER_EXPERIMENT SECONDS_IN_DAY
//#define DELAY_SECONDS_PER_EXPERIMENT 120 // 2 mins for the functional testing
#define SERIAL_TIMEOUT 10000 //milliseconds

const unsigned int MAX_MESSAGE_LENGTH = 12;
Expand Down Expand Up @@ -453,10 +453,10 @@ void rtcInit() {
Serial.println("RTC is NOT initialized, let's set the time!");
// When time needs to be set on a new device, or after a power loss, the
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
//rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
// rtc.adjust(DateTime(2022, 11, 10, 2, 3, 3));
//
// Note: allow 2 seconds after inserting battery or applying external power
// without battery before calling adjust(). This gives the PCF8523's
Expand Down Expand Up @@ -521,22 +521,42 @@ void recoverSystemStart(){
/* (1) check for hard faults */
// (1.1) if system failed during an experiment, generate fault
if(systemStateStructVar.testDayComplete != 1){
Serial.println("System was interrupted during an experiment! No way to resume!");
while(1);
return;
Serial.print("System was interrupted during experiment: ");
Serial.println(systemStateStructVar.testDay);
saveExperimentalLog("System was interrupted during experiment: " + String(systemStateStructVar.testDay));

if(systemStateStructVar.testDay == 1){
Serial.print("Restarting entire experiment since lost power on day 1");
saveExperimentalLog("Restarting entire experiment since lost power on day 1");
day_1();
systemState = true;
return;
}
}

// (1.2) if system paused for longer than test day interval, generate fault
uint32_t timeSinceLastExperiment = rtc.now().unixtime() - systemStateStructVar.epoch;
uint16_t skipDays;
if(timeSinceLastExperiment >= DELAY_SECONDS_PER_EXPERIMENT){
Serial.println("System was off for longer than experiment interval! No way to resume!");
while(1);
return;
Serial.println("System was off for longer than experiment interval!");

skipDays = int( timeSinceLastExperiment / DELAY_SECONDS_PER_EXPERIMENT );
for(int i = 0; i < skipDays; i++){
systemStateStructVar.testDay++;
Serial.print(" Skipping day: ");
Serial.println(systemStateStructVar.testDay);

saveExperimentalLog(" Skipping day: " + String(systemStateStructVar.testDay));
}
}

timeSinceLastExperiment = int( timeSinceLastExperiment % DELAY_SECONDS_PER_EXPERIMENT );
// (1.3) check if tests had already ended
if(systemStateStructVar.testDay == TOTAL_EXPERIMENTS - 1){
Serial.println("Power failure occured after experiment finished! No reason to resume!");

saveExperimentalLog("Power failure occured after experiment finished! No reason to resume!");

while(1);
return;
}
Expand All @@ -553,6 +573,8 @@ void recoverSystemStart(){
// }

Serial.println("System has recovered gracefully!");

systemState = true;
}


Expand Down Expand Up @@ -590,6 +612,8 @@ bool checkForStartSerialCommand() {
//Print the message (or do other things)
Serial.println("Executing Test Script");



day_functionTest();
}

Expand All @@ -602,19 +626,13 @@ bool checkForStartSerialCommand() {
}

void day_functionTest(){

// DUMMY TASK

//EXP1
moveLiquid (experimentOne, e_buffer, chamberA, 2000); //buffer to chamber A - 2 ml (flexible)
//EXP2
moveLiquid (experimentTwo, e_buffer, chamberA, 2000); //buffer to chamber A - 2 ml (flexible)

Serial.println("revival pumping...");
motorSensorBrdCtrl(1, forward);
delay (5000);
motorSensorBrdCtrl(1, halt);


/////DAYFUNCTION

/////DAYFUNCTION

/////DAYFUNCTION

}


Expand Down Expand Up @@ -642,13 +660,20 @@ void day_1() {
saveExperimentalLog("Executing Day 1");


// =============== SAFETY MECHANISM ================
// DUMMY TASK
// =============== ENZYME EXP =====================

//EXP1
moveLiquid (experimentOne, e_buffer, chamberA, 2000); //buffer to chamber A - 2 ml (flexible)
//EXP2
moveLiquid (experimentTwo, e_buffer, chamberA, 2000); //buffer to chamber A - 2 ml (flexible)
//DUMMY CODE
moveLiquid (experimentOne, e_buffer, chamberA, 1000); //buffer to chamber A - 1 ml (flexible)
moveLiquid (experimentTwo, e_buffer, chamberA, 1000); //buffer to chamber A - 1 ml (flexible)
Serial.println("finish the dummy code...");
saveExperimentalLog("Finish dummy code!");

//EXP1 - liquid in dummy code
moveLiquid (experimentOne, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml
moveLiquid (experimentOne, e_buffer, chamberA, 1525); //buffer to chamber A - 1.525 ml (flexible)
//EXP2 - liquid in dummy code
moveLiquid (experimentTwo, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml
moveLiquid (experimentTwo, e_buffer, chamberA, 1525); //buffer to chamber A - 1.525 ml (flexible)


// =============== MICROBE EXP =====================
Expand All @@ -670,16 +695,6 @@ void day_1() {
motorSensorBrdCtrl(3, halt);


// =============== ENZYME EXP =====================

//EXP1
moveLiquid (experimentOne, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml
moveLiquid (experimentOne, e_buffer, chamberA, 2525); //buffer to chamber A - 2.925 ml (flexible)
//EXP2
moveLiquid (experimentTwo, enzyme, chamberA, 75); //enzyme to chamber A - 0.075 ml
moveLiquid (experimentTwo, e_buffer, chamberA, 2525); //buffer to chamber A - 2.925 ml (flexible)


// =============== UPDATE STATUS ===================
systemStateStructVar.testDayComplete = 1;
saveStateToSD(&systemStateStructVar);
Expand Down Expand Up @@ -1767,23 +1782,23 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume)
if (experiment == 1 && origin == 0)
{
switch_conn_pin(BASEBD_J10_PIN2, LOW); //Experiment 1 valveA
Serial.println("_E1_exp1 move from e_buffer");
saveExperimentalLog("_E1_move from e_buffer");
Serial.println("E1_exp1 move from e_buffer");
saveExperimentalLog("E1_move from e_buffer");
}

if (experiment == 1 && origin == 1)
{
switch_conn_pin(BASEBD_J10_PIN2, HIGH); //Experiment 1 valveA
Serial.println("_E1 move from enzyme");
saveExperimentalLog("_E1_move from enzyme");
Serial.println("E1 move from enzyme");
saveExperimentalLog("E1_move from enzyme");
}

if (experiment == 1 && target == 2)
{
switch_conn_pin(BASEBD_J9_PIN2, HIGH); //Experiment 1 valveB high, waste line open
int move_pulse = liquid_volume / 25; //1ml = 1000uL and the pump moves 25uL at a time
Serial.println("move to chamberA");
saveExperimentalLog("exp1_move to chamberA" + String(move_pulse * 25) + "uL");
saveExperimentalLog("E1_move to chamberA" + String(move_pulse * 25) + "uL");
for (int i = 0; i <= move_pulse; i++) {
switch_conn_pin(BASEBD_J10_PIN4, HIGH); //Experiment 1 pumpA
digitalWrite(LED, HIGH);
Expand All @@ -1792,6 +1807,7 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume)
digitalWrite(LED, LOW);
delay(200);
Serial.println( i * 25); //print out the moving volume
saveExperimentalLog("STEP_exp1_move to chamberA" + String(i * 25) + "uL");
}
switch_conn_pin(BASEBD_J10_PIN2, LOW); //Reset eperiment 1 valveA so enzyme is blocked
}
Expand Down Expand Up @@ -1821,8 +1837,8 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume)
if (experiment == 1 && origin == 3 && target == 4)
{
int move_pulse = liquid_volume / 25; //1ml = 1000uL and the pump moves 25uL at a time
Serial.println("_E1 move to chamberB");
saveExperimentalLog("_E1_move to chamberB " + String(move_pulse * 25) + "uL");
Serial.println("E1 move to chamberB");
saveExperimentalLog("E1_move to chamberB " + String(move_pulse * 25) + "uL");
for (int i = 0; i <= move_pulse; i++) {
switch_conn_pin(BASEBD_J9_PIN4, HIGH); //Experiment 1 pumpB
digitalWrite(LED, HIGH);
Expand All @@ -1831,6 +1847,7 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume)
digitalWrite(LED, LOW);
delay(200);
Serial.println( i * 25); //print out the moving volume
saveExperimentalLog("STEP_E1_move to chamberB " + String(i * 25) + "uL");
}
// switch_conn_pin(BASEBD_J9_PIN2, LOW); //Reset experiment 1 valveB so chamberA is blocked
}
Expand All @@ -1840,23 +1857,23 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume)
if (experiment == 2 && origin == 0)
{
switch_conn_pin(BASEBD_J12_PIN2, LOW); //Experiment 2 valveA
Serial.println("_E2 move from e_buffer");
saveExperimentalLog("_E2_move from e_buffer");
Serial.println("E2 move from e_buffer");
saveExperimentalLog("E2_move from e_buffer");
}

if (experiment == 2 && origin == 1)
{
switch_conn_pin(BASEBD_J12_PIN2, HIGH); //Experiment 2 valveA
saveExperimentalLog("_E2_move from enzyme");
Serial.println("_E2 move from Enzyme");
saveExperimentalLog("E2_move from enzyme");
Serial.println("E2 move from Enzyme");
}

if (experiment == 2 && target == 2)
{
switch_conn_pin(BASEBD_J11_PIN2, HIGH); //Experiment 2 valveB high, waste line open
int move_pulse = liquid_volume / 25; //1ml = 1000uL and the pump moves 25uL at a time
Serial.println("_E2 move to chamberA");
saveExperimentalLog("_E2_move to chamberA " + String(move_pulse * 25) + "uL");
Serial.println("E2 move to chamberA");
saveExperimentalLog("E2_move to chamberA " + String(move_pulse * 25) + "uL");
for (int i = 0; i <= move_pulse; i++) {
switch_conn_pin(BASEBD_J12_PIN4, HIGH); //Experiment 2 pumpA
digitalWrite(LED, HIGH);
Expand All @@ -1865,6 +1882,7 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume)
digitalWrite(LED, LOW);
delay(200);
Serial.println( i * 25);
saveExperimentalLog("STEP_E2_move to chamberA " + String(i * 25) + "uL");
}
switch_conn_pin(BASEBD_J12_PIN2, LOW); //Reset xperiment 1 valveA so enzyme is blocked
}
Expand Down Expand Up @@ -1895,8 +1913,8 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume)
if (experiment == 2 && origin == 3 && target == 4)
{
int move_pulse = liquid_volume / 25; //1ml = 1000uL and the pump moves 35uL at a time
Serial.println("_E2 media move to chamberB");
saveExperimentalLog("_E2_media_move to chamberB " + String(move_pulse * 25) + "uL");
Serial.println("E2 media move to chamberB");
saveExperimentalLog("E2_media_move to chamberB " + String(move_pulse * 25) + "uL");
for (int i = 0; i <= move_pulse; i++){
switch_conn_pin(BASEBD_J11_PIN4, HIGH); //Experiment 2 pumpB
digitalWrite(LED, HIGH);
Expand All @@ -1905,6 +1923,7 @@ void moveLiquid(int experiment, int origin, int target, float liquid_volume)
digitalWrite(LED, LOW);
delay(200);
Serial.println( i * 25);
saveExperimentalLog("STEP_E2_media_move to chamberB " + String(i * 25) + "uL");
}
}
}
Expand All @@ -1914,23 +1933,23 @@ void switchCollection(int experiment, int bag)
if (experiment == 1 && bag == 0)
{
switch_conn_pin(BASEBD_J5_PIN4, LOW); //Experiment 1 waste V6
Serial.println("exp1 open waste bag");
saveExperimentalLog("exp1_opem waste bag");
Serial.println("E1 open waste bag");
saveExperimentalLog("E1_opem waste bag");
}
if (experiment == 1 && bag == 1)
{
switch_conn_pin(BASEBD_J5_PIN4, HIGH); //NOT V6
switch_conn_pin(BASEBD_J5_PIN2, LOW); //Experiment 1 preservativeOne V5
Serial.println("exp1 open preservativeOne bag");
saveExperimentalLog("exp1_open preservativeOne bag");
Serial.println("E1 open preservativeOne bag");
saveExperimentalLog("E1_open preservativeOne bag");
}
if (experiment == 1 && bag == 2)
{
switch_conn_pin(BASEBD_J5_PIN4, HIGH); //NOT V6
switch_conn_pin(BASEBD_J5_PIN2, HIGH); //NOT V5
switch_conn_pin(BASEBD_J3_PIN4, LOW); ////Experiment 1 preservativeTwo V4
Serial.println("exp1 open preservativeTwo bag");
saveExperimentalLog("exp1_open preservativeTwo bag");
Serial.println("E1 open preservativeTwo bag");
saveExperimentalLog("E1_open preservativeTwo bag");
}
if (experiment == 1 && bag == 3)
{
Expand All @@ -1939,7 +1958,7 @@ void switchCollection(int experiment, int bag)
switch_conn_pin(BASEBD_J3_PIN4, HIGH); //NOT V4
switch_conn_pin(BASEBD_J3_PIN2, LOW); //Experiment 1 preservativeThree V3
Serial.println("open preservativeThree bag");
saveExperimentalLog("exp1_open preservativeThree bag");
saveExperimentalLog("E1_open preservativeThree bag");
}
if (experiment == 1 && bag == 4)
{
Expand All @@ -1948,40 +1967,40 @@ void switchCollection(int experiment, int bag)
switch_conn_pin(BASEBD_J3_PIN4, HIGH); //NOT V4
switch_conn_pin(BASEBD_J3_PIN2, HIGH); //NOT V3
switch_conn_pin(BASEBD_J1_PIN4, LOW); //Experiment 1 preservativeFour V2
Serial.println("open preservativeFour bag");
Serial.println("E1_open preservativeFour bag");
}

//experiment two collection

if (experiment == 2 && bag == 0)
{
switch_conn_pin(BASEBD_J2_PIN2, LOW); //Experiment 2 waste V7
Serial.println("exp2 open waste bag");
saveExperimentalLog("exp2_opem waste bag");
Serial.println("E2 open waste bag");
saveExperimentalLog("E2_opem waste bag");
}
if (experiment == 2 && bag == 1)
{
switch_conn_pin(BASEBD_J2_PIN2, HIGH); //NOT V7
switch_conn_pin(BASEBD_J2_PIN4, LOW); //Experiment 2 preservativeOne V8
Serial.println("exp2 open preservativeOne bag");
saveExperimentalLog("exp2_open preservativeOne bag");
Serial.println("E2 open preservativeOne bag");
saveExperimentalLog("E2_open preservativeOne bag");
}
if (experiment == 2 && bag == 2)
{
switch_conn_pin(BASEBD_J2_PIN2, HIGH); //NOT V7
switch_conn_pin(BASEBD_J2_PIN4, HIGH); //NOT V8
switch_conn_pin(BASEBD_J4_PIN2, LOW); ////Experiment 2 preservativeTwo V9
Serial.println("exp2 open preservativeTwo bag");
saveExperimentalLog("exp2_open preservativeTwo bag");
Serial.println("E2 open preservativeTwo bag");
saveExperimentalLog("E2_open preservativeTwo bag");
}
if (experiment == 2 && bag == 3)
{
switch_conn_pin(BASEBD_J2_PIN2, HIGH); //NOT V7
switch_conn_pin(BASEBD_J2_PIN4, HIGH); //NOT V8
switch_conn_pin(BASEBD_J4_PIN2, HIGH); //NOT V9
switch_conn_pin(BASEBD_J4_PIN4, LOW); //Experiment 2 preservativeThree V10
Serial.println("open preservativeThree bag");
saveExperimentalLog("exp2_open preservativeThree bag");
Serial.println("E2_open preservativeThree bag");
saveExperimentalLog("E2_open preservativeThree bag");
}
if (experiment == 2 && bag == 4)
{
Expand All @@ -1990,8 +2009,8 @@ if (experiment == 2 && bag == 4)
switch_conn_pin(BASEBD_J4_PIN2, HIGH); //NOT V9
switch_conn_pin(BASEBD_J4_PIN4, HIGH); //NOT V10
switch_conn_pin(BASEBD_J6_PIN2, LOW); //Experiment 2 preservativeFour V11
Serial.println("open preservativeFour bag");
saveExperimentalLog("exp2_open preservativeFour bag");
Serial.println("E2_open preservativeFour bag");
saveExperimentalLog("E2_open preservativeFour bag");
}
}

Expand Down
Loading