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 ebf496f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
13 changes: 10 additions & 3 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 Down Expand Up @@ -163,16 +165,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
40 changes: 35 additions & 5 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 @@ -214,6 +214,36 @@ TEST_F(KnitterTest, test_isr) {
ASSERT_TRUE(Mock::VerifyAndClear(encodersMock));
}

TEST_F(KnitterTest, test_ready_startL) {
// Machine is initialized when Left hall sensor
// is passed in Right direction inside active needles.
get_to_ready();
ASSERT_EQ(fsm->getState(), s_ready);

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

TEST_F(KnitterTest, test_ready_startR) {
// New feature (August 2020): the machine is also initialized
// when the right Hall sensor is passed in the Left direction.
Machine_t m = knitter->getMachineType();
expected_isr(80 - END_OF_LINE_OFFSET_R[m] - 1, Left, Right, Regular, Knit);

// initialize
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(encodersMock));
ASSERT_TRUE(Mock::VerifyAndClear(comMock));
}

TEST_F(KnitterTest, test_startKnitting_NoMachine) {
uint8_t pattern[] = {1};
Machine_t m = knitter->getMachineType();
Expand Down Expand Up @@ -355,7 +385,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

0 comments on commit ebf496f

Please sign in to comment.