diff --git a/client/src/config.json b/client/src/config.json index 68ed5ea..d997de5 100644 --- a/client/src/config.json +++ b/client/src/config.json @@ -1,321 +1,219 @@ { - "telemetry": { - "GS_IP": "127.0.0.1", - "GS_PORT": 5005, - "DELAY": 0.1, - "SOCKETIO_HOST": "127.0.0.1", - "SOCKETIO_PORT": 5000 - }, - "sensors": { - "list": { - "thermocouple": {}, - "pressure": { - "PT-5": { - "kalman_args": { - "process_variance": 0.01, - "measurement_variance": 0.02, - "kalman_value": 1000 - }, - "boundaries": { - "waiting": { - "safe": [-20, 50], - "warn": [-30, 75], - "critical": [-50, 100] - }, - "pressurization": { - "safe": [693, 806], - "warn": [637, 862], - "critical": [0, 1000] - }, - "autosequence": { - "safe": [100, 500], - "warn": [50, 600], - "critical": [0, 800] - }, - "postburn": { - "safe": [0, 1000], - "warn": [0, 1001], - "critical": [0, 1002] - } - }, - "pin": 14 - }, - "PT-P": { - "kalman_args": { - "process_variance": 0.01, - "measurement_variance": 0.02, - "kalman_value": 1000 - }, - "boundaries": { - "waiting": { - "safe": [693, 806], - "warn": [637, 862], - "critical": [0, 1000] - }, - "pressurization": { - "safe": [693, 806], - "warn": [637, 862], - "critical": [0, 1000] - }, - "autosequence": { - "safe": [100, 500], - "warn": [50, 600], - "critical": [0, 800] - }, - "postburn": { - "safe": [0, 1000], - "warn": [0, 1001], - "critical": [0, 1002] - } - }, - "pin": 15 - }, - "PT-7": { - "kalman_args": { - "process_variance": 0.01, - "measurement_variance": 0.02, - "kalman_value": 1000 - }, - "boundaries": { - "waiting": { - "safe": [-20, 50], - "warn": [-30, 75], - "critical": [-50, 100] - }, - "pressurization": { - "safe": [693, 806], - "warn": [637, 862], - "critical": [0, 1000] - }, - "autosequence": { - "safe": [100, 500], - "warn": [50, 600], - "critical": [0, 800] - }, - "postburn": { - "safe": [0, 1000], - "warn": [0, 1001], - "critical": [0, 1002] - } - }, - "pin": 16 - }, - "PT-8": { - "kalman_args": { - "process_variance": 0.01, - "measurement_variance": 0.02, - "kalman_value": 1000 - }, - "boundaries": { - "waiting": { - "safe": [-20, 50], - "warn": [-30, 75], - "critical": [-50, 100] - }, - "pressurization": { - "safe": [-20, 50], - "warn": [-30, 75], - "critical": [-50, 100] - }, - "autosequence": { - "safe": [100, 800], - "warn": [50, 900], - "critical": [0, 1000] - }, - "postburn": { - "safe": [0, 1000], - "warn": [0, 1001], - "critical": [0, 1002] - } - }, - "pin": 17 - }, - "PT-1": { - "kalman_args": { - "process_variance": 0.01, - "measurement_variance": 0.02, - "kalman_value": 1000 - }, - "boundaries": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600], - "waiting": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] - }, - "pressurization": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] - }, - "autosequence": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] - }, - "postburn": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] - } - }, - "pin": 14 - }, - "PT-2": { - "kalman_args": { - "process_variance": 0.01, - "measurement_variance": 0.02, - "kalman_value": 1000 - }, - "boundaries": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600], - "waiting": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] - }, - "pressurization": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] - }, - "autosequence": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] - }, - "postburn": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] + "telemetry": { + "GS_IP": "127.0.0.1", + "GS_PORT": 5005, + "DELAY": 0.1, + "SOCKETIO_HOST": "127.0.0.1", + "SOCKETIO_PORT": 5000, + "XBEE_RX_PIN": 10, + "XBEE_TX_PIN": 11, + "XBEE_BAUD_RATE": 9600 + }, + "sensors": { + "list": { + "thermocouple": { + "Thermo-1": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "waiting": { + "safe": [100, 500], + "warn": [50, 550] + }, + "pressurization": { + "safe": [100, 500], + "warn": [50, 550] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 550] + }, + "postburn": { + "safe": [100, 500], + "warn": [50, 550] + } + }, + "thermo_pins": [33, 0, 1, 32] + } + }, + "pressure": { + "PT-5": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "waiting": { + "safe": [100, 500], + "warn": [50, 550] + }, + "pressurization": { + "safe": [100, 500], + "warn": [50, 550] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 550] + }, + "postburn": { + "safe": [100, 500], + "warn": [50, 550] + } + }, + "pressure_pin": 10 + }, + "PT-P": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "waiting": { + "safe": [100, 500], + "warn": [50, 550] + }, + "pressurization": { + "safe": [100, 500], + "warn": [50, 550] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 550] + }, + "postburn": { + "safe": [100, 500], + "warn": [50, 550] + } + }, + "pressure_pin": 15 + }, + "PT-7": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "waiting": { + "safe": [100, 500], + "warn": [50, 550] + }, + "pressurization": { + "safe": [100, 500], + "warn": [50, 550] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 550] + }, + "postburn": { + "safe": [100, 500], + "warn": [50, 550] + } + }, + "pressure_pin": 16 + }, + "PT-8": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "waiting": { + "safe": [100, 500], + "warn": [50, 550] + }, + "pressurization": { + "safe": [100, 500], + "warn": [50, 550] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 550] + }, + "postburn": { + "safe": [100, 500], + "warn": [50, 550] + } + }, + "pressure_pin": 17 + } } - }, - "pin": 15 }, - "PT-3": { - "kalman_args": { - "process_variance": 0.01, - "measurement_variance": 0.02, - "kalman_value": 1000 - }, - "boundaries": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600], - "waiting": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] - }, - "pressurization": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] - }, - "autosequence": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] - }, - "postburn": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] - } - }, - "pin": 16 - }, - "PT-4": { - "kalman_args": { - "process_variance": 0.01, - "measurement_variance": 0.02, - "kalman_value": 1000 - }, - "boundaries": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600], - "waiting": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] - }, - "pressurization": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] - }, - "autosequence": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] - }, - "postburn": { - "safe": [100, 500], - "warn": [50, 550], - "critical": [0, 600] + "address": "/dev/ttyACM0", + "baud": 115200, + "send_interval": 0.5 + }, + "valves": { + "list": { + "solenoid": { + "ethanol_pressurization": { + "label": "NCSV-1", + "pin": 4, + "natural": "CLOSED", + "special": true + }, + "ethanol_vent": { + "label": "NCSV-2", + "pin": 39, + "natural": "CLOSED", + "special": true + }, + "ethanol_mpv": { + "label": "NCSV-3", + "pin": 6, + "natural": "CLOSED", + "special": true + }, + "nitrous_pressurization": { + "label": "NCSV-4", + "pin": 5, + "natural": "CLOSED", + "special": true + }, + "nitrous_fill": { + "label": "NOSV-1", + "pin": 11, + "natural": "OPEN", + "special": false + }, + "nitrous_mpv": { + "label": "NCSV-5", + "pin": 9, + "natural": "CLOSED", + "special": true } - }, - "pin": 17 } - } + }, + "address": "/dev/ttyACM1", + "baud": 115200, + "send_interval": 0.5 }, - "address": "/dev/ttyACM0", - "baud": 115200, - "send_interval": 0.5 - }, - "valves": { - "list": { - "solenoid": { - "pressurization_valve": { - "pin": 5, - "natural": "CLOSED", - "special": true - }, - "vent_valve": { - "pin": 6, - "natural": "OPEN", - "special": false - }, - "remote_drain_valve": { - "pin": 7, - "natural": "OPEN", - "special": true - }, - "main_propellant_valve": { - "pin": 8, - "natural": "CLOSED", - "special": true - } - } + "stages": { + "list": ["waiting", "pressurization", "autosequence", "postburn"], + "request_interval": 10, + "send_interval": 2 + }, + "timer": { + "delay": 0.001 + }, + "pressure_control": { + "active_stages": ["pressurization", "autosequence", "postburn"] + }, + "arduino_type": "real", + "task_config": { + "tasks": ["sensor", "valve", "telemetry"], + "control_tasks": ["sensor", "valve", "telemetry"] + }, + "UI": { + "data_cutoff": 30, + "message_cutoff": 10 }, - "address": "/dev/ttyACM1", - "baud": 115200, - "send_interval": 0.5 - }, - "stages": { - "list": ["waiting", "pressurization", "autosequence", "postburn"], - "request_interval": 10, - "send_interval": 2 - }, - "timer": { - "delay": 0.001 - }, - "pressure_control": { - "active_stages": ["pressurization", "autosequence", "postburn"] - }, - "arduino_type": "real", - "task_config": { - "tasks": ["sensor", "telemetry", "valve"], - "control_tasks": ["sensor", "telemetry", "valve", "stage", "pressure"] - }, - "UI": { - "data_cutoff": 30, - "message_cutoff": 10 - }, - "Authorized_IPs": ["localhost"] + "Authorized_IPs": ["localhost"] } diff --git a/client/src/lib/getColor.ts b/client/src/lib/getColor.ts index 34ffe25..d51860d 100644 --- a/client/src/lib/getColor.ts +++ b/client/src/lib/getColor.ts @@ -1,7 +1,7 @@ import caelusLogger from "./caelusLogger"; const getColor = (status: any) => { - if(status == undefined){ + if(status === undefined){ return "black"; } switch (status) { diff --git a/client/src/lib/locationNames.ts b/client/src/lib/locationNames.ts index 484df64..2ab0d6e 100644 --- a/client/src/lib/locationNames.ts +++ b/client/src/lib/locationNames.ts @@ -32,9 +32,16 @@ export const valveTypeNames = { }; export const valveLocationNames = { - main_propellant_valve: "Main Propellant Valve", - pressure_relief: "Pressure Relief Valve", - pressurization: "Pressurization Valve", + ethanol_drain: "Ethanol Drain", + ethanol_pressurization: "Ethanol Pressurization", + ethanol_vent: "Ethanol Vent", + ethanol_mpv: "Ethanol MPV", + ethanol_fill: "Ethanol Fill", + nitrous_drain: "Nitrous Drain", + nitrous_pressurization: "Nitrous Pressurization", + nitrous_vent: "Nitrous Vent", + nitrous_mpv: "Nitrous MPV", + nitrous_fill: "Nitrous Fill", }; export const actuationTypeNames = { diff --git a/client/src/lib/pid.js b/client/src/lib/pid.js index 3d30f07..108c10a 100644 --- a/client/src/lib/pid.js +++ b/client/src/lib/pid.js @@ -33,19 +33,19 @@ export const PADDING = { }, }, VALVE: { - pressurization_valve: { + nitrous_pressurization: { x: 404 / 784, y: 210 / 850, }, - vent_valve: { + nitrous_vent: { x: 33 / 784, y: 95 / 850, }, - remote_drain_valve: { + nitrous_fill: { x: 19 / 784, y: 598 / 850, }, - main_propellant_valve: { + nitrous_mpv: { x: 317 / 784, y: 736 / 850, }, @@ -75,15 +75,15 @@ export const PADDING = { }, }, VALVE: { - "NCSV-1": { + ethanol_vent: { x: 274 / 1971, y: 91 / 1522, }, - "NOSV-2": { + ethanol_mpv: { x: 347 / 1971, y: 517 / 1522, }, - pressurization_valve: { + ethanol_pressurization: { x: 52 / 1971, y: 1375 / 1522, }, @@ -137,35 +137,35 @@ export const PADDING = { }, }, VALVE: { - vent_valve: { + nitrous_vent: { x: 136 / 3200, y: 104 / 1595, }, - pressurization_valve: { + nitrous_pressurization: { x: 619 / 3200, y: 716 / 1595, }, - remote_drain_valve: { + nitrous_fill: { x: 669 / 3200, y: 1163 / 1595, }, - main_propellant_valve: { + nitrous_mpv: { x: 447 / 3200, y: 1385 / 1595, }, - "NCSV-1": { + ethanol_vent: { x: 2187 / 3200, y: 133 / 1595, }, - "NOSV-1": { + ethanol_pressurization: { x: 2756 / 3200, y: 571 / 1595, }, - "NCSV-2": { + ethanol_fill: { x: 2269 / 3200, y: 1478 / 1595, }, - "NOSV-2": { + ethanol_mpv: { x: 1969 / 3200, y: 1152 / 1595, }, diff --git a/client/src/old_config.json b/client/src/old_config.json new file mode 100644 index 0000000..c37aa6f --- /dev/null +++ b/client/src/old_config.json @@ -0,0 +1,321 @@ +{ + "telemetry": { + "GS_IP": "127.0.0.1", + "GS_PORT": 5005, + "DELAY": 0.1, + "SOCKETIO_HOST": "127.0.0.1", + "SOCKETIO_PORT": 5000 + }, + "sensors": { + "list": { + "thermocouple": {}, + "pressure": { + "PT-5": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "waiting": { + "safe": [-20, 50], + "warn": [-30, 75], + "critical": [-50, 100] + }, + "pressurization": { + "safe": [693, 806], + "warn": [637, 862], + "critical": [0, 1000] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 600], + "critical": [0, 800] + }, + "postburn": { + "safe": [0, 1000], + "warn": [0, 1001], + "critical": [0, 1002] + } + }, + "pin": 14 + }, + "PT-P": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "waiting": { + "safe": [693, 806], + "warn": [637, 862], + "critical": [0, 1000] + }, + "pressurization": { + "safe": [693, 806], + "warn": [637, 862], + "critical": [0, 1000] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 600], + "critical": [0, 800] + }, + "postburn": { + "safe": [0, 1000], + "warn": [0, 1001], + "critical": [0, 1002] + } + }, + "pin": 15 + }, + "PT-7": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "waiting": { + "safe": [-20, 50], + "warn": [-30, 75], + "critical": [-50, 100] + }, + "pressurization": { + "safe": [693, 806], + "warn": [637, 862], + "critical": [0, 1000] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 600], + "critical": [0, 800] + }, + "postburn": { + "safe": [0, 1000], + "warn": [0, 1001], + "critical": [0, 1002] + } + }, + "pin": 16 + }, + "PT-8": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "waiting": { + "safe": [-20, 50], + "warn": [-30, 75], + "critical": [-50, 100] + }, + "pressurization": { + "safe": [-20, 50], + "warn": [-30, 75], + "critical": [-50, 100] + }, + "autosequence": { + "safe": [100, 800], + "warn": [50, 900], + "critical": [0, 1000] + }, + "postburn": { + "safe": [0, 1000], + "warn": [0, 1001], + "critical": [0, 1002] + } + }, + "pin": 17 + }, + "PT-1": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600], + "waiting": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + }, + "pressurization": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + }, + "postburn": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + } + }, + "pin": 14 + }, + "PT-2": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600], + "waiting": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + }, + "pressurization": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + }, + "postburn": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + } + }, + "pin": 15 + }, + "PT-3": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600], + "waiting": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + }, + "pressurization": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + }, + "postburn": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + } + }, + "pin": 16 + }, + "PT-4": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600], + "waiting": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + }, + "pressurization": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + }, + "postburn": { + "safe": [100, 500], + "warn": [50, 550], + "critical": [0, 600] + } + }, + "pin": 17 + } + } + }, + "address": "/dev/ttyACM0", + "baud": 115200, + "send_interval": 0.5 + }, + "valves": { + "list": { + "solenoid": { + "ethanol_pressurization": { + "pin": 5, + "natural": "CLOSED", + "special": true + }, + "vent_valve": { + "pin": 6, + "natural": "OPEN", + "special": false + }, + "remote_drain_valve": { + "pin": 7, + "natural": "OPEN", + "special": true + }, + "main_propellant_valve": { + "pin": 8, + "natural": "CLOSED", + "special": true + } + } + }, + "address": "/dev/ttyACM1", + "baud": 115200, + "send_interval": 0.5 + }, + "stages": { + "list": ["waiting", "pressurization", "autosequence", "postburn"], + "request_interval": 10, + "send_interval": 2 + }, + "timer": { + "delay": 0.001 + }, + "pressure_control": { + "active_stages": ["pressurization", "autosequence", "postburn"] + }, + "arduino_type": "real", + "task_config": { + "tasks": ["sensor", "telemetry", "valve"], + "control_tasks": ["sensor", "telemetry", "valve", "stage", "pressure"] + }, + "UI": { + "data_cutoff": 30, + "message_cutoff": 10 + }, + "Authorized_IPs": ["localhost"] +} diff --git a/client/src/panes/ButtonPane.tsx b/client/src/panes/ButtonPane.tsx index 3e08b32..4ba5cd5 100644 --- a/client/src/panes/ButtonPane.tsx +++ b/client/src/panes/ButtonPane.tsx @@ -160,8 +160,9 @@ const ButtonPane = () => { }, [currentStage]); // If u click on a closed view, it opens. If it's already opened, it closes. - const switchView = (name: keyof typeof views) => + const switchView = (name: keyof typeof views) => { setViews({ ...views, [name]: !views[name] }); + } const actuationTypeRef = useRef(null); const actuationPriorityRef = useRef(null); diff --git a/server/config.json b/server/config.json index f72ff70..bf7bda2 100644 --- a/server/config.json +++ b/server/config.json @@ -1,163 +1,194 @@ { "telemetry": { "GS_IP": "127.0.0.1", - "GS_PORT": 5005, + "SOCKET_PORT": 5005, "DELAY": 0.1, "SOCKETIO_HOST": "127.0.0.1", - "SOCKETIO_PORT": 5000 + "SOCKETIO_PORT": 5000, + "XBEE_PORT": "/dev/ttyUSB0", + "XBEE_BAUD_RATE": 9600, + "USING_XBEE": true }, "sensors": { - "list": { - "pressure": { - "PT-5": { - "kalman_args": { - "process_variance": 0.01, - "measurement_variance": 0.02, - "kalman_value": 1000 - }, - "boundaries": { - "waiting": { - "safe": [-20, 50], - "warn": [-30, 75], - "critical": [-50, 100] - }, - "pressurization": { - "safe": [693, 806], - "warn": [637, 862], - "critical": [0, 1000] - }, - "autosequence": { - "safe": [100, 500], - "warn": [50, 600], - "critical": [0, 800] - }, - "postburn": { - "safe": [0, 1000], - "warn": [0, 1001], - "critical": [0, 1002] - } - }, - "pin": 14 - }, - "PT-P": { - "kalman_args": { - "process_variance": 0.01, - "measurement_variance": 0.02, - "kalman_value": 1000 - }, - "boundaries": { - "waiting": { - "safe": [693, 806], - "warn": [637, 862], - "critical": [0, 1000] - }, - "pressurization": { - "safe": [693, 806], - "warn": [637, 862], - "critical": [0, 1000] - }, - "autosequence": { - "safe": [100, 500], - "warn": [50, 600], - "critical": [0, 800] - }, - "postburn": { - "safe": [0, 1000], - "warn": [0, 1001], - "critical": [0, 1002] - } - }, - "pin": 15 - }, - "PT-7": { - "kalman_args": { - "process_variance": 0.01, - "measurement_variance": 0.02, - "kalman_value": 1000 - }, - "boundaries": { - "waiting": { - "safe": [-20, 50], - "warn": [-30, 75], - "critical": [-50, 100] - }, - "pressurization": { - "safe": [693, 806], - "warn": [637, 862], - "critical": [0, 1000] - }, - "autosequence": { - "safe": [100, 500], - "warn": [50, 600], - "critical": [0, 800] - }, - "postburn": { - "safe": [0, 1000], - "warn": [0, 1001], - "critical": [0, 1002] + "list": { + "thermocouple": { + "Thermo-1": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "waiting": { + "safe": [100, 500], + "warn": [50, 550] + }, + "pressurization": { + "safe": [100, 500], + "warn": [50, 550] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 550] + }, + "postburn": { + "safe": [100, 500], + "warn": [50, 550] + } + }, + "thermo_pins": [33, 0, 1, 32] } }, - "pin": 16 - }, - "PT-8": { - "kalman_args": { - "process_variance": 0.01, - "measurement_variance": 0.02, - "kalman_value": 1000 - }, - "boundaries": { - "waiting": { - "safe": [-20, 50], - "warn": [-30, 75], - "critical": [-50, 100] + "pressure": { + "PT-5": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "waiting": { + "safe": [100, 500], + "warn": [50, 550] + }, + "pressurization": { + "safe": [100, 500], + "warn": [50, 550] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 550] + }, + "postburn": { + "safe": [100, 500], + "warn": [50, 550] + } + }, + "pressure_pin": 10 }, - "pressurization": { - "safe": [-20, 50], - "warn": [-30, 75], - "critical": [-50, 100] + "PT-P": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "waiting": { + "safe": [100, 500], + "warn": [50, 550] + }, + "pressurization": { + "safe": [100, 500], + "warn": [50, 550] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 550] + }, + "postburn": { + "safe": [100, 500], + "warn": [50, 550] + } + }, + "pressure_pin": 15 }, - "autosequence": { - "safe": [100, 800], - "warn": [50, 900], - "critical": [0, 1000] + "PT-7": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "waiting": { + "safe": [100, 500], + "warn": [50, 550] + }, + "pressurization": { + "safe": [100, 500], + "warn": [50, 550] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 550] + }, + "postburn": { + "safe": [100, 500], + "warn": [50, 550] + } + }, + "pressure_pin": 16 }, - "postburn": { - "safe": [0, 1000], - "warn": [0, 1001], - "critical": [0, 1002] + "PT-8": { + "kalman_args": { + "process_variance": 0.01, + "measurement_variance": 0.02, + "kalman_value": 1000 + }, + "boundaries": { + "waiting": { + "safe": [100, 500], + "warn": [50, 550] + }, + "pressurization": { + "safe": [100, 500], + "warn": [50, 550] + }, + "autosequence": { + "safe": [100, 500], + "warn": [50, 550] + }, + "postburn": { + "safe": [100, 500], + "warn": [50, 550] + } + }, + "pressure_pin": 17 } - }, - "pin": 17 - } - } - }, - "address": "/dev/ttyACM0", - "baud": 115200, - "send_interval": 0.5 + } + }, + "address": "/dev/ttyACM0", + "baud": 115200, + "send_interval": 0.5 }, "valves": { "list": { "solenoid": { - "pressurization_valve": { - "pin": 5, + "ethanol_pressurization": { + "label": "NCSV-1", + "pin": 4, "natural": "CLOSED", "special": true }, - "vent_valve": { - "pin": 6, - "natural": "OPEN", - "special": false - }, - "remote_drain_valve": { - "pin": 7, - "natural": "OPEN", + "ethanol_vent": { + "label": "NCSV-2", + "pin": 39, + "natural": "CLOSED", "special": true }, - "main_propellant_valve": { - "pin": 8, + "ethanol_mpv": { + "label": "NCSV-3", + "pin": 6, "natural": "CLOSED", "special": true - } + }, + "nitrous_pressurization": { + "label": "NCSV-4", + "pin": 5, + "natural": "CLOSED", + "special": true + }, + "nitrous_fill": { + "label": "NOSV-1", + "pin": 11, + "natural": "OPEN", + "special": false + }, + "nitrous_mpv": { + "label": "NCSV-5", + "pin": 9, + "natural": "CLOSED", + "special": true + } } }, "address": "/dev/ttyACM1", @@ -177,10 +208,12 @@ }, "arduino_type": "real", "task_config": { - "tasks": ["sensor", "telemetry", "valve"], - "control_tasks": ["sensor", "telemetry", "valve", "stage", "pressure"] + "tasks": ["sensor", "valve", "telemetry"], + "control_tasks": ["sensor", "valve", "telemetry"] }, "UI": { - "data_cutoff": 30 - } + "data_cutoff": 30, + "message_cutoff": 10 + }, + "Authorized_IPs": ["localhost"] } diff --git a/server/enums.py b/server/enums.py index d75481c..f7444fb 100644 --- a/server/enums.py +++ b/server/enums.py @@ -32,9 +32,14 @@ class ValveType(str, Enum): class ValveLocation(str, Enum): - PRESSURE_RELIEF = "pressure_relief" - PRESSURIZATION = "pressurization" - MAIN_PROPELLANT_VALVE = "main_propellant_valve" + ETHANOL_DRAIN = "ethanol_drain" + ETHANOL_PRESSURIZATION = "ethanol_pressurization" + ETHANOL_VENT = "ethanol_vent" + ETHANOL_MPV = "ethanol_mpv" + NITROUS_DRAIN = "nitrous_drain" + NITROUS_PRESSURIZATION = "nitrous_pressurization" + NITROUS_VENT = "nitrous_vent" + NITROUS_MPV = "nitrous_mpv" class ActuationType(IntEnum): diff --git a/server/handler.py b/server/handler.py index 7708a97..82c2499 100644 --- a/server/handler.py +++ b/server/handler.py @@ -1,21 +1,23 @@ from queue import Empty, Queue import time import heapq -import socket +import serial import threading +import serial from typing import Any, List, Tuple, Union from packet import Packet, Log, LogPriority from flask_socketio import Namespace -import traceback -BYTE_SIZE = 16384 + +BYTE_SIZE = 8192 DELAY = .05 -DELAY_LISTEN = .05 -DELAY_SEND = .05 +DELAY_LISTEN = .005 +DELAY_SEND = 2 DELAY_HEARTBEAT = 3 SEND_ALLOWED = True + BLOCK_SIZE = 32 f = open("black_box.txt", "w+") f.close() @@ -24,11 +26,12 @@ class Handler(Namespace): """ Handles all communication """ - def init(self, ip, port, socketio): + def init(self, gs_port, baud_rate): """ Based on given IP and port, create and connect a socket """ """ A heapqueue of packets to send """ self.queue_send: List[Tuple[str, str]] = [] + self.rcvd_data = "" self.send_thread = threading.Thread(target=self.send, daemon=True) self.send_thread.daemon = True @@ -42,42 +45,30 @@ def init(self, ip, port, socketio): self.ingest_thread = threading.Thread(target=self.ingest_loop, daemon=True) self.ingest_thread.daemon = True - self.conn = None + self.ser = None self.running = False + self.INITIAL_TIME = -100 - self.socketio = socketio - self.socketio.on_event( - 'json', - self.send_to_flight_software - ) - - self.connect(ip, port) - self.INITIAL_TIME = time.time() + try: + self.ser = serial.Serial(gs_port, baud_rate) + self.ser.flushInput() + self.ser.flushOutput() + self.INITIAL_TIME = time.time() + print("Finished connecting") + + except Exception as e: + print("ERROR:", e) + self.running = False self.general_copy = None self.sensors_copy = None self.valves_copy = None self.buttons_copy = None - ## telemetry methods - - def connect(self, ip, port): - # Server-side socket - self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - - # Binds to the provided IP and port - print("IP:", ip, "PORT:", port) - self.sock.bind((ip, port)) - - # Listens for connections, allowing at most 1 pending connection - self.sock.listen(1) - - # Accept a connection - (self.conn, _addr) = self.sock.accept() - - print("Finished connecting") + self.rcvd = "" + self.heartbeat_packet_number = 0 + ## telemetry methods def begin(self): """ Starts the send and listen threads """ @@ -89,36 +80,59 @@ def begin(self): def send_to_flight_software(self, json): - log = Log(header=json['header'], message=json['message'], timestamp=time.time()-self.INITIAL_TIME) + log = Log(header=json['header'], message=json['message'], timestamp=round(time.time()-self.INITIAL_TIME, 3)) self.enqueue(Packet(logs=[log], timestamp=log.timestamp)) def send(self): - """ Constantly sends next packet from queue to ground station """ + """ Constantly sends next packet from queue to flight software """ while self.running: try: if self.queue_send and SEND_ALLOWED: - _, encoded = heapq.heappop(self.queue_send) - self.conn.send(encoded) - print("Sending:", encoded) - time.sleep(DELAY_SEND) + _, packet_str = heapq.heappop(self.queue_send) + + subpackets = [packet_str[i:60+i] for i in range(0, len(packet_str), 60)] #split into smaller packets of 255 + + for subpacket in subpackets: + self.ser.write(subpacket) + + + print("\nSent packet:", packet_str, len(packet_str)) + time.sleep(DELAY_SEND) + except Exception as e: - print("ERROR: ", e) + print("ERROR:", e) self.running = False def listen(self): """ Constantly listens for any from ground station """ while self.running: - data = self.conn.recv(BYTE_SIZE) + # print("HI") + # print(self.ser.in_waiting) + # print(self.ser.read(self.ser.in_waiting)) + # self.ser.flushInput() + data = self.ser.read(self.ser.in_waiting).decode() if data: - # print("ME LIKEYYYYYY") - self.ingest_queue.put(data) - + self.rcvd += data + + packet_start = self.rcvd.find("^") + if packet_start != -1: + packet_end = self.rcvd.find("$", packet_start) + if packet_end != -1: + incoming_packet = self.rcvd[packet_start+1:packet_end] + print("\nRecived:", incoming_packet) + + + self.ingest_queue.put(incoming_packet) + + self.rcvd = self.rcvd[packet_end+1:] + + time.sleep(DELAY_LISTEN) def enqueue(self, packet): """ Encrypts and enqueues the given Packet """ # TODO: This is implemented wrong. It should enqueue by finding packets that have similar priorities, not changing the priorities of current packets. - packet_str = (packet.to_string() + "END").encode("ascii") + packet_str = ("^" + packet.to_string() + "$").encode("ascii") heapq.heappush(self.queue_send, (packet.priority, packet_str)) @@ -128,48 +142,35 @@ def ingest_loop(self): # block=True waits until an item is available # We add a timeout so the loop can stop try: - if not self.ingest_queue.empty(): - # print("dfjkGOOOOOD") - data = self.ingest_queue.get(block=True, timeout=1) - self.ingest(data) - except Exception as e: - # print('SDJFKKKKKKK=-----------------------------------------') - # print(e) - traceback.print_exc() + data = self.ingest_queue.get(block=True, timeout=1) + self.ingest(data) + except Empty: + pass def ingest(self, packet_str): """ Prints any packets received """ - try: - packet_str = packet_str.decode() - print("Received: " + packet_str) - packet_strs = packet_str.split("END")[:-1] - # print('AAAAAAAAAAAAAAAJJJJJJJJJJJJJJJJ') - packets = [Packet.from_string(p_str) for p_str in packet_strs] - for packet in packets: - for log in packet.logs: - log.timestamp = round(log.timestamp, 1) #########CHANGE THIS TO BE TIMESTAMP - START TIME IF PYTHON - if "heartbeat" in log.header or "stage" in log.header or "response" in log.header or "mode" in log.header: - self.update_general(log.__dict__) - - if "sensor_data" in log.header: - self.update_sensor_data(log.__dict__) - - if "valve_data" in log.header: - self.update_valve_data(log.__dict__) - - log.save() + packet = Packet.from_string(packet_str) + for log in packet.logs: + log.timestamp = round(log.timestamp, 1) #########CHANGE THIS TO BE TIMESTAMP - START TIME IF PYTHON + if "heartbeat" in log.header or "stage" in log.header or "response" in log.header or "mode" in log.header: + self.update_general(log.__dict__) - except Exception as e: - # print('ohFN ODSNOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO') - # print(e) - traceback.print_exc() + if "sensor_data" in log.header: + self.update_sensor_data(log.__dict__) + + if "valve_data" in log.header: + self.update_valve_data(log.__dict__) + + log.save() def heartbeat(self): """ Constantly sends heartbeat message """ + time.sleep(1) while self.running: - # TODO: WHY IS THERE A MESSAGE? - log = Log(header="heartbeat", message={}, timestamp=time.time()-self.INITIAL_TIME) + log = Log(header="heartbeat", message="AT - " + str(self.heartbeat_packet_number), timestamp=round(time.time()-self.INITIAL_TIME, 3)) + self.heartbeat_packet_number += 1 + self.enqueue(Packet(logs=[log], priority=LogPriority.INFO, timestamp=log.timestamp)) # print("Sent heartbeat") time.sleep(DELAY_HEARTBEAT) @@ -195,7 +196,6 @@ def update_store_data(self): self.socketio.emit('sensors_copy', self.sensors_copy) self.socketio.emit('valves_copy', self.valves_copy) self.socketio.emit('buttons_copy', self.buttons_copy) - self.socketio.emit('initial_time', self.INITIAL_TIME) ## store copy methods def update_general_copy(self, general): @@ -211,7 +211,7 @@ def update_buttons_copy(self, buttons): self.buttons_copy = buttons def on_button_press(self, data): - log_send('button', data) + # log_send('button', data) if data['header'] == 'update_general': self.update_general_copy(data['message']) elif data['header'] == 'update_sensors': @@ -223,12 +223,11 @@ def on_button_press(self, data): elif data['header'] == 'store_data': self.update_store_data() else: - print(data) - log = Log(header=data['header'], message=data['message'], timestamp=time.time()-self.INITIAL_TIME) - self.enqueue(Packet(logs=[log], priority=LogPriority.INFO, timestamp=log.timestamp)) + print("\n", data) + log = Log(header=data['header'], message=data['message']) + self.enqueue(Packet(logs=[log], priority=LogPriority.INFO)) -hidden_log_types = set() # {"general", "sensor", "valve", "button"} +hidden_log_types = {"general", "sensor", "valve", "button"} def log_send(type, log): if type not in hidden_log_types: - # print(f"Sending [{type}] {log}") - pass \ No newline at end of file + print(f"\nSending [{type}] {log}") \ No newline at end of file diff --git a/server/main.py b/server/main.py index 23a5b19..2ee4ec3 100644 --- a/server/main.py +++ b/server/main.py @@ -9,7 +9,6 @@ import argparse - log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) @@ -36,8 +35,8 @@ config = json.loads(open("config.json").read()) -GS_IP = config["telemetry"]["GS_IP"] -GS_PORT = config["telemetry"]["GS_PORT"] +BAUD_RATE = config["telemetry"]["XBEE_BAUD_RATE"] +GS_PORT = config["telemetry"]["XBEE_PORT"] app = Flask(__name__, static_folder="templates") CORS(app) @@ -46,11 +45,11 @@ time.sleep(1) if __name__ == "__main__": - print("listening and sending") - + handler = Handler('/') - handler.init(GS_IP, GS_PORT, socketio) + handler.init(GS_PORT, BAUD_RATE) handler.begin() + print("listening and sending") socketio.on_namespace(handler) socketio.run(app, host=config["telemetry"]["SOCKETIO_HOST"], port=int(config["telemetry"]["SOCKETIO_PORT"])) diff --git a/server/packet.py b/server/packet.py index 9f6796a..5207c2a 100644 --- a/server/packet.py +++ b/server/packet.py @@ -102,6 +102,9 @@ def from_string(input_string): or {... 'logs': ['{json string stuff}', '{second json string}', ...] ...} \n \ Given json: " + input_string) + for i in range(len(real_logs)): + if isinstance(real_logs[i]["message"], str): + real_logs[i]["message"] = json.loads(real_logs[i]["message"]) # String to dict return Packet( [ Log(log["header"], log["message"], log["timestamp"]) diff --git a/server/serial_test.py b/server/serial_test.py new file mode 100644 index 0000000..cb668bd --- /dev/null +++ b/server/serial_test.py @@ -0,0 +1,21 @@ +import serial +import threading +import time + +PORT = "/dev/ttyUSB0" # change if needed +BAUD_RATE = 9600 +ser = serial.Serial(PORT, BAUD_RATE) + +def listen(): + while True: + data = ser.read(ser.in_waiting) + if data: print("Recived:", data.decode()) + time.sleep(0.05) + +listen_thread = threading.Thread(target=listen, daemon=True) +listen_thread.start() + +while True: + data = input() + ser.write(data.encode()) + print("sent:", data) diff --git a/server/test.py b/server/test.py new file mode 100644 index 0000000..3fd692b --- /dev/null +++ b/server/test.py @@ -0,0 +1,9 @@ +import serial +import time + +ser = serial.Serial("COM6", 9600) +while True: + data = self.ser.read(self.ser.in_waiting).decode() + if data: + print("Just got:", data) + time.sleep(0.1)