Skip to content

Commit 4448c79

Browse files
committed
Small changes to pins etc.
1 parent 42fdd2e commit 4448c79

File tree

9 files changed

+126
-97
lines changed

9 files changed

+126
-97
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ build without running `./pi -b`
3535
## Using the Program {curly brackets mean TODO}
3636

3737
Once you have launched the TUI successfully, you must launch the system into SAFE mode by pressing s[afe]. The system
38-
may be armed by pressing <CTRL-A>, then {once you are satisfied that the system has booted correctly,} STARTUP mode may
39-
be entered by pressing <SPACE>. The computer will then enter STARTUP, followed by FIRING and SHUTDOWN {as it runs the
38+
may be armed by pressing <CTRL-A>, then {once you are satisfied that the system has booted correctly,} IGNITION mode may
39+
be entered by pressing <SPACE>. The computer will then enter IGNITION, followed by FIRING and SHUTDOWN {as it runs the
4040
preconfigured fire sequence}. An ABORT may be triggered by pressing <BACKSPACE> {or automatically by the system
4141
detecting unsafe parameters}. ABORT mode can only be exitied by the computer, for safety reasons {currently press
4242
e[rror] to debug exit}. SHUTDOWN exits to SAFE, and ABORT exits to ERROR, from which SAFE mode can be entered by

include/Relay.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Relay {
1313

1414
static void set_output(int output, int value);
1515

16-
static void set_outputs(const std::array<int, NUM_VALVES> *values);
16+
static void set_outputs(const int values[NUM_VALVES]);
1717

1818
private:
1919
static const int pins[NUM_VALVES];

include/State.hpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
enum State {
1313
INIT,
1414
SAFE,
15-
ARMED,
16-
STARTUP,
15+
READY,
16+
F_FILL,
17+
O_FILL,
18+
CHILL,
19+
P_TANKS,
20+
P_CHAM,
21+
IGNITION,
1722
FIRING,
1823
SHUTDOWN,
24+
VENT,
1925
ABORT,
2026
ERROR,
2127
OFF,
@@ -44,10 +50,5 @@ class StateMachine {
4450
std::chrono::time_point<std::chrono::system_clock> state_begin;
4551
static const bool transition_matrix[NUM_STATES][NUM_STATES];
4652

47-
const std::vector<std::array<int, NUM_VALVES>> *valve_matrix;
48-
49-
static const std::vector<std::array<int, NUM_VALVES>> IPA_cft_solenoids;
50-
static const std::vector<std::array<int, NUM_VALVES>> N2O_cft_solenoids;
51-
static const std::vector<std::array<int, NUM_VALVES>> H2O_cft_solenoids;
52-
53+
static const int valve_matrix[NUM_STATES][NUM_VALVES];
5354
};

src/ADC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "../include/ADC.hpp"
22

33

4-
ADC::ADC(int bus, int addr, int freq) : freq(freq), values(), k_filter{0.01}, is_alive(true) {
4+
ADC::ADC(int bus, int addr, int freq) : freq(freq), values(), k_filter{1}, is_alive(true) {
55
char filename[20];
66

77
snprintf(filename, 19, "/dev/i2c-%d", bus);

src/Display.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ Display::Display(
4141
// examples:
4242
// &((*PTs)[0]->*(&PT::pressure)) references the pressure of PT0
4343
// &(((*ADCs)[0]->*(&ADC::values))[0]) references value 0 of ADC0
44-
graph_srcs[0] = &(((*ADCs)[0]->*(&ADC::values))[0]);
45-
graph_srcs[1] = &(((*ADCs)[0]->*(&ADC::values))[1]);
46-
graph_srcs[2] = &(((*ADCs)[0]->*(&ADC::values))[2]);
47-
graph_srcs[3] = &((*LCs)[0]->*(&LoadCell::weight));
44+
graph_srcs[0] = &((*PTs)[0]->*(&PT::pressure));
45+
graph_srcs[1] = &((*PTs)[1]->*(&PT::pressure));
46+
graph_srcs[2] = &((*PTs)[2]->*(&PT::pressure));
47+
graph_srcs[3] = &((*PTs)[3]->*(&PT::pressure));
4848

4949
for (int i = 0; i < 4; i++) {
5050
std::deque<float> temp{0};
@@ -163,12 +163,18 @@ void Display::draw_gauges() {
163163
mvwprintw(top_win, 7, 4, "P2: %f", (*PTs)[2]->pressure);
164164
mvwprintw(top_win, 8, 4, "T2: %f", (*PTs)[2]->temperature);
165165

166-
mvwprintw(top_win, 1, 18, "LC0: %f", (*LCs)[0]->weight);
166+
mvwprintw(top_win, 1, 24, "P3: %f", (*PTs)[3]->pressure);
167+
mvwprintw(top_win, 2, 24, "T3: %f", (*PTs)[3]->temperature);
168+
169+
mvwprintw(top_win, 4, 24, "P4: %f", (*PTs)[4]->pressure);
170+
mvwprintw(top_win, 5, 24, "T4: %f", (*PTs)[4]->temperature);
171+
172+
mvwprintw(top_win, 1, 44, "LC0: %f", (*LCs)[0]->weight);
167173

168174

169175
for (int i = 0; i < 2; i++) {
170176
for (int j = 0; j < 4; j++) {
171-
mvwprintw(top_win, 5 + j, 18 + 20 * i, "ADC%d/%d: %5.0f", i, j, (*ADCs)[i]->values[j]);
177+
mvwprintw(top_win, 5 + j, 44 + 20 * i, "ADC%d/%d: %5.0f", i, j, (*ADCs)[i]->values[j]);
172178
}
173179
}
174180

src/LoadCell.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bool LoadCell::init() {
1414
is_alive = true;
1515

1616
options.stratType=HX711::StrategyType::Samples;
17-
options.samples=5;
17+
options.samples=1; // change this for actual operation perhaps
1818

1919
obj = std::make_unique<std::thread>(&LoadCell::loop, this);
2020
return true;

src/Relay.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "Relay.hpp"
22

3-
const int Relay::pins[NUM_VALVES] = {23, 24, 12, 25};
3+
const int Relay::pins[NUM_VALVES] = {26, 19, 11, 10, 27};
44

55
Relay::Relay() {
66
// no need to check error code of wiringPiSetup()
@@ -13,12 +13,11 @@ Relay::Relay() {
1313
}
1414

1515
void Relay::set_output(int output, int value) {
16-
digitalWrite(pins[output], value);
16+
digitalWrite(pins[output], 1-value);
1717
}
1818

19-
void Relay::set_outputs(const std::array<int, NUM_VALVES> *values) {
20-
for (int i = 0; auto output: *values) {
21-
digitalWrite(pins[i], output);
22-
i++;
19+
void Relay::set_outputs(const int values[NUM_VALVES]) {
20+
for (int i = 1; i<NUM_VALVES; i++) { // use i=1 because i=0 represents the helium valve servo
21+
digitalWrite(pins[i-1], 1-values[i]);
2322
}
2423
}

src/State.cpp

Lines changed: 90 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,78 @@
22

33
// names of states
44
const char *StateMachine::names[]{
5-
"INIT", "SAFE", "ARMED", "STARTUP", "FIRING", "SHUTDOWN", "ABORT", "ERROR", "OFF"
5+
"INIT", "[S]AFE", "[^R]EADY", "[F]UEL FILL", "[O]X FILL", "C[H]ILL",
6+
"[C]HAMBER PRESS", "[T]ANKS PRESS", "[I]GNITION", "[_]FIRING", "[x]SHUTDOWN",
7+
"[V]ENT", "[<-]ABORT", "[E]RROR", "[^O]FF"
68
};
79

810
// ncurses colors of states
911
const int StateMachine::colors[]{
10-
10, 10, 11, 12, 12, 12, 9, 9, 0
12+
10, 10, 11, 12, 12, 12,
13+
12, 12, 208, 208, 208,
14+
220, 9, 9, 0
1115
};
1216

1317
// permissible states accessible from a given state
1418
const bool StateMachine::transition_matrix[NUM_STATES][NUM_STATES]{
15-
// INIT SAFE ARMED STARTUP FIRING SHUTDOWN ABORT ERROR OFF
19+
// INIT SAFE READY IGNITION FIRING SHUTDOWN ABORT ERROR OFF
1620

17-
{true, true, false, false, false, false, false, true, true}, //INIT
18-
{false, true, true, false, false, false, false, true, true}, //SAFE
19-
{false, true, true, true, false, false, false, true, false}, //ARMED
20-
{false, false, false, true, true, false, true, false, false}, //STARTUP
21-
{false, false, false, false, true, true, true, false, false}, //FIRING
22-
{false, true, false, false, false, true, true, true, false}, //SHUTDOWN
23-
{false, false, false, false, false, false, true, true, false}, //ABORT
24-
{false, true, false, false, false, false, false, true, true}, //ERROR
25-
{false, true, false, false, false, false, false, false, true} //OFF
26-
};
27-
28-
const std::vector<std::array<int, NUM_VALVES>> StateMachine::IPA_cft_solenoids{
29-
{{0, 0, 0, 0, 0, 0, 1},
30-
{1, 0, 0, 0, 0, 0, 0},
31-
{1, 1, 0, 0, 0, 0, 0},
32-
{1, 0, 0, 0, 0, 0, 0},
33-
{1, 0, 1, 0, 0, 0, 0},
34-
{0, 0, 0, 0, 0, 0, 0},
35-
{0, 0, 0, 0, 1, 1, 1}}
36-
};
21+
// {true, true, false, false, false, false, false, true, true}, //INIT
22+
// {false, true, true, false, false, false, false, true, true}, //SAFE
23+
// {false, true, true, true, false, false, false, true, false}, //READY
24+
// {false,false,false,false,false,false,false,false,false,false,false,false,},
25+
// {},
26+
// {},
27+
// {},
28+
// {},
29+
// {false, false, false, true, true, false, true, false, false}, //IGNITION
30+
// {false, false, false, false, true, true, true, false, false}, //FIRING
31+
// {false, true, false, false, false, true, true, true, false}, //SHUTDOWN
32+
// {},
33+
// {false, false, false, false, false, false, true, true, false}, //ABORT
34+
// {false, true, false, false, false, false, false, true, true}, //ERROR
35+
// {false, true, false, false, false, false, false, false, true} //OFF
36+
// ALL TRUE FOR DEBUG
37+
// INIT SAFE READY FUEL FILL OX FILL CHILL CHAM P TANKS P IGNITION FIRING SHUTDOWN VENT ABORT ERROR OFF
38+
{true, true, false, false, false, false, false, false, false, false, false, false, false, true, true}, // INIT
39+
{false, true, true, false, false, false, false, false, false, false, false, false, false, true, true}, // SAFE
40+
{false, true, true, true, true, true, true, true, true, false, false, true, false, true, false}, // READY
41+
{false, false, true, true, false, false, false, false, false, false, false, false, false, true, false}, // F FILL
42+
{false, false, true, false, true, false, false, false, false, false, false, false, false,true , false}, // O FILL
43+
{false, false, true, false, false, true, false, false, false, false, false, false, false,true , false}, // CHILL
44+
{false, false, true, false, false, false, true, false, false, false, false, false, false,true , false}, // CHAM P
45+
{false, false, true, false, false, false, false, true, false, false, false, false, false,true , false}, // TANK P
46+
{false, false, false, false, false, false, false, false, true, true, false, false, true, false, false}, // IGNITION
47+
{false, false, false, false, false, false, false, false, false, true, true, false, true, false, false}, // FIRING
48+
{false, false, true, false, false, false, false, false, false, false, true, false, false, true, false}, // SHUTDOWN
49+
{false, false, true, false, false, false, false, false, false, false, false, true, false, true, false}, // VENT
50+
{false, false, true, false, false, false, false, false, false, false, false, false, true, true, false}, // ABORT
51+
{false, false, true, false, false, false, false, false, false, false, false, false, false, true, true}, // ERROR
52+
{false, true, false, false, false, false, false, false, false, false, false, false, false, false, true} // OFF
3753

38-
const std::vector<std::array<int, NUM_VALVES>> StateMachine::N2O_cft_solenoids{
39-
{{0, 0, 0, 1, 0, 0, 0},
40-
{0, 0, 0, 0, 0, 1, 0},
41-
{6, 6, 6, 6, 6, 6, 6},
42-
{0, 0, 0, 0, 0, 0, 0},
43-
{1, 0, 1, 0, 0, 0, 0},
44-
{1, 0, 0, 0, 0, 0, 0},
45-
{1, 1, 0, 0, 0, 0, 0},
46-
{0, 0, 0, 0, 0, 0, 0},
47-
{0, 0, 0, 0, 1, 1, 1}}
4854
};
4955

50-
const std::vector<std::array<int, NUM_VALVES>> StateMachine::H2O_cft_solenoids{
51-
{{0, 0, 0, 1, 0, 0, 0},
52-
{0, 0, 0, 0, 0, 0, 0},
53-
{1, 0, 0, 0, 0, 0, 0},
54-
{1, 1, 1, 0, 0, 0, 0},
55-
{0, 0, 0, 0, 0, 0, 0},
56-
{0, 0, 0, 0, 1, 1, 1}}
56+
const int StateMachine::valve_matrix[NUM_STATES][NUM_VALVES]{
57+
// HE MAIN(SERVO), N2O FILL(NO), CHAM VENT, N2O VENT, IPA VENT, IGNITER -- NOTE, ASSUMED ALL VALVES ARE NC, 1 = OPEN, 0 = CLOSED
58+
{1, 1, 1, 1, 1, 0}, // INIT
59+
{0, 0, 1, 1, 1, 0}, // SAFE
60+
{0, 0, 0, 0, 0, 0}, // READY
61+
{0, 0, 0, 0, 1, 0}, // FUEL FILL
62+
{0, 1, 0, 0, 0, 0}, // OX FILL
63+
{0, 0, 0, 1, 0, 0}, // CHILL
64+
{1, 0, 0, 0, 0, 0}, // PRESS CHAMBER
65+
{1, 0, 0, 0, 0, 0}, // PRESS TANKS
66+
{1, 0, 0, 0, 0, 1}, // IGNITION
67+
{1, 0, 0, 0, 0, 0}, // FIRING
68+
{0, 0, 0, 0, 0, 0}, // SHUTDOWN
69+
{0, 0, 1, 1, 1, 0}, // VENT
70+
{0, 0, 1, 0, 0, 0}, // ABORT (VENT CHAMBER)
71+
{0, 0, 0, 0, 0, 0}, // ERROR
72+
{0, 0, 0, 0, 0, 0} // OFF
5773
};
5874

59-
StateMachine::StateMachine(std::shared_ptr<Relay> valves, std::shared_ptr<Servo> servos) : state(INIT), valves(valves), servos(servos), valve_matrix(&N2O_cft_solenoids) {}
75+
StateMachine::StateMachine(std::shared_ptr<Relay> valves, std::shared_ptr<Servo> servos)
76+
: state(INIT), valves(valves), servos(servos) {}
6077

6178
bool StateMachine::canChangeTo(State next) const {
6279
return transition_matrix[state][next];
@@ -71,21 +88,46 @@ State StateMachine::update(int ch) {
7188
case 's':
7289
changeState(SAFE);
7390
break;
74-
case 'a' - 96:
75-
changeState(ARMED);
91+
case 'r':
92+
if (state!=SAFE) changeState(READY);
93+
break;
94+
case 'r' - 96:
95+
changeState(READY);
96+
break;
97+
case 'f':
98+
changeState(F_FILL);
99+
break;
100+
case 'o':
101+
changeState(O_FILL);
102+
break;
103+
case 'h':
104+
changeState(CHILL);
105+
break;
106+
case 'c':
107+
changeState(P_CHAM);
108+
break;
109+
case 't':
110+
changeState(P_TANKS);
111+
break;
112+
case 'i':
113+
changeState(IGNITION);
76114
break;
77115
case ' ':
78-
changeState(SHUTDOWN);
79116
changeState(FIRING);
80-
changeState(STARTUP);
117+
break;
118+
case 'x':
119+
changeState(SHUTDOWN);
120+
break;
121+
case 'v':
122+
changeState(VENT);
81123
break;
82124
case 263:
83125
changeState(ABORT);
84126
break;
85127
case 'e':
86128
changeState(ERROR);
87129
break;
88-
case 'o':
130+
case 'o'-96:
89131
changeState(OFF);
90132
break;
91133
default:
@@ -95,27 +137,6 @@ State StateMachine::update(int ch) {
95137
}
96138

97139
void StateMachine::process() const {
98-
valves->set_outputs(&(valve_matrix->at(state)));
99-
switch (state) {
100-
case INIT:
101-
break;
102-
case SAFE:
103-
break;
104-
case ARMED:
105-
break;
106-
case STARTUP:
107-
break;
108-
case FIRING:
109-
break;
110-
case SHUTDOWN:
111-
break;
112-
case ABORT:
113-
break;
114-
case ERROR:
115-
break;
116-
case OFF:
117-
break;
118-
case NUM_STATES:
119-
break;
120-
}
140+
valves->set_outputs(valve_matrix[state]);
141+
121142
}

src/main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ int main() {
1414
auto PTs = std::make_shared<std::vector<PT*>>();
1515

1616
PTs->push_back(new PT(1, M32JM_ADDR, SAMPLING_FREQ));
17-
PTs->push_back(new PT(3, M32JM_ADDR, SAMPLING_FREQ));
17+
PTs->push_back(new PT(3, M32JM_ADDR, 100));
1818
PTs->push_back(new PT(4, M32JM_ADDR, SAMPLING_FREQ));
19+
PTs->push_back(new PT(5, M32JM_ADDR, SAMPLING_FREQ));
20+
PTs->push_back(new PT(6, 0x49, SAMPLING_FREQ));
1921

2022
auto LCs = std::make_shared<std::vector<LoadCell*>>();
2123

2224
LCs->push_back(new LoadCell(7,25));
2325

2426
auto ADCs = std::make_shared<std::vector<ADC*>>();
2527

26-
ADCs->push_back(new ADC(1,ADC0_ADDR,300));
27-
ADCs->push_back(new ADC(3,ADC1_ADDR,300));
28+
ADCs->push_back(new ADC(1,ADC0_ADDR,200));
29+
ADCs->push_back(new ADC(3,ADC0_ADDR,200));
2830

2931
auto relays = std::make_shared<Relay>();
3032
auto servos = std::make_shared<Servo>(4, 40);

0 commit comments

Comments
 (0)