Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Systemic changes to support garter carriage on the full bed #196

Merged
Merged
Changes from 5 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
60d299e
Start G-carriage earlier to avoid overflowing m_position
clholgat Jul 31, 2024
efefaf1
Cleanup
clholgat Jul 31, 2024
702e55b
Whitespace
clholgat Jul 31, 2024
f273377
Rethink how solenoids are calculated
clholgat Aug 18, 2024
1d0d6cf
Finally works
clholgat Aug 25, 2024
600d0e3
Cleanup
clholgat Aug 25, 2024
b013100
Fix knit carriage belt shift
clholgat Aug 25, 2024
5f24490
Update offsets
clholgat Aug 25, 2024
2d56775
Belt shift experimentation
clholgat Aug 27, 2024
20bbb23
Fix Right to Left
clholgat Aug 27, 2024
d28c392
It works
clholgat Aug 30, 2024
fe3a180
Fix lace carriage
clholgat Aug 30, 2024
9bcfd16
Remove unused variable
clholgat Aug 30, 2024
fc9ba8c
Start G-carriage earlier to avoid overflowing m_position
clholgat Jul 31, 2024
b490d6f
Cleanup
clholgat Jul 31, 2024
44f5b36
Whitespace
clholgat Jul 31, 2024
696b9b7
Rethink how solenoids are calculated
clholgat Aug 18, 2024
cdd1afd
Finally works
clholgat Aug 25, 2024
ba29a37
Cleanup
clholgat Aug 25, 2024
03149f7
Fix knit carriage belt shift
clholgat Aug 25, 2024
5560a08
Update offsets
clholgat Aug 25, 2024
e99ebeb
Belt shift experimentation
clholgat Aug 27, 2024
95c11ae
Fix Right to Left
clholgat Aug 27, 2024
4d7b11b
It works
clholgat Aug 30, 2024
ea8733f
Fix lace carriage
clholgat Aug 30, 2024
b309e39
Remove unused variable
clholgat Aug 30, 2024
284371b
Update src/ayab/encoders.cpp
dl1com Aug 30, 2024
67affda
Update src/ayab/encoders.cpp
dl1com Aug 30, 2024
030c5f3
Fixed existing tests, removed the ones that are no longer relevant
clholgat Aug 31, 2024
52cd583
Merge branch 'clholgat/garter_carriage' of https://github.com/clholga…
clholgat Sep 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 49 additions & 23 deletions src/ayab/encoders.cpp
Original file line number Diff line number Diff line change
@@ -75,6 +75,8 @@ void Encoders::init(Machine_t machineType) {
m_beltShift = BeltShift::Unknown;
m_carriage = Carriage_t::NoCarriage;
m_oldState = false;
m_passedLeft = false;
m_passedRight = false;
}

/*!
@@ -133,20 +135,13 @@ void Encoders::encA_rising() {
m_direction = digitalRead(ENC_PIN_B) != 0 ? Direction_t::Right : Direction_t::Left;

// Update carriage position
if ((Direction_t::Right == m_direction) && (m_position < END_RIGHT[static_cast<uint8_t>(m_machineType)])) {
m_position = m_position + 1;
}

// The garter carriage has a second set of magnets that are going to
// pass the sensor and will reset state incorrectly if allowed to
// continue.
if (m_carriage == Carriage_t::Garter) {
return;
}
if (Direction_t::Right == m_direction) {
m_position = m_position + (uint8_t) 1;

// If the carriage is already set, ignore the rest.
if ((m_carriage == Carriage_t::Knit) && (m_machineType == Machine_t::Kh270)) {
return;
// Reset carriage passed state when we know all magnets have cleared the turn mark.
if (m_position > ALL_MAGNETS_CLEARED_LEFT[static_cast<uint8_t>(m_machineType)]) {
m_passedLeft = false;
}
}

// In front of Left Hall Sensor?
@@ -155,6 +150,26 @@ void Encoders::encA_rising() {
(hallValue > FILTER_L_MAX[static_cast<uint8_t>(m_machineType)])) {
m_hallActive = Direction_t::Left;

// Only set the belt shift the first time a magnet passes the turn mark.
// Headed to the right.
if (!m_passedLeft && Direction_t::Right == m_direction) {
// Belt shift signal only decided in front of hall sensor
m_beltShift = digitalRead(ENC_PIN_C) != 0 ? BeltShift::Regular : BeltShift::Shifted;
m_passedLeft = true;
}

// The garter carriage has a second set of magnets that are going to
// pass the sensor and will reset state incorrectly if allowed to
// continue.
if (m_carriage == Carriage_t::Garter) {
clholgat marked this conversation as resolved.
Show resolved Hide resolved
return;
}

// If the carriage is already set, ignore the rest.
if ((m_carriage == Carriage_t::Knit) && (m_machineType == Machine_t::Kh270)) {
return;
}

Carriage detected_carriage = Carriage_t::NoCarriage;
uint8_t start_position = END_LEFT_PLUS_OFFSET[static_cast<uint8_t>(m_machineType)];

@@ -183,9 +198,6 @@ void Encoders::encA_rising() {
m_carriage = detected_carriage;
}

// Belt shift signal only decided in front of hall sensor
m_beltShift = digitalRead(ENC_PIN_C) != 0 ? BeltShift::Regular : BeltShift::Shifted;

// Known position of the carriage -> overwrite position
m_position = start_position;
}
@@ -203,8 +215,13 @@ void Encoders::encA_falling() {
m_direction = digitalRead(ENC_PIN_B) ? Direction_t::Left : Direction_t::Right;

// Update carriage position
if ((Direction_t::Left == m_direction) && (m_position > END_LEFT[static_cast<uint8_t>(m_machineType)])) {
m_position = m_position - 1;
if (Direction_t::Left == m_direction) {
m_position = m_position - (uint8_t) 1;
X-sam marked this conversation as resolved.
Show resolved Hide resolved

// Reset carriage passed state when we know all magnets have cleared the turn mark.
if (m_position < ALL_MAGNETS_CLEARED_RIGHT[static_cast<uint8_t>(m_machineType)]) {
m_passedRight = false;
}
}

// In front of Right Hall Sensor?
@@ -219,15 +236,24 @@ void Encoders::encA_falling() {
if (hallValueSmall || hallValue > FILTER_R_MAX[static_cast<uint8_t>(m_machineType)]) {
m_hallActive = Direction_t::Right;

// The garter carriage has a second set of magnets that are going to
// Only set the belt shift when the first magnet passes the turn mark.
// Headed to the left.
if (!m_passedRight && Direction_t::Left == m_direction) {
// Belt shift signal only decided in front of hall sensor
m_beltShift = digitalRead(ENC_PIN_C) != 0 ? BeltShift::Shifted : BeltShift::Regular;
m_passedRight = true;
}

// The garter carriage has extra magnets that are going to
// pass the sensor and will reset state incorrectly if allowed to
// continue.
if (hallValueSmall && (m_carriage != Carriage_t::Garter)) {
m_carriage = Carriage_t::Knit;
if (m_carriage == Carriage_t::Garter) {
return;
}

// Belt shift signal only decided in front of hall sensor
m_beltShift = digitalRead(ENC_PIN_C) != 0 ? BeltShift::Shifted : BeltShift::Regular;
if (hallValueSmall) {
m_carriage = Carriage_t::Knit;
}

// Known position of the carriage -> overwrite position
m_position = END_RIGHT_MINUS_OFFSET[static_cast<uint8_t>(m_machineType)];
12 changes: 9 additions & 3 deletions src/ayab/encoders.h
Original file line number Diff line number Diff line change
@@ -74,17 +74,20 @@ constexpr uint8_t END_OFFSET[NUM_MACHINES] = {28U, 28U, 5U};
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 ALL_MAGNETS_CLEARED_LEFT[NUM_MACHINES] = {56U, 56U, 10U};
constexpr uint8_t ALL_MAGNETS_CLEARED_RIGHT[NUM_MACHINES] = {199U, 199U, 130U};

// The garter slop is needed to determine whether or not we have a garter carriage.
// If we didn't have it, we'd decide which carriage we had when the first magnet passed the sensor.
// For the garter carriage we need to see both magnets.
constexpr uint8_t GARTER_SLOP = 2U;
constexpr uint16_t GARTER_SLOP = 2U;

constexpr uint8_t START_OFFSET[NUM_MACHINES][NUM_DIRECTIONS][NUM_CARRIAGES] = {
// KH910
{
// K, L, G
{40U, 40U, 32U}, // Left
{16U, 16U, 56U} // Right
{40U, 32U, 32U/*16U*/}, // Left
{16U, 32U, 50U/*40U*/} // Right
},
// KH930
{
@@ -111,6 +114,7 @@ constexpr uint16_t FILTER_R_MAX[NUM_MACHINES] = {1023U, 600U, 600U};
constexpr uint16_t SOLENOIDS_BITMASK = 0xFFFFU;

constexpr uint8_t MAGNET_DISTANCE_270 = 12U;
constexpr uint8_t HALF_MAGNET_DISTANCE_G = 12U;

/*!
* \brief Encoder interface.
@@ -181,6 +185,8 @@ class Encoders : public EncodersInterface {
volatile Direction_t m_hallActive;
volatile uint8_t m_position;
volatile bool m_oldState;
volatile bool m_passedLeft;
volatile bool m_passedRight;

void encA_rising();
void encA_falling();
46 changes: 13 additions & 33 deletions src/ayab/knitter.cpp
Original file line number Diff line number Diff line change
@@ -271,6 +271,7 @@ void Knitter::knit() {

if (!calculatePixelAndSolenoid()) {
// no valid/useful position calculated
GlobalBeeper::finishedLine();
return;
}

@@ -345,7 +346,7 @@ bool Knitter::setNextLine(uint8_t lineNumber) {
// Is there even a need for a new line?
if (lineNumber == m_currentLineNumber) {
m_lineRequested = false;
GlobalBeeper::finishedLine();
//GlobalBeeper::finishedLine();
return true;
} else {
// line numbers didn't match -> request again
@@ -397,44 +398,23 @@ bool Knitter::calculatePixelAndSolenoid() {
case Direction_t::Right:
startOffset = getStartOffset(Direction_t::Left);

// We have to start setting pixels earlier when the lace carriage is selected because we shift
// the lace pixel selection up HALF_SOLENOIDS_NUM in this direction. Doesn't matter going back
// the other way.
if (Carriage_t::Lace == m_carriage) {
laceOffset = HALF_SOLENOIDS_NUM[static_cast<uint8_t>(m_machineType)];
}
m_pixelToSet = m_position - startOffset;
clholgat marked this conversation as resolved.
Show resolved Hide resolved

if (m_position >= startOffset - laceOffset) {
m_pixelToSet = m_position - startOffset;

if ((BeltShift::Regular == m_beltShift) || (m_machineType == Machine_t::Kh270)) {
m_solenoidToSet = m_position % SOLENOIDS_NUM[static_cast<uint8_t>(m_machineType)];
} else if (BeltShift::Shifted == m_beltShift) {
m_solenoidToSet = (m_position - HALF_SOLENOIDS_NUM[static_cast<uint8_t>(m_machineType)]) % SOLENOIDS_NUM[static_cast<uint8_t>(m_machineType)];
}
if (Carriage_t::Lace == m_carriage) {
m_pixelToSet = m_pixelToSet + HALF_SOLENOIDS_NUM[static_cast<uint8_t>(m_machineType)];
}
} else {
return false;
if ((BeltShift::Regular == m_beltShift)) {
m_solenoidToSet = m_pixelToSet % SOLENOIDS_NUM[static_cast<uint8_t>(m_machineType)];
} else if (BeltShift::Shifted == m_beltShift) {
m_solenoidToSet = (m_pixelToSet + HALF_SOLENOIDS_NUM[static_cast<uint8_t>(m_machineType)]) % SOLENOIDS_NUM[static_cast<uint8_t>(m_machineType)];
}
break;

case Direction_t::Left:
startOffset = getStartOffset(Direction_t::Right);
if (m_position <= (END_RIGHT[static_cast<uint8_t>(m_machineType)] - startOffset)) {
m_pixelToSet = m_position - startOffset;

if ((BeltShift::Regular == m_beltShift) || (m_machineType == Machine_t::Kh270)) {
m_solenoidToSet = (m_position + HALF_SOLENOIDS_NUM[static_cast<uint8_t>(m_machineType)]) % SOLENOIDS_NUM[static_cast<uint8_t>(m_machineType)];
} else if (BeltShift::Shifted == m_beltShift) {
m_solenoidToSet = m_position % SOLENOIDS_NUM[static_cast<uint8_t>(m_machineType)];
}
if (Carriage_t::Lace == m_carriage) {
m_pixelToSet = m_pixelToSet - SOLENOIDS_NUM[static_cast<uint8_t>(m_machineType)];
}
} else {
return false;
m_pixelToSet = m_position - startOffset;

if (BeltShift::Regular == m_beltShift) {
m_solenoidToSet = (m_pixelToSet + HALF_SOLENOIDS_NUM[static_cast<uint8_t>(m_machineType)]) % SOLENOIDS_NUM[static_cast<uint8_t>(m_machineType)];
} else if (BeltShift::Shifted == m_beltShift) {
m_solenoidToSet = m_pixelToSet % SOLENOIDS_NUM[static_cast<uint8_t>(m_machineType)];
}
break;