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

Adds ramp acceleration to FREEZE_FEATURE #27592

Open
wants to merge 12 commits into
base: bugfix-2.1.x
Choose a base branch
from

Conversation

Switchleg1
Copy link

Simply removes the FREEZE_FEATURE instant halt code and adds a linear ramp of deceleration when pin is triggered and acceleration back to full speed on deactivation. Acceleration values are based on the current planner blocks and final jerk is set within the configuration file.

This is achieved by intercepting the calculated step_rate during Step::block_phase_isr() on each planner block stages (init/accel/decel/cruise) by tracking the time accumulated since triggering the freeze pin.

For example here is the deceleration implementation:

#if ENABLED(FREEZE_FEATURE)
if(frozen_time) check_frozen_time(step_rate);
#endif

// step_rate to timer interval and steps per stepper isr
interval = calc_multistep_timer_interval(step_rate << oversampling_factor);
deceleration_time += interval;

#if ENABLED(FREEZE_FEATURE)
check_frozen_pin(1, interval);
#endif

-->

Requirements

Should work on all boards, has been tested on mega2560.

Benefits

Prevents skipped steps when trying to pause a machine.

Configurations

Configuration_Adv.h

#define FREEZE_FEATURE
#if ENABLED(FREEZE_FEATURE)
#define FREEZE_PIN 5 // Override the default (KILL) pin here
#define FREEZE_JERK 2 // Completely halt when motion has decelerated below this value
#define FREEZE_STATE LOW // State of pin indicating freeze
#endif

adds FREEZE_JERK as in the example above

@Switchleg1
Copy link
Author

I apologize for the multiple updates. Copying over from another branch it appears I missed a few lines.

Prevents calculating unnecessary linear acceleration rate during path planning when using s_curve_acceleration.  General cleanup and commented out feature by default in configuration.
@thisiskeithb
Copy link
Member

This wording will also need to be adjusted (or options/defaults changed) since it will no longer be "instant":

* Instant freeze / unfreeze functionality

Switchleg1 and others added 4 commits December 18, 2024 20:53
User has the option of turning the laser off when motion is halted regardless of laser mode.  Once motion starts previous laser power is restored.

Also makes changes to feature description in config_adv.h
If freeze is triggered when machine is stationary it immediately sets solid flag.
@@ -500,7 +500,7 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
#endif

#if ENABLED(FREEZE_FEATURE)
stepper.frozen = READ(FREEZE_PIN) == FREEZE_STATE;
stepper.set_frozen_triggered(READ(FREEZE_PIN) == FREEZE_STATE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that without some debounce this state will oscillate, and will be reset if the pin is released. It will be simpler to set the frozen state with a single trigger of the pin and then not reset it to 0 when the pin is un-triggered, but if that is too sensitive then some debounce logic can help. It depends on the use case for freeze and the kind of switch that it's attached to.

Copy link
Author

@Switchleg1 Switchleg1 Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes though bouncing only affects whether the machine is accelerating or decelerating for the duration of the bounce and since it does not violate the machine abilities do we care? I have been using similar code on my CNC router using a standard rocker switch on ramps/AVR for the past month and a half and it's served me well without any noticable stuttering.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image (1)

Example of how a bounce would look.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also want to be able to restart the machine after a freeze condition. Some scenarios include material build up in the tool, also incorrect gcode where we would like to clear the current buffer (and current move) and restart without having to redial the machine back in as in the case of using the kill method. I had implemented this in repetier years ago and plan to complete this function in Marlin when I have a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants