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

[FR] shared_stepper for tilting carriages #5190

Closed
DrumClock opened this issue Jan 24, 2022 · 19 comments
Closed

[FR] shared_stepper for tilting carriages #5190

DrumClock opened this issue Jan 24, 2022 · 19 comments

Comments

@DrumClock
Copy link

DrumClock commented Jan 24, 2022

[gcode_macro T1]
gcode:
SET_GCODE_OFFSET Z=0.100 MOVE=1 # Adjust z-height
SET_SERVO SERVO=extruder_servo angle=100 # Position second extruder
SET_GCODE_OFFSET X=5 # Account for different X offset
ACTIVATE_EXTRUDER EXTRUDER=extruder1

A Switching Extruder is a dual extruder that uses a single stepper motor to drive two filaments,
but only one at a time. The servo is used to switch the side of the extruder that will drive the filament.
The E motor also reverses direction for the second filament.

TEST 1:

[duplicate_pin_override]
pins: PB5, PB6, PC12

[extruder]               ### stepper motor E0
step_pin: PB5
dir_pin: PB6            ### normal rotation fot T0 (CW)
enable_pin: !PC12
...

[extruder1]             ### stepper motor E0
step_pin: PB5
dir_pin: !PB6          ### reverse rotation for T1 (CCW)
enable_pin: !PC12
....

I wanted to use this setting for toolhead, where two hotends (T0 / T1) use same stepper motor (E0).
When using this configurations the following problem occurs:

ACTIVATE_EXTRUDER EXTRUDER = extruder
G1 E10 >>>> direction rotation of stepper motor E0 is OK (CW)

ACTIVATE_EXTRUDER EXTRUDER = extruder1
G1 E10 >>>> direction rotation of stepper motor E0 is OK (CCW)

Any further change to ACTIVATE_EXTRUDER EXTRUDER no longer changes the direction of rotation
of the motor and remains after the second change from G28.

I also couldn't set [tmc2209 extruder] and [tmc2209 extruder1] stepper motor driver via single wire UART, when they use the same stepper driver for motor E0.

TEST 2:

As a temporary solution, I used the [extruder] setting for T0 and [heater_generic t1] for T1.

It is necessary to G1 modification was required:

[gcode_macro G1]
rename_existing: G1.1
gcode:
    # E-rotation revers for HotEnd 1/T1)
    {% set user_vars = printer["gcode_macro VARIABLE"] %}
    {% set emultiplier = -1.0 if user_vars.active_tool == 1 else 1.0 %}
    {% set _E = params.E|default(0)|float * emultiplier %}
    # Get parameters
    {% set X = '' if 'X' not in params else " X%s" % params.X %}
    {% set Y = '' if 'Y' not in params else " Y%s" % params.Y %}
    {% set Z = '' if 'Z' not in params else " Z%s" % params.Z %}
    {% set E = '' if 'E' not in params else " E%s" % _E %}
    {% set F = '' if 'F' not in params else " F%s" % params.F %}
    G1.1{"%s%s%s%s%s" % (X,Y,Z,E,F)}

Unfortunately, it is necessary to set min_extrude_temp: 0 so that printing only works with the T1 tool when the T0 hotend is off.
Of course no configurations of type pressure_advance, max_extrude_cross_section and others which are in section [extruder] are possible for T1.

A POSSIBLE SOLUTION

Add an option in the section for "extruder1", "extruder2", "extruder3" etc. this:

[extruder1]

shared_stepper:
#   If this extruder uses the same stepperr already defined for another
#   extruder then place the name of that extruder here. 
#   The default is to not reuse an existing extruder.

reverse_dir: False
#  If the shared extrude needs reversing rotation, set to True. 
#  The default setting is False

@vladbabii
Copy link

A different temporary solution could be to override G0 and G1 with macros and put an if extruder=0 then move in the normal direction and if extruder=1 then move in the opposite direction

@DrumClock
Copy link
Author

Hi @vladbabii
YES - I used override G0 and G1 with macros in TEST 2
NO - section [extruder] and [extruder1] cannot be defined because that uses a single stepper motor to drive two filaments

Must be defined [extruder] setting for T0 and [heater_generic t1] for T1.
However, this does not allow the use of the following functions, for example:
min_extrude_temp pressure_advance max_extrude_cross_section

@Tircown
Copy link
Contributor

Tircown commented Jan 30, 2022

#5210 provides a robust solution.

@Sineos
Copy link
Collaborator

Sineos commented Feb 18, 2022

Topic seems to be concluded. For further discussions please do not hesitate to open a new topic on https://klipper.discourse.group.

@Sineos Sineos closed this as completed Feb 18, 2022
@DrumClock
Copy link
Author

Hi @Sineos , the topic is solved using # 5210 only half ..... you ** still can't share one stepper motor for two extruders **

@Sineos
Copy link
Collaborator

Sineos commented Feb 18, 2022

See https://klipper.discourse.group/t/switching-between-extruders/2020 and generally continue on Discourse if needed

@DrumClock
Copy link
Author

Hi @Sineos
.... I guess we don't understand I have two hotends, two filaments but only one stepper for the extruder .....

The [extruder] and [extruder1] sections cannot be defined because they have a common stepper motor

@KevinOConnor
Copy link
Collaborator

KevinOConnor commented Feb 18, 2022

If we allowed an extruder object to be created without a stepper, would that help your setup? That is, if you could create an [extruder] config section defining the hotend/stepper and an [extruder1] config section defining just the second hotend, would that be sufficient?

-Kevin

@DrumClock
Copy link
Author

If the second [extruder1] also contained functions such as:

nozzle_diameter:
filament_diameter:
max_extrude_cross_section:
instantaneous_corner_velocity: 
max_extrude_only_distance: 
max_extrude_only_velocity:
max_extrude_only_accel:
pressure_advance: 
pressure_advance_smooth_time: 

So probably yes, I would test that.

Otherwise, it can be done by defining [extruder] and [heater_generic t1] but it has disadvantages regarding the parameters that are only in the extruder section.

Another disadvantage is the g-code "T" when:
[extruder] = T0
[heater_generic t1] = user define T1

However, if I add another [extruder1] = T1 there will be a conflict for command M105, M104 and M109 ....

I don't know how to deal with it to be the best. I think it would help to just share the stepper motor of one extruder with another.

I like to try it, it's not a problem for me, I can configure the printer's HW very quickly.

Maybe be inspired by FW Marlin who has the SWITCHING EXTRUDER function when one stepper is used for two extruders.
The result is that T0 (extruder) has the reverse speed than T1 (extruder1)

I'll try TEST 1 above with the same step_pin, dir_pin and nable_pin and
I solve the reversal of rotation with SET_EXTRUDER_ROTATION_DISTANCE

@DrumClock
Copy link
Author

DrumClock commented Feb 18, 2022

I'll try TEST 1 above with the same step_pin, dir_pin and nable_pin and
I solve the reversal of rotation with SET_EXTRUDER_ROTATION_DISTANCE

----- it seems to work but only to be used [extruder] ---

for T0 =
ACTIVATE_EXTRUDER EXTRUDER=extruder
SET_EXTRUDER_ROTATION_DISTANCE EXTRUDER=extruder DISTANCE={dafault_rotation * 1}

for T1 =
ACTIVATE_EXTRUDER EXTRUDER=extruder
SET_EXTRUDER_ROTATION_DISTANCE EXTRUDER=extruder DISTANCE={dafault_rotation * -1}

tested so far without printing and temp hotend only the direction of rotation of the stepper

@DrumClock
Copy link
Author

so you can't use min_extrude_temp for [extruder1]

ie. if[extruder] .temp = 0and [extruder1] .temp = 200
it does not work like that

@DrumClock
Copy link
Author

DrumClock commented Feb 18, 2022

Hi @KevinOConnor
this looks functional
I used some unconnected pins for the [extruder1] configuration.

maybe it would be enough not to enter pins or "dummy"
(in this case it is not necessary to define TMC stepper driver configuration)

step_pin: dummy
dir_pin: dummy
enable_pin: dummy

I will test tomorrow on real 3D printing

[gcode_macro SET_HOTEND]
description: Set HotEnd: SET_HOTEND E=[0|1]
gcode:
  
    {% set hotend = params.E|int %}
  
  {% set default_servo = (1,1)[hotend] %}   
  {% set dafault_extruder =('extruder','extruder1')[hotend] %}
  {% set sync_extruder =('extruder1','extruder')[hotend] %} 
  {% set dafault_rotation = printer.configfile.settings[dafault_extruder].rotation_distance * ((1,-1)[hotend]) %}
   

  #### Tilt the toolhead 
  {% if hotend in [0,1] %}     
     ACTIVATE_EXTRUDER EXTRUDER={dafault_extruder}
     SET_EXTRUDER_ROTATION_DISTANCE EXTRUDER={dafault_extruder} DISTANCE={dafault_rotation}
     SET_EXTRUDER_ROTATION_DISTANCE EXTRUDER={sync_extruder} DISTANCE={dafault_rotation}
 
   {% if  hotend == 0 %}
     SYNC_EXTRUDER_MOTION EXTRUDER={dafault_extruder} MOTION_QUEUE={dafault_extruder}     
     SYNC_EXTRUDER_MOTION EXTRUDER={sync_extruder} MOTION_QUEUE={sync_extruder} 

     SET_SERVO SERVO={default_servo} angle=25     # position for HotEnd 0

   {% elif  hotend == 1 %}
     SYNC_EXTRUDER_MOTION EXTRUDER={sync_extruder} MOTION_QUEUE={dafault_extruder}
     SYNC_EXTRUDER_MOTION EXTRUDER={dafault_extruder} MOTION_QUEUE={sync_extruder}

     SET_SERVO SERVO={default_servo} angle=155     # position for HotEnd 1

   {% endif %}

     G4 P800  
     SET_GCODE_VARIABLE MACRO=VARIABLE VARIABLE=active_tool VALUE={hotend}   
  {% else %}
      RESPOND TYPE="error" MSG="Params E="{hotend} " not available for define HotEnd. "
  {% endif %}
 
  #### End of switching 

@DrumClock
Copy link
Author

so I simplified the macro and I go for 3D printing

[gcode_macro SET_HOTEND]
description: Set HotEnd: SET_HOTEND E=[0|1]
gcode:
  
  {% set user_vars = printer["gcode_macro VARIABLE"] %}
  {% set hotend = params.E|default(user_vars.active_tool)|int %}
  
  {% set default_servo = (1,1)[hotend] %}  
  {% set default_angel = (user_vars.angle_e0, user_vars.angle_e1)[hotend] %} 

  {% set default_extruder =('extruder','extruder1')[hotend] %}
  {% set sync_extruder =('extruder','extruder')[hotend] %} 
  {% set dafault_rotation = printer.configfile.settings[default_extruder].rotation_distance  * ((1,-1)[hotend]) %}
   

  #### Tilt the toolhead 

  {% if hotend in [0,1] %} 

  #### set active extruder  
     ACTIVATE_EXTRUDER EXTRUDER={default_extruder}    
     SET_EXTRUDER_ROTATION_DISTANCE EXTRUDER={sync_extruder} DISTANCE={dafault_rotation}
     SYNC_EXTRUDER_MOTION EXTRUDER={sync_extruder} MOTION_QUEUE={default_extruder}
   
  #### set servo position for HotEnd 
     SET_SERVO SERVO={default_servo} angle={default_angel}
     G4 P{user_vars.delay_1} 
 
  #### save variable
     SET_GCODE_VARIABLE MACRO=VARIABLE VARIABLE=active_tool VALUE={hotend}   

  {% else %}
      RESPOND TYPE="error" MSG="Params E="{hotend} " not available for define HotEnd. "
  {% endif %}
 
  #### End of switching 

@DrumClock
Copy link
Author

DrumClock commented Feb 19, 2022

Printing is OK

Terminal:

Send: set_hotend e=1
Recv: // Activating extruder extruder1
Recv: // Extruder 'extruder' rotation distance set to -21.293000
Recv: // Extruder stepper now syncing with 'extruder1'

Recv: ok
Send: set_hotend e=0
Recv: // Activating extruder extruder
Recv: // Extruder 'extruder' rotation distance set to 21.293000
Recv: // Extruder stepper now syncing with 'extruder'

Conclusion:

If it is possible to omit the definition (or not enter) in the [extruder1] section step_pin, dir_pin, enable_pin it will work

@Tircown
Copy link
Contributor

Tircown commented Feb 19, 2022

Just a thought, an universal solution would be to split extruders and extruder steppers into the config too.
One can define any stepper_e section needed, [stepper_e], [stepper_e1], ..., and associate them in the [extruder] section throught the parameter extruder_stepper: stepper_e. [extruder] and [extruder1] sections can use the same extruder_stepper value.
As backward compatibility one can still use the step, dir and enable pins in the extruder section.
The reverse direction can be accomplished in the activation macro or another solution would be to override or keep the rotation_distance in the extruder section (with a negative value for extruder1).

Config splitted:

[stepper_e]
step_pin:
dir_pin:
enable_pin:
microsteps:
rotation_distance:
rotation_distance:
#full_steps_per_rotation:
#gear_ratio:

[tmc2209 stepper_e]
...

[extruder]
extruder_stepper: stepper_e
nozzle_diameter:
filament_diameter:
#max_extrude_cross_section:
#instantaneous_corner_velocity: 1.000
#max_extrude_only_distance: 50.0
#max_extrude_only_velocity:
#max_extrude_only_accel:
#pressure_advance: 0.0
#pressure_advance_smooth_time: 0.040
heater_pin:
#max_power: 1.0
sensor_type:
sensor_pin:
#pullup_resistor: 4700
#smooth_time: 1.0
control:
pid_Kp:
pid_Ki:
pid_Kd:
#max_delta: 2.0
#pwm_cycle_time: 0.100
#min_extrude_temp: 170
min_temp:
max_temp:

@DrumClock
Copy link
Author

DrumClock commented Feb 19, 2022

Yes, good idea to split extruder and stepper and allow the negative value rotation_distance to be specified for reversal

@DrumClock
Copy link
Author

DrumClock commented Feb 20, 2022

Hi, or for backward compatibility, add the extruder_stepper: option to the extruder section and leave it up to the user to define pins or stepper.

@KevinOConnor
Copy link
Collaborator

FYI - I created PR #5294 .

It's possible to separate out steppers from extruders in the general case, but I fear that will seem "pedantic" to most users - as the vast majority of users have a single hotend and a single extruder motor. So, I think it makes sense to use a single config section for that common case.

Separately, note that pressure advance is currently always specified for the stepper - not the extruder motion queue. So, both before and after PR #5294 it would be necessary for Tx macros to explicitly manage pressure advance if a single stepper is reconfigured to push a different type of filament.

-Kevin

@DrumClock
Copy link
Author

Yes, I agree with you on both points.

I'm ill as soon as I'm fit I'll test the PR5294

@github-actions github-actions bot locked and limited conversation to collaborators Aug 21, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants