I found the bug in my code. The code snippet to insert in planner.cpp should be the following...
// If there has been a change in direction, add any hysteresis to the steps
if( block->direction_bits != previous_direction_bits )
{
if( (block->direction_bits & (1<<X_AXIS)) != (previous_direction_bits & (1<<X_AXIS)) )
{
block->steps_x += hysteresis_steps_x;
}
if( (block->direction_bits & (1<<Y_AXIS)) != (previous_direction_bits & (1<<Y_AXIS)) )
{
block->steps_y += hysteresis_steps_y;
}
if( (block->direction_bits & (1<<Z_AXIS)) != (previous_direction_bits & (1<<Z_AXIS)) )
{
block->steps_z += hysteresis_steps_z;
}
if( (block->direction_bits & (1<<E_AXIS)) != (previous_direction_bits & (1<<E_AXIS)) )
{
block->steps_e += hysteresis_steps_e;
}
block->step_event_count = max(block->steps_x, max(block->steps_y, max(block->steps_z, block->steps_e)));
}
previous_direction_bits = block->direction_bits;
Also, if you want to be able to set the hysteresis values with a command that you can send from the repetier G-Code text box, then you need to add the following to Marlin.pde.
This first one is just a comment so isn't necessary, but for completeness. Add this comment amongst the similar command comments near the top of the file...
// M99 - Set XYZE hysteresis values. To turn off hysteresis... (M99 X0 Y0 Z0 E0)
Search for M92 in the code to find the case statement that processes M commands. After M92, insert the following...
case 99: // M99
{
if(code_seen('X')) hysteresis_steps_x = code_value() ;
if(code_seen('Y')) hysteresis_steps_y = code_value() ;
if(code_seen('Z')) hysteresis_steps_z = code_value() ;
if(code_seen('E')) hysteresis_steps_e = code_value() ;
}
break;
Finally, we need to inform Marlin.pde of where the hysteresis variables are by adding the following to planner.h...
extern long hysteresis_steps_x;
extern long hysteresis_steps_y;
extern long hysteresis_steps_z;
extern long hysteresis_steps_e;
That's it. You can now change the hysteresis values from repetier like this...
M99 Z5000
That would add a 2mm hysteresis to the Z motion. Obviously way too much, but it lets you see that the code is working. You can set multiple values at the same time, for example, the following will turn off all hysteresis...
M99 X0 Y0 Z0 E0
Have fun with that. If you want me to explain anything in detail then I'll be happy to.