Skip to content

Commit

Permalink
tests passing + rm outside calls to test
Browse files Browse the repository at this point in the history
  • Loading branch information
caila-marashaj committed Mar 18, 2024
1 parent 935ff85 commit bda60fa
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,9 @@ class MotorTask {
LidStepperState::Status old_state = _lid_stepper_state.status.load();
auto error = handle_hinge_state_end(policy);
if ((_lid_stepper_state.status == LidStepperState::Status::IDLE &&
old_state != _lid_stepper_state.status &&
_lid_stepper_state.response_id != INVALID_ID) || error != errors::ErrorCode::NO_ERROR) {
old_state != _lid_stepper_state.status &&
_lid_stepper_state.response_id != INVALID_ID) ||
error != errors::ErrorCode::NO_ERROR) {
// Send an ACK if a movement just finished
auto response = messages::AcknowledgePrevious{
.responding_to_id = _lid_stepper_state.response_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
*/
#pragma once

#include <array>
#include <optional>

#include "core/pid.hpp"
#include "thermocycler-gen2/thermal_general.hpp"
#include <optional>
#include <array>

namespace plate_control {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

#include <concepts>
#include <cstdint>
#include <cstring>
#include <functional>
#include <optional>
#include <cstring>

#include "core/bit_utils.hpp"
#include "systemwide.h"
Expand Down Expand Up @@ -300,7 +300,8 @@ class TMC2130 {
// this on __packed structures that mimic hardware registers
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
RegisterSerializedTypeA value;
std::memcpy(&value, &reg, std::min(sizeof(Reg), sizeof(RegisterSerializedTypeA)));
std::memcpy(&value, &reg,
std::min(sizeof(Reg), sizeof(RegisterSerializedTypeA)));
//*reinterpret_cast<RegisterSerializedTypeA*>(&reg);
value &= Reg::value_mask;
return _spi.write(Reg::address, value, policy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ concept TMC2130Register =
std::remove_cvref_t<Registers&>> &&
std::integral<decltype(Reg::value_mask)>;

// Struct has a valid register address
// Struct has an integer with the total number of bits in a register.
// This is used to mask the 64-bit value before writing to the IC.
// Struct has a valid register address
// Struct has an integer with the total number of bits in a register.
// This is used to mask the 64-bit value before writing to the IC.

template <typename Reg>
concept WritableRegister = requires() {
Expand Down
189 changes: 99 additions & 90 deletions stm32-modules/thermocycler-gen2/tests/test_motor_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,28 +909,31 @@ SCENARIO("motor task lid state machine") {
motor_policy.set_lid_closed_switch(true);
steps.push_back(
// an ack with error code NO_ERROR should follow
MotorStep{.msg = messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
.motor_state = MotorStep::MotorState::IDLE,
.ack = messages::AcknowledgePrevious{
.responding_to_id = 123,
.with_error = errors::ErrorCode::NO_ERROR}});
MotorStep{.msg =
messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
.motor_state = MotorStep::MotorState::IDLE,
.ack = messages::AcknowledgePrevious{
.responding_to_id = 123,
.with_error = errors::ErrorCode::NO_ERROR}});
test_motor_state_machine(tasks, steps);
}
AND_WHEN("the closed switch is not triggered") {
motor_policy.set_lid_closed_switch(false);
steps.push_back(
// an ack with error code UNEXPECTED_LID_STATE should follow
MotorStep{.msg = messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
MotorStep{
.msg =
messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
.motor_state = MotorStep::MotorState::IDLE,
.ack = messages::AcknowledgePrevious{
.responding_to_id = 0,
.with_error =
errors::ErrorCode::UNEXPECTED_LID_STATE}});
test_motor_state_machine(tasks, steps);
test_motor_state_machine(tasks, steps);
}
}
WHEN("sending plate lift command") {
Expand Down Expand Up @@ -1031,30 +1034,34 @@ SCENARIO("motor task lid state machine") {
motor_policy.set_lid_closed_switch(true);
steps.push_back(
// an ack with error code NO_ERROR should follow
MotorStep{.msg = messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
.motor_state = MotorStep::MotorState::IDLE,
.ack = messages::AcknowledgePrevious{
.responding_to_id = 123,
.with_error = errors::ErrorCode::NO_ERROR}});
MotorStep{
.msg =
messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
.motor_state = MotorStep::MotorState::IDLE,
.ack = messages::AcknowledgePrevious{
.responding_to_id = 123,
.with_error = errors::ErrorCode::NO_ERROR}});
test_motor_state_machine(tasks, steps);
}
AND_WHEN("the closed switch is not triggered") {
motor_policy.set_lid_closed_switch(false);
steps.push_back(
// an ack with error code UNEXPECTED_LID_STATE should follow
MotorStep{.msg = messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
// an ack with error code UNEXPECTED_LID_STATE should
// follow
MotorStep{
.msg =
messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
.motor_state = MotorStep::MotorState::IDLE,
.ack = messages::AcknowledgePrevious{
.responding_to_id = 0,
.with_error =
errors::ErrorCode::UNEXPECTED_LID_STATE}});
test_motor_state_machine(tasks, steps);
test_motor_state_machine(tasks, steps);
}
test_motor_state_machine(tasks, steps);
}
}
GIVEN("seal switches aren't shared") {
Expand Down Expand Up @@ -1091,30 +1098,34 @@ SCENARIO("motor task lid state machine") {
motor_policy.set_lid_closed_switch(true);
steps.push_back(
// an ack with error code NO_ERROR should follow
MotorStep{.msg = messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
.motor_state = MotorStep::MotorState::IDLE,
.ack = messages::AcknowledgePrevious{
.responding_to_id = 123,
.with_error = errors::ErrorCode::NO_ERROR}});
MotorStep{
.msg =
messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
.motor_state = MotorStep::MotorState::IDLE,
.ack = messages::AcknowledgePrevious{
.responding_to_id = 123,
.with_error = errors::ErrorCode::NO_ERROR}});
test_motor_state_machine(tasks, steps);
}
AND_WHEN("the closed switch is not triggered") {
motor_policy.set_lid_closed_switch(false);
steps.push_back(
// an ack with error code UNEXPECTED_LID_STATE should follow
MotorStep{.msg = messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
// an ack with error code UNEXPECTED_LID_STATE should
// follow
MotorStep{
.msg =
messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
.motor_state = MotorStep::MotorState::IDLE,
.ack = messages::AcknowledgePrevious{
.responding_to_id = 0,
.with_error =
errors::ErrorCode::UNEXPECTED_LID_STATE}});
test_motor_state_machine(tasks, steps);
test_motor_state_machine(tasks, steps);
}
test_motor_state_machine(tasks, steps);
}
}
}
Expand Down Expand Up @@ -1181,74 +1192,72 @@ SCENARIO("motor task lid state machine") {
.lid_angle_decreased = true,
.lid_overdrive = false,
.lid_rpm =
motor_task::LidStepperState::LID_DEFAULT_VELOCITY_RPM}
};
motor_task::LidStepperState::LID_DEFAULT_VELOCITY_RPM}};
test_motor_state_machine(tasks, steps);
steps.clear();
AND_WHEN("the closed switch is triggered") {
motor_policy.set_lid_closed_switch(true);
// Fourth step overdrives hinge
steps.push_back(MotorStep{.msg = messages::LidStepperComplete(),
.lid_angle_decreased = true,
.lid_overdrive = true});
// Now extend seal to switch
steps.push_back(MotorStep{.msg = messages::LidStepperComplete(),
.seal_on = true,
.seal_direction = false,
.seal_switch_armed = true});
// Retract seal from switch
steps.push_back(
MotorStep{.msg =
messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::LIMIT},
.seal_on = true,
.seal_direction = true,
.seal_switch_armed = false});
steps.push_back(
// an ack with error code NO_ERROR should follow
MotorStep{.msg =
messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
.ack = messages::AcknowledgePrevious{
.responding_to_id = 123,
.with_error = errors::ErrorCode::NO_ERROR}});
test_motor_state_machine(tasks, steps);
steps.clear();
AND_WHEN("the closed switch is triggered") {
motor_policy.set_lid_closed_switch(true);
// Fourth step overdrives hinge
steps.push_back(
MotorStep{.msg = messages::LidStepperComplete(),
.lid_angle_decreased = true,
.lid_overdrive = true});
// Now extend seal to switch
steps.push_back(
MotorStep{.msg = messages::LidStepperComplete(),
.seal_on = true,
.seal_direction = false,
.seal_switch_armed = true});
// Retract seal from switch
steps.push_back(
MotorStep{.msg =
messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::LIMIT},
.seal_on = true,
.seal_direction = true,
.seal_switch_armed = false});
steps.push_back(
// an ack with error code NO_ERROR should follow
MotorStep{.msg = messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
.ack = messages::AcknowledgePrevious{
.responding_to_id = 123,
.with_error = errors::ErrorCode::NO_ERROR}});
test_motor_state_machine(tasks, steps);
}
AND_WHEN("the closed switch is not triggered") {
motor_policy.set_lid_closed_switch(false);
// Fourth step overdrives hinge
steps.push_back(
MotorStep{.msg = messages::LidStepperComplete(),
.lid_angle_decreased = true,
.lid_overdrive = true});
steps.push_back(MotorStep{.msg = messages::LidStepperComplete(),
.lid_angle_decreased = true,
.lid_overdrive = true});
// Now extend seal to switch
steps.push_back(
MotorStep{.msg = messages::LidStepperComplete(),
.seal_on = true,
.seal_direction = false,
.seal_switch_armed = true});
steps.push_back(MotorStep{.msg = messages::LidStepperComplete(),
.seal_on = true,
.seal_direction = false,
.seal_switch_armed = true});
// Retract seal from switch
steps.push_back(
MotorStep{.msg =
messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::LIMIT},
.seal_on = true,
.seal_direction = true,
.seal_switch_armed = false});
messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::LIMIT},
.seal_on = true,
.seal_direction = true,
.seal_switch_armed = false});
steps.push_back(
// an ack with error code UNEXPECTED_LID_STATE should follow
MotorStep{.msg = messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
MotorStep{
.msg =
messages::SealStepperComplete{
.reason = messages::SealStepperComplete::
CompletionReason::DONE},
.ack = messages::AcknowledgePrevious{
.responding_to_id = 0,
.with_error =
errors::ErrorCode::UNEXPECTED_LID_STATE}});
test_motor_state_machine(tasks, steps);
test_motor_state_machine(tasks, steps);
}
}
WHEN("sending plate lift command") {
Expand Down

0 comments on commit bda60fa

Please sign in to comment.