Skip to content

Commit

Permalink
Ignitor Implementation (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwz5 authored Jan 18, 2025
2 parents d4bb96b + e6958ea commit b8173fc
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/fill_station_action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ jobs:
bazel build //fill/lib/MockWiringPi:mock_wiringpi
./fill/setup_mock_wiringpi.sh
bazel build //fill:all
# ./fill/test/bv_test.sh
# ./fill/test/ignitor_test.sh
# ./fill/test/bv_test.sh
# ./fill/test/qd_test.sh
# ./fill/test/sv1_test.sh
elif [[ "${{ matrix.arch }}" == "arm64" ]]; then
Expand Down
1 change: 1 addition & 0 deletions fill/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cc_binary(
"//fill/actuators:ball_valve",
"//fill/umbilical:rocket_proto_builder",
"//fill/actuators:sol_valve",
"//fill/actuators:ignitor",
"//fill/sensors:pt",
"@abseil-cpp//absl/flags:flag",
"@abseil-cpp//absl/flags:parse",
Expand Down
12 changes: 12 additions & 0 deletions fill/actuators/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,16 @@ cc_library(
visibility = [
"//fill:__subpackages__",
],
)

cc_library(
name = "ignitor",
srcs = ["ignitor.cc"],
hdrs = ["ignitor.h"],
deps = [":actuator","//fill/lib/MockWiringPi:mock_wiringpi"],
includes = ["."],
linkopts = ["-lwiringPi"],
visibility = [
"//fill:__subpackages__",
],
)
3 changes: 2 additions & 1 deletion fill/actuators/actuator.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef ACTUATOR_H
#define ACTUATOR_H

// TODO: Remove actuator interface entirely
class Actuator {
public:
// Actuates the actuator
Expand All @@ -12,4 +13,4 @@ class Actuator {
bool actuating;
};

#endif
#endif
23 changes: 23 additions & 0 deletions fill/actuators/ignitor.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "ignitor.h"

Ignitor::Ignitor(){
wiringPiSetupGpio();
pinMode(IG_0, OUTPUT);
pinMode(IG_1, OUTPUT);

// write low initially
digitalWrite(IG_0, LOW);
digitalWrite(IG_1, LOW);
}

Ignitor::~Ignitor(){}

bool Ignitor::Actuate(){
digitalWrite(IG_0, HIGH);
digitalWrite(IG_1, HIGH);
delay(1000);
digitalWrite(IG_0, LOW);
digitalWrite(IG_1, LOW);
}

bool Ignitor::isActuating(){}
17 changes: 17 additions & 0 deletions fill/actuators/ignitor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef IGNITOR_H
#define IGNITOR_H

#include "actuator.h"
#include "wiringPi.h"

#define IG_0 17
#define IG_1 27

class Ignitor : public Actuator{
public:
Ignitor();
~Ignitor();
bool Actuate();
bool isActuating();
};
#endif
9 changes: 8 additions & 1 deletion fill/fill_station.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "actuators/qd.h"
#include "actuators/ball_valve.h"
#include "actuators/sol_valve.h"
#include "actuators/ignitor.h"

#include "sensors/pt.h"
#include "umbilical/proto_build.h"
Expand Down Expand Up @@ -48,6 +49,7 @@ using grpc::Status;
QD qd;
BallValve ball_valve;
SolValve sv1;
Ignitor ignitor;

/* Sensors */
PT pt1 = PT(0x48, 3);
Expand Down Expand Up @@ -121,7 +123,12 @@ class CommanderServiceImpl final : public Commander::Service
sv1.close();
}
}

if (request->has_ignite()){
if (request->ignite()){
ignitor.Actuate();
}
}

protoBuild.sendCommand(request);

return Status::OK;
Expand Down
43 changes: 43 additions & 0 deletions fill/test/ignitor_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash

# Check if grpcurl is already installed
if ! command -v grpcurl &> /dev/null; then
echo "Installing grpcurl..."
wget https://github.com/fullstorydev/grpcurl/releases/download/v1.9.1/grpcurl_1.9.1_linux_amd64.deb
sudo apt install ./grpcurl_1.9.1_linux_amd64.deb
rm ./grpcurl_1.9.1_linux_amd64.deb # Clean up the downloaded deb file
echo "grpcurl installed."
fi

# Capture output and check against expected value
# Run fill_station in the background and capture its PID
stdbuf -oL ./bazel-bin/fill/fill_station > fill_station_output.txt 2>&1 &
fill_station_pid=$!

# Wait for fill_station to start listening
while [[ ! $(grep "Server listening on" fill_station_output.txt) ]]; do
sleep 0.1 # Check every 0.1 seconds
if [[ $(ps -p $fill_station_pid) == "" ]]; then
echo "fill_station died unexpectedly"
exit 1
fi
done

# Send grpcurl command
grpcurl -plaintext -d '{"ignite": true}' localhost:50051 command.Commander/SendCommand
grpcurl -plaintext -d '{"ignite": false}' localhost:50051 command.Commander/SendCommand

# Kill fill_station after a timeout (adjust timeout as needed)
sleep 2
pkill -9 -f fill_station

actual_output=$(cat fill_station_output.txt)
expected_output=$(cat ./fill/test/ignitor_test_expected_output.txt)
if [[ "$actual_output" != "$expected_output" ]]; then
echo "Output mismatch:"
echo "Expected:"
echo "$expected_output"
echo "Actual:"
echo "$actual_output"
exit 1
fi
33 changes: 33 additions & 0 deletions fill/test/ignitor_test_expected_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[MOCK] wiringPiSetupGpio called
[MOCK] pinMode called, pin: 5, mode: 1
[MOCK] pinMode called, pin: 6, mode: 1
[MOCK] pinMode called, pin: 22, mode: 1
[MOCK] pinMode called, pin: 26, mode: 1
[MOCK] wiringPiSetupGpio called
[MOCK] pinMode called, pin: 24, mode: 1
[MOCK] pinMode called, pin: 23, mode: 1
[MOCK] digitalWrite called, pin: 24, value: 0
[MOCK] digitalWrite called, pin: 23, value: 0
[MOCK] wiringPiSetupGpio called
[MOCK] pinMode called, pin: 13, mode: 1
[MOCK] digitalWrite called, pin: 13, value: 0
[MOCK] wiringPiSetupGpio called
[MOCK] pinMode called, pin: 17, mode: 1
[MOCK] pinMode called, pin: 27, mode: 1
[MOCK] digitalWrite called, pin: 17, value: 0
[MOCK] digitalWrite called, pin: 27, value: 0
setting up ADS with m_i2cAddress = 72
[MOCK] wiringPiI2CSetup called with devId: 72
m_i2cFd = 72
setting up ADS with m_i2cAddress = 72
[MOCK] wiringPiI2CSetup called with devId: 72
m_i2cFd = 72
Error opening /dev/rocket.
Error getting termios attributes.
Error setting termios attributes.
Server listening on 0.0.0.0:50051
[MOCK] digitalWrite called, pin: 17, value: 1
[MOCK] digitalWrite called, pin: 27, value: 1
[MOCK] delay called, howLong: 1000 (usleep used in mock)
[MOCK] digitalWrite called, pin: 17, value: 0
[MOCK] digitalWrite called, pin: 27, value: 0

0 comments on commit b8173fc

Please sign in to comment.