|
|
|
@@ -30,7 +30,7 @@ void prepare_channel_for_tilt(int initial_cmd) {
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state());
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_IDLE, relay_chn_get_state());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TEST_CASE: Test transition from running forward to tilt forward
|
|
|
|
// Test transition from running forward to tilt forward
|
|
|
|
// Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD
|
|
|
|
// Scenario: RELAY_CHN_STATE_FORWARD -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD
|
|
|
|
TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][tilt][inertia]")
|
|
|
|
TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][tilt][inertia]")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -53,7 +53,7 @@ TEST_CASE("Run Forward to Tilt Forward transition with inertia", "[relay_chn][ti
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state());
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TEST_CASE: Test transition from running reverse to tilt reverse
|
|
|
|
// Test transition from running reverse to tilt reverse
|
|
|
|
// Scenario: RELAY_CHN_STATE_REVERSE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE
|
|
|
|
// Scenario: RELAY_CHN_STATE_REVERSE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE
|
|
|
|
TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][tilt][inertia]")
|
|
|
|
TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][tilt][inertia]")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -74,7 +74,7 @@ TEST_CASE("Run Reverse to Tilt Reverse transition with inertia", "[relay_chn][ti
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state());
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TEST_CASE: Test transition from FREE state to tilt forward (now with preparation)
|
|
|
|
// Test transition from FREE state to tilt forward (now with preparation)
|
|
|
|
// Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD
|
|
|
|
// Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_forward) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_FORWARD
|
|
|
|
TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn][tilt][inertia]")
|
|
|
|
TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn][tilt][inertia]")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -89,7 +89,7 @@ TEST_CASE("FREE to Tilt Forward transition with inertia (prepared)", "[relay_chn
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state());
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TEST_CASE: Test transition from FREE state to tilt reverse (now with preparation)
|
|
|
|
// Test transition from FREE state to tilt reverse (now with preparation)
|
|
|
|
// Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE
|
|
|
|
// Scenario: RELAY_CHN_STATE_IDLE -> (prepare) -> RELAY_CHN_STATE_IDLE -> (relay_chn_tilt_reverse) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_TILT_REVERSE
|
|
|
|
TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn][tilt][inertia]")
|
|
|
|
TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn][tilt][inertia]")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -103,7 +103,7 @@ TEST_CASE("FREE to Tilt Reverse transition with inertia (prepared)", "[relay_chn
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state());
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_REVERSE, relay_chn_get_state());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TEST_CASE: Test transition from tilt forward to run forward (inertia expected for run)
|
|
|
|
// Test transition from tilt forward to run forward (inertia expected for run)
|
|
|
|
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD
|
|
|
|
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_forward) -> RELAY_CHN_STATE_FORWARD
|
|
|
|
TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][tilt][inertia]")
|
|
|
|
TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][tilt][inertia]")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -121,7 +121,7 @@ TEST_CASE("Tilt Forward to Run Forward transition with inertia", "[relay_chn][ti
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD, relay_chn_get_state());
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD, relay_chn_get_state());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TEST_CASE: Test transition from tilt reverse to run reverse (no inertia expected for run)
|
|
|
|
// Test transition from tilt reverse to run reverse (no inertia expected for run)
|
|
|
|
// Scenario: RELAY_CHN_STATE_TILT_REVERSE -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE
|
|
|
|
// Scenario: RELAY_CHN_STATE_TILT_REVERSE -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE
|
|
|
|
TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][tilt][inertia]")
|
|
|
|
TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][tilt][inertia]")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -138,7 +138,7 @@ TEST_CASE("Tilt Reverse to Run Reverse transition with inertia", "[relay_chn][ti
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state());
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TEST_CASE: Test transition from tilt forward to run reverse (without inertia)
|
|
|
|
// Test transition from tilt forward to run reverse (without inertia)
|
|
|
|
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE
|
|
|
|
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_run_reverse) -> RELAY_CHN_STATE_REVERSE
|
|
|
|
TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn][tilt][inertia]")
|
|
|
|
TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn][tilt][inertia]")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -154,7 +154,7 @@ TEST_CASE("Tilt Forward to Run Reverse transition without inertia", "[relay_chn]
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state());
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TEST_CASE: Test stopping from a tilt state (no inertia for stop command itself)
|
|
|
|
// Test stopping from a tilt state (no inertia for stop command itself)
|
|
|
|
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_stop) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_IDLE
|
|
|
|
// Scenario: RELAY_CHN_STATE_TILT_FORWARD -> (relay_chn_stop) -> RELAY_CHN_STATE_STOPPED -> (inertia) -> RELAY_CHN_STATE_IDLE
|
|
|
|
TEST_CASE("Tilt to Stop transition without immediate inertia for stop", "[relay_chn][tilt][inertia]")
|
|
|
|
TEST_CASE("Tilt to Stop transition without immediate inertia for stop", "[relay_chn][tilt][inertia]")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
@@ -264,4 +264,36 @@ TEST_CASE("run command during TILT state transitions correctly", "[relay_chn][ti
|
|
|
|
// Should transition to REVERSE or REVERSE_PENDING depending on inertia logic
|
|
|
|
// Should transition to REVERSE or REVERSE_PENDING depending on inertia logic
|
|
|
|
relay_chn_state_t state = relay_chn_get_state();
|
|
|
|
relay_chn_state_t state = relay_chn_get_state();
|
|
|
|
TEST_ASSERT(state == RELAY_CHN_STATE_REVERSE || state == RELAY_CHN_STATE_REVERSE_PENDING);
|
|
|
|
TEST_ASSERT(state == RELAY_CHN_STATE_REVERSE || state == RELAY_CHN_STATE_REVERSE_PENDING);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Test run command during active tilt cycle (move/pause)
|
|
|
|
|
|
|
|
TEST_CASE("run command during active tilt cycle stops tilt", "[relay_chn][tilt][interrupt]")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Set a known sensitivity for predictable timing.
|
|
|
|
|
|
|
|
// For sensitivity=50, move_time=30ms, pause_time=270ms.
|
|
|
|
|
|
|
|
relay_chn_tilt_set_sensitivity(50);
|
|
|
|
|
|
|
|
const uint32_t move_time_ms = 30;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- Test interrupting during MOVE step ---
|
|
|
|
|
|
|
|
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
|
|
|
|
|
|
|
|
relay_chn_tilt_forward();
|
|
|
|
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(move_time_ms / 2)); // Wait for half of the move time
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Interrupt with run_reverse while in the MOVE part of the cycle
|
|
|
|
|
|
|
|
relay_chn_run_reverse();
|
|
|
|
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(TEST_DELAY_MARGIN_MS));
|
|
|
|
|
|
|
|
// Should stop tilting and go to REVERSE immediately (no inertia from TILT_FORWARD)
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_REVERSE, relay_chn_get_state());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// --- Test interrupting during PAUSE step ---
|
|
|
|
|
|
|
|
prepare_channel_for_tilt(RELAY_CHN_CMD_FORWARD);
|
|
|
|
|
|
|
|
relay_chn_tilt_forward();
|
|
|
|
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(move_time_ms + TEST_DELAY_MARGIN_MS)); // Wait past MOVE, into PAUSE
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_TILT_FORWARD, relay_chn_get_state());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Interrupt with run_forward while in the PAUSE part of the cycle
|
|
|
|
|
|
|
|
relay_chn_run_forward();
|
|
|
|
|
|
|
|
// Should stop tilting and go to FORWARD_PENDING (inertia from TILT_FORWARD)
|
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL(RELAY_CHN_STATE_FORWARD_PENDING, relay_chn_get_state());
|
|
|
|
}
|
|
|
|
}
|