Skip to content

Commit

Permalink
Get rid of MAGNET_DISTANCE_270
Browse files Browse the repository at this point in the history
By incorporating the additional offset caused by the second
magnet into the end offsets we can avoid a special case in
the Encoders class.
  • Loading branch information
jonathanperret committed Jan 19, 2025
1 parent 13d5000 commit 7ae2bae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
14 changes: 2 additions & 12 deletions src/ayab/encoders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,7 @@ void Encoders::encA_rising() {

uint8_t start_position = END_LEFT_PLUS_OFFSET[static_cast<uint8_t>(m_machineType)];

if (m_machineType == Machine_t::Kh270) {
m_carriage = Carriage_t::Knit;

// Assume the rightmost magnet was detected
start_position = start_position + MAGNET_DISTANCE_270;
} else if (m_carriage == Carriage_t::Lace &&
if (m_carriage == Carriage_t::Lace &&
detected_carriage == Carriage_t::Knit &&
m_position > start_position) {
m_carriage = Carriage_t::Garter;
Expand Down Expand Up @@ -298,12 +293,7 @@ void Encoders::encA_falling() {

uint8_t start_position = END_RIGHT_MINUS_OFFSET[static_cast<uint8_t>(m_machineType)];

if (m_machineType == Machine_t::Kh270) {
m_carriage = Carriage_t::Knit;

// Assume the leftmost magnet was detected
start_position = start_position; // FIXME
} else if (m_carriage == Carriage_t::Lace &&
if (m_carriage == Carriage_t::Lace &&
detected_carriage == Carriage_t::Knit &&
m_position < start_position) {
m_carriage = Carriage_t::Garter;
Expand Down
10 changes: 4 additions & 6 deletions src/ayab/encoders.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ constexpr uint8_t END_OF_LINE_OFFSET_L[NUM_MACHINES] = {12U, 12U, 6U};
constexpr uint8_t END_OF_LINE_OFFSET_R[NUM_MACHINES] = {12U, 12U, 6U};

constexpr uint8_t END_LEFT[NUM_MACHINES] = {0U, 0U, 0U};
constexpr uint8_t END_RIGHT[NUM_MACHINES] = {255U, 255U, 140U};
constexpr uint8_t END_OFFSET[NUM_MACHINES] = {28U, 28U, 5U};
constexpr uint8_t END_RIGHT[NUM_MACHINES] = {255U, 255U, 150U};
constexpr uint8_t END_OFFSET[NUM_MACHINES] = {28U, 28U, 17U};

// The following two arrays are created by combining, respectively,
// the arrays END_LEFT and END_RIGHT with END_OFFSET
constexpr uint8_t END_LEFT_PLUS_OFFSET[NUM_MACHINES] = {28U, 28U, 5U};
constexpr uint8_t END_RIGHT_MINUS_OFFSET[NUM_MACHINES] = {227U, 227U, 135U};
constexpr uint8_t END_LEFT_PLUS_OFFSET[NUM_MACHINES] = {28U, 28U, 17U};
constexpr uint8_t END_RIGHT_MINUS_OFFSET[NUM_MACHINES] = {227U, 227U, 133U};

constexpr uint8_t ALL_MAGNETS_CLEARED_LEFT[NUM_MACHINES] = {56U, 56U, 10U};
constexpr uint8_t ALL_MAGNETS_CLEARED_RIGHT[NUM_MACHINES] = {199U, 199U, 130U};
Expand Down Expand Up @@ -117,8 +117,6 @@ constexpr uint16_t FILTER_R_MAX[NUM_MACHINES] = {1023U, 600U, 600U};

constexpr uint16_t SOLENOIDS_BITMASK = 0xFFFFU;

constexpr uint8_t MAGNET_DISTANCE_270 = 12U;

/*!
* \brief Encoder interface.
*
Expand Down

0 comments on commit 7ae2bae

Please sign in to comment.