Control Box code section in readme

This commit is contained in:
judsonupchurch 2025-01-16 20:26:12 -06:00
parent 27c2c156f3
commit 49b5934d79
2 changed files with 186 additions and 0 deletions

12
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,12 @@
{
"configurations": [
{
"type": "cmake",
"request": "launch",
"name": "Debug portfile(s)",
"cmakeDebugType": "external",
"pipeName": "\\\\.\\pipe\\vcpkg_ext_portfile_dbg",
"preLaunchTask": "Debug vcpkg commands"
}
]
}

174
README.md
View File

@ -79,7 +79,181 @@ The actuator box is responsible for actuating valves on the oxidizer fluid panel
<img src=readme_media/actuator_box/assembled_actuator_iso.jpg width="500">
# Arduino Software
## Common Software
### CAN Comms
For the peer to peer communication between the Control Box and the Actuator Box, the Controller Area Network (CAN) Bus was chosen for its amazing signal integrity and simple to use libraries with Arduino. Key features in this use case are the 8 byte frames sending unsigned chars and the can_id unsigned integer which designates the type of packet being sent.
On startup (and communication loss from a power outage, random restart, or CAN harness disconnect), the devices go through a 2-way handshake that consists of the control box sending a ping, the actuator box replying to the ping, and the control box acknowledging the reply.
For the packet structure, the formatting can be found [here](Code/Packet%20Formatting.txt).
## Control Box
### Logic Diagram
<img src=readme_media/control_box/control_software_1.png width="500">
<img src=readme_media/control_box/control_software_2.png width="500">
### Custom LCD Class
To help manage the text on the 20x4 LCD, a custom class was created.
```cpp
class LCD {
private:
// An array of strings. Each element represents what is currently being shown on the row
String current_text[4] = {"", "", "", ""};
// What we will want to update the LCD with
String desired_text[4] = {"", "", "", ""};
// Keep track of any blank lines
bool blank_rows[4] = {true, true, true, true};
public:
LCD();
// Clear the entire LCD
void clear_lcd();
// Clear only the line as specified in int row (indexed at 0)
void clear_lcd_line(int row);
// Update the physical LCD with the text stored in self->desired_text
void set_lcd_to_desired_text();
// Add a string to the self->desired_text arraw at the specified row
int add_string_to_desired_text(String to_add, int row = -1);
// Helper function to check string is in self->desired_text
int check_if_already_in_desired_text(String to_add);
// Clear the self->desired_text
void clear_desired_text(int row = -1);
};
```
### LED Groups Based on Relay Type
With the display board having multiple LEDs for different types of relays, as well as a slightly different byte structure being reported from the actuator box to signify different states or fails, custom classes were made to handle the groups of LEDs and writing LCD messages.
#### Non-Latching Relay Display
```cpp
class NonLatchingRelayDisplays {
private:
// Represents if the AB saw the on signal and set the pin HIGH
unsigned int relay_led_pin;
// Represents if the AB actually saw a voltage across the relay and thinks the valve was opened
unsigned int state_led_pin;
// So our LCD messages have meaning
String name;
// If we come across a pin error state, update this string so the LCD can find it and print it
String pin_error_message = "";
// If we come across a relay error state, update this string so the LCD can find it and print it
String relay_error_message = "";
public:
// The row that the error message is on the LCD. -1 means it is not on the LCD
int pin_error_message_row = -1;
// The row that the error message is on the LCD. -1 means it is not on the LCD
int relay_error_message_row = -1;
NonLatchingRelayDisplays (unsigned int relay_led_pin,
unsigned int state_led_pin,
String name);
String get_pin_error_message();
String get_relay_error_message();
// Sets the desired and actual LEDs as given by the status byte from CAN
// If there is an error signified in the byte, write to the LCD
void control_leds(unsigned int status);
};
```
#### Latching Relay Display
The latching relay is the exact same as the non-latching relay besides some differences in error messages. For example, the latching relay could have a pin failure for the SET or RESET pin while the non-latching relay can only have a SET pin.
```cpp
class LatchingRelayDisplays {
private:
// Represents if the AB saw the on signal and set the pin HIGH
unsigned int relay_led_pin;
// Represents if the AB actually saw a voltage across the relay and thinks the valve was opened
unsigned int state_led_pin;
// So our LCD messages have meaning
String name;
// If we come across a pin error state, update this string so the LCD can find it and print it
String pin_error_message = "";
// If we come across a relay error state, update this string so the LCD can find it and print it
String relay_error_message = "";
public:
// The row that the error message is on the LCD. -1 means it is not on the LCD
int pin_error_message_row = -1;
// The row that the error message is on the LCD. -1 means it is not on the LCD
int relay_error_message_row = -1;
LatchingRelayDisplays (unsigned int relay_led_pin,
unsigned int state_led_pin,
String name);
String get_pin_error_message();
String get_relay_error_message();
// Sets the desired and actual LEDs as given by the status byte from CAN
// If there is an error signified in the byte, write to the LCD
void control_leds(unsigned int status);
};
```
#### Latching Solenoid Display
The latching solenoid controls 2 relays, so it gets 2 bytes from CAN and has more complex error messages.
```cpp
class LatchingSolenoidDisplays {
private:
// Represents if the AB saw the on signal and set the pin HIGH
unsigned int relay_led_pin;
// Represents if the AB actually saw a voltage across the relay and thinks the valve was opened
unsigned int state_led_pin;
// So our LCD messages have meaning
String name;
// If we come across a pin error state, update this string so the LCD can find it and print it
String pin_error_message = "";
// If we come across a relay error state, update this string so the LCD can find it and print it
String relay_error_message = "";
public:
// The row that the error message is on the LCD. -1 means it is not on the LCD
int pin_error_message_row = -1;
// The row that the error message is on the LCD. -1 means it is not on the LCD
int relay_error_message_row = -1;
LatchingSolenoidDisplays (unsigned int relay_led_pin,
unsigned int state_led_pin,
String name);
String get_pin_error_message();
String get_relay_error_message();
// Sets the desired and actual LEDs as given by the 2 statuss bytes from CAN
// If there is an error signified in the bytes, write to the LCD
void control_leds(unsigned int on_relay_status, unsigned int off_relay_status);
};
```
## Actuator Box