Skip to content

Commit

Permalink
Add constants & abstraction function
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminwp18 committed Jun 21, 2024
1 parent 718d691 commit 67f476b
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/float/float_transceiver/float_transceiver.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ const uint32_t PRESSURE_READ_INTERVAL = 5000;
const uint32_t PROFILE_SEGMENT = 60000;
#endif

const uint32_t ONE_SECOND = 60000;

// Schedule (all delays in ms)
const uint32_t RELEASE_MAX = 8 * 60000;
const uint32_t RELEASE_MAX = 8 * ONE_SECOND;
const uint32_t SUCK_MAX = PROFILE_SEGMENT;
const uint32_t DESCEND_TIME = PROFILE_SEGMENT;
const uint32_t PUMP_MAX = PROFILE_SEGMENT;
const uint32_t ASCEND_TIME = 0; // Disable ascend times now that we're properly ballasted
const uint32_t TX_MAX = 2 * 60000;
const uint32_t CODA = 2 * 60000;
const uint32_t TX_MAX_TIME = 2 * ONE_SECOND;

const size_t SCHEDULE_LENGTH = 12;

Expand All @@ -57,7 +58,7 @@ struct Stage {
OverrideState overrideState = OverrideState::NoOverride;
uint8_t currentStage = 0;

Stage SCHEDULE[SCHEDULE_LENGTH] = {
const Stage SCHEDULE[SCHEDULE_LENGTH] = {
// Pump immediately in case we just rebooted at the bottom of the pool
{StageType::Pump, PUMP_MAX },

Expand All @@ -70,15 +71,15 @@ Stage SCHEDULE[SCHEDULE_LENGTH] = {
{StageType::Pump, PUMP_MAX },
{StageType::WaitProfiling, ASCEND_TIME },

{StageType::WaitTransmitting, TX_MAX },
{StageType::WaitTransmitting, TX_MAX_TIME },

// Profile 2
{StageType::Suck, SUCK_MAX },
{StageType::WaitProfiling, DESCEND_TIME},
{StageType::Pump, PUMP_MAX },
{StageType::WaitProfiling, ASCEND_TIME },

{StageType::WaitTransmitting, CODA },
{StageType::WaitTransmitting, TX_MAX_TIME },
};

uint32_t stageStartTime;
Expand Down Expand Up @@ -139,7 +140,10 @@ void setup() {

void loop() {
bool submergeReceived = false;
if (!stageIs(StageType::Suck) && !stageIs(StageType::Pump)) {

// Disable command Rx when the motor is moving
// Otherwise the motor can overrun the limit switch
if (!isMotorMoving()) {
submergeReceived = receiveCommand();
}

Expand Down Expand Up @@ -394,6 +398,10 @@ MotorState getMotorState() {
}
}

bool isMotorMoving() {
return getMotorState() == MotorState::Pump && getMotorState() == MotorState::Suck;
}

bool stageIs(StageType type) { return SCHEDULE[currentStage].type == type; }

bool isSurfaced() {
Expand Down

0 comments on commit 67f476b

Please sign in to comment.