Skip to content

Commit

Permalink
Carriage can start on the Right hand side moving Left.
Browse files Browse the repository at this point in the history
  • Loading branch information
t0mpr1c3 committed Aug 23, 2020
1 parent a1ce5d2 commit 35bb0d1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
15 changes: 10 additions & 5 deletions src/ayab/knitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void Knitter::init() {
setUpInterrupt();

// explicitly initialize members

// job parameters
m_machineType = NoMachine;
m_startNeedle = 0U;
m_stopNeedle = 0U;
Expand All @@ -79,8 +81,6 @@ void Knitter::init() {
#ifdef DBG_NOMACHINE
m_prevState = false;
#endif
m_solenoidToSet = 0U;
m_pixelToSet = 0U;
}

void Knitter::setUpInterrupt() {
Expand Down Expand Up @@ -163,16 +163,21 @@ void Knitter::encodePosition() {
}
}

// return true -> move from state `s_init` to `s_ready`
// if this function returns true then
// the FSM will move from state `s_init` to `s_ready`
bool Knitter::isReady() {
#ifdef DBG_NOMACHINE
bool state = digitalRead(DBG_BTN_PIN);

// TODO(who?): check if debounce is needed
if (m_prevState && !state) {
#else
// machine is initialized when left hall sensor is passed in Right direction
if (Right == m_direction && Left == m_hallActive) {
// Machine is initialized when left Hall sensor is passed in Right direction
// New feature (August 2020): the machine is also initialized
// when the right Hall sensor is passed in Left direction.
if ((Right == m_direction and Left == m_hallActive) or
(Left == m_direction and Right == m_hallActive)) {

#endif // DBG_NOMACHINE
GlobalSolenoids::setSolenoids(SOLENOIDS_BITMASK);
indState(true);
Expand Down
28 changes: 22 additions & 6 deletions test/test_knitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class KnitterTest : public ::testing::Test {
}

void expect_isr(Direction_t dir, Direction_t hall) {
expect_isr(1, dir, hall, Regular, Garter);
expect_isr(1, dir, hall, Regular, Knit);
}

void expected_isr(Direction_t dir, Direction_t hall) {
Expand Down Expand Up @@ -151,10 +151,10 @@ class KnitterTest : public ::testing::Test {
}

void get_to_ready() {
// machine is initialized when left hall sensor
// is passed in Right direction inside active needles
// Machine is initialized when Left hall sensor
// is passed in Right direction inside active needles.
Machine_t m = knitter->getMachineType();
expected_isr(40 + END_OF_LINE_OFFSET_L[m] + 1);
expected_isr(40 + END_OF_LINE_OFFSET_L[m] + 1, Right, Left, Regular, Knit);

// initialize
EXPECT_CALL(*solenoidsMock, setSolenoids(0xFFFF));
Expand Down Expand Up @@ -355,7 +355,7 @@ TEST_F(KnitterTest, test_knit_Kh910) {
expected_knit(false);

// no useful position calculated by `calculatePixelAndSolenoid()`
expected_isr(100, NoDirection, Right, Shifted, Garter);
expected_isr(100, NoDirection, Right, Shifted, Knit);
EXPECT_CALL(*solenoidsMock, setSolenoid).Times(0);
expect_indState();
expected_knit(false);
Expand Down Expand Up @@ -670,7 +670,8 @@ TEST_F(KnitterTest, test_fsm_init_RR) {
}

TEST_F(KnitterTest, test_fsm_init_RL) {
// ready
// Machine is initialized when Left hall sensor
// is passed in Right direction inside active needles.
expected_isr(Right, Left);
EXPECT_CALL(*solenoidsMock, setSolenoids(0xFFFF));
expect_indState();
Expand All @@ -682,3 +683,18 @@ TEST_F(KnitterTest, test_fsm_init_RL) {
ASSERT_TRUE(Mock::VerifyAndClear(comMock));
ASSERT_TRUE(Mock::VerifyAndClear(encodersMock));
}

TEST_F(KnitterTest, test_fsm_init_LR) {
// New feature (August 2020): the machine is also initialized
// when the right Hall sensor is passed in the Left direction.
expected_isr(Left, Right);
EXPECT_CALL(*solenoidsMock, setSolenoids(0xFFFF));
expect_indState();
expected_fsm();
ASSERT_EQ(fsm->getState(), s_ready);

// test expectations without destroying instance
ASSERT_TRUE(Mock::VerifyAndClear(solenoidsMock));
ASSERT_TRUE(Mock::VerifyAndClear(comMock));
ASSERT_TRUE(Mock::VerifyAndClear(encodersMock));
}

0 comments on commit 35bb0d1

Please sign in to comment.