Skip to content

Instantly share code, notes, and snippets.

@jonathanperret
Created August 19, 2024 16:32
Show Gist options
  • Save jonathanperret/2d2f532012125c9c3d825c5d1ae8a4b5 to your computer and use it in GitHub Desktop.
Save jonathanperret/2d2f532012125c9c3d825c5d1ae8a4b5 to your computer and use it in GitHub Desktop.
AYAB lace carriage belt shift

calculatePixelAndSolenoid in v0.75 (looks to be the same logic as current, just clearer)

With the lace carriage, the computed pixel/solenoid shift seems different between right and left directions!

Computing (pixelToSet - solenoidToSet) % 16 which should be independent of direction:

dir shift K L
Right Regular 8 0
Shifted 0 8
Left Regular 8 8
Shifted 0 0

Computation worked out in comments in the code below:

bool Knitter::calculatePixelAndSolenoid()
{
	switch( m_direction )
	{ // Calculate the solenoid and pixel to be set
	  // Implemented according to machine manual
	  // Magic numbers result from machine manual	
		case Right:
			if( m_position >= 40 ) 
			{ 
				m_pixelToSet = m_position - 40;
				
				if ( Regular == m_beltshift )
				{
					m_solenoidToSet = m_position % 16;
				}
				else if ( Shifted == m_beltshift )
				{
					m_solenoidToSet = (m_position-8) % 16;
				}
				
				if ( L == m_carriage )
				{
					m_pixelToSet = m_pixelToSet + 8;
				}

				// m_beltshift == Regular:
				
				// K: (m_pixelToSet - m_solenoidToSet) % 16 = ((m_position - 40) - (m_position % 16)) % 16
				//                                          = (m_position - 40 + m_position) % 16
				//                                          = -40 % 16
				//                                          = 8

				// L: (m_pixelToSet - m_solenoidToSet) % 16 = ((m_position - 40 + 8) - (m_position % 16)) % 16
				//                                          = (m_position - 40 + 8 + m_position) % 16
				//                                          = -32 % 16
				//                                          = 0

				// m_beltshift == Shifted:

				// K: (m_pixelToSet - m_solenoidToSet) % 16 = ((m_position - 40) - ((m_position - 8) % 16)) % 16
				//                                          = (-40 + 8) % 16
				//                                          = 0

				// L: (m_pixelToSet - m_solenoidToSet) % 16 = ((m_position - 40 + 8) - ((m_position - 8) % 16)) % 16
				//                                          = (-32 + 8) % 16
				//                                          = 8

			}
			else
			{
				return false;
			}
			break;

		case Left:
			if( m_position <= (255 - 16) )
			{ 
				m_pixelToSet = m_position - 16;
				
				if ( Regular == m_beltshift )
				{
					m_solenoidToSet = (m_position+8) % 16;
				}
				else if ( Shifted == m_beltshift )
				{
					m_solenoidToSet = m_position % 16;
				}
				
				if ( L == m_carriage )
				{
					m_pixelToSet = m_pixelToSet - 16;
				}

				// m_beltshift == Regular:
				
				// K: (m_pixelToSet - m_solenoidToSet) % 16 = ((m_position - 16) - ((m_position + 8) % 16)) % 16
				//                                          = (-16 - 8) % 16
				//                                          = 8

				// L: (m_pixelToSet - m_solenoidToSet) % 16 = ((m_position - 16 - 16) - ((m_position + 8) % 16)) % 16
				//                                          = 8 % 16
				//                                          = 8

				// m_beltshift == Shifted:

				// K: (m_pixelToSet - m_solenoidToSet) % 16 = ((m_position - 16) - (m_position % 16)) % 16
				//                                          = 0

				// L: (m_pixelToSet - m_solenoidToSet) % 16 = ((m_position - 16 - 16) - (m_position % 16)) % 16
				//                                          = 0


			}
			else
			{
				return false;
			}
			break;

		default:
			return false;
			break;
	}
	return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment