Saturday, August 5, 2017

Setting Up a CoreXY Printer's Origin and EndStops

In this explanation, I'm going to use SmoothieWare as an example for the config file entries, but there are similar entries for whatever firmware you are using.  Look them up!

If your printer is not a coreXY type, please refer to this post for setting up its origin and end stops.

I will refer to the motor that connects to the X or alpha output on the controller as the alpha motor, and the motor connecting to the Y or beta output as the beta motor.  The Z axis motor connects to the Z or gamma output.  I will largely ignore the Z axis because it's pretty straightforward- you're going to have an endstop at the Z=0 position at the top of the Z axis.

CoreXY motion can be a little confusing when trying to set up endstops and motor direction in firmware.  The printer's firmware needs to know:
  1. That a corexy mechanism is being used
  2. The locations of the printer's endstop switches and origin
  3. The length of each axis
  4. The direction to spin each motor


Step by step CoreXY firmware setup

  1. Build your printer, and mount the motors and limit switches.
  2. Choose origin location, either left-front or right-rear
  3. Set home_to direction for each axis, plug in the endstops
  4. Assign appropriate ordinate values for each axis
  5. Set motor rotation directions for all three motors.

Mounting Motors and Switches

You can mount the motors either pulley-up or pulley-down or one up and one down - it doesn't matter.  You can put limit switches at either end of either axis, but you have to make appropriate assignments in the firmware and plug the switches into the appropriate inputs on the controller board.  We'll get to that in a minute.


Example corexy layout , viewed from the top of the printer, that will be used to illustrate firmware configuration.  Motors are at the front of the machine, origin is at the left-front (L-F) corner, X axis endstop is at the right (bright green box), Y axis endstop is at the rear (red box).


First things first: you have to tell the controller that your printer uses a corexy mechanism.  You do that in SmoothieWare by using this line in the config file:

arm_solution corexy

In RepRap Firmware (Duet board):

         M667   S1 ;  set up corexy kinematics

Origin Location


The printer's origin (0,0,0) has to be located at the left-front (L-F) corner or the right-rear (R-R) corner in order to match the right-hand-rule coordinate space used in CAD and slicing software, otherwise your prints will come out mirrored.  Slicers commonly default to showing the origin at the left-front, and the jog controls in Pronterface assume a left-front origin, so you can save yourself some mental gymnastics by doing the same.  There is no explicit statement in the config file that tells the controller where the origin is.  Its location is implied by the homing directions and endstops used.

The Z=0 position is at the level of the extruder nozzle.

Setting "home_to" Direction for Each Axis


If the switch is at the origin end of its axis, you'll set that axis for home_to_min.  If it's at the far end, set that axis for home_to_max.  

Printer
Origin
X axis
Y axis
endstop location
alpha home-to
endstop location
beta home-to
L-F
left
min
front
min
L-F
right
max
front
min
L-F
left
min
rear
max
L-F
right
max
rear
max
R-R
left
max
front
max
R-R
right
min
front
max
R-R
left
max
rear
min
R-R
right
min
rear
min

Let's say that the origin is at the L-F and the switches are located at the right and rear.  In SmoothieWare, you'll have entries like this:

corexy_homing true
alpha_homing_direction home_to_max
beta_homing_direction home_to_max
gamma_homing_direction home_to_min
In the example above, the alpha and beta endstop switches are both located at the maximum ends of the X and Y axes, so you have to plug the endstop switches into the Xmax and Ymax endstop inputs on the controller board.  The Z endstop should plug into the Zmin endstop input, assuming you have positioned the Z limit switch at the physical top of the Z axis, at the level of the extruder nozzle.

In RepRap Firmware (Duet board) it will look like this:

          M574 X2 Y2 Z1 S1              ; Set active high endstops

X2 and Y2 define the positions of the endstops at the maximum end of the X and Y axes.  Z1 means the Z axis endstop is at the minimum end of the Z axis.  S1 sets them as active high.  The endstop switches will be plugged into the X, Y, and Z endstop inputs (there are no min and max inputs, just a single input for each axis).

Set Ordinate Values for Each Axis


Measure the length of the X axis by manually moving the extruder carriage from the far left to the far right.  Do the same for the Y axis by measuring the distance the extruder nozzle moves from the front to the back of the machine.  And, of course, measure the usable Z range of motion.

Let's say the X axis range of motion is 380 mm, the Y axis is 340 mm, and the Z axis is 400 mm.  In SmoothieWare you'll have entries like this:

alpha_min 0
alpha_max 380
beta_min 0
beta_max 340
gamma_min 0
gamma_max 400
In RepRap Firmware (Duet board) the assignments will look like this:

          M208 X0:380 Y0:340 Z0:400          ; Set axis minima:maxima

Setting Direction of Rotation


Setting direction of rotation is done either by reversing the connectors at the motors or controller board (only with power off or you may destroy the motor driver chip!), or by inverting the direction logic via the firmware.  

Here is how the mechanism works, ignoring any of the electrical stuff (rotation of the drive pulleys, viewed from above, motors at the front of the mechanism):

Left Motor
(alpha)
Right Motor
(beta)
Extruder Motion
Toward:
CW
CW
left
CW
CCW
front
CCW
CW
rear
CCW
CCW
right
CW
off
left-front
CCW
off
right-rear
off
CW
left-rear
off
CCW
right-front

Remember, when homing the mechanism, the location of the switches are important, not the location of the origin.  Homing should always send the extruder carriage toward the switches.  Using the table above, just the top four entries, notice that, when homing, if the switches are at the
  • left and front, the alpha motor must turn CW.  
  • left and rear, the beta motor must turn CW.
  • right and front, the beta motor turns CCW
  • right and rear, the alpha motor turns CCW
In Smoothieware, the motor rotation direction is set by these lines in the config file:

alpha_dir_pin 0.5 
beta_dir_pin 0.11
gamma_dir_pin 0.20
We can use the table to easily set the motor rotation directions.  For example, if the switches are located at the right and rear, manually push the extruder carriage to the center of the build area, tell the controller to home all axes (G28), and watch the rotation of the alpha motor.  It should turn CCW.  If it doesn't, reverse its direction either by shutting off power and reversing the cable connection to the motor, or by appending a "!" in the config file, like this:

alpha_dir_pin 0.5!

Once the alpha motor is turning the right way, push the extruder carriage to the center of the XY space, send another home-all-axes command (G28), and watch the mechanism.  If it moves toward both switches, both motors are turning in the right directions.  If not, reverse the beta motor direction like this:
beta_dir_pin 0.11!
The Z motor should likewise move the bed toward the limit switch, normally at the level of the extruder nozzle.  If you have positioned the switch at that location, Z is homing to minimum (Z=0) and the G28 command should drive the bed upward, toward the switch.

In RepRap Firmware (Duet board), P selects the driver and S sets the rotation direction:

          M569 P0 S1          ; motor A goes forward
          M569 P1 S0          ; motor B goes backward
          M569 P2 S1          ; Z motor goes forward

Endstop wiring


If you are using simple, reliable, snap-action switches for the endstops, they can be wired either normally open (NO) or normally closed (NC).  For safety, it is best to wire them NC.  That way, if a wire breaks or becomes disconnected the controller will interpret that as a switch closure and it will quickly become apparent that something is wrong.

The SmoothieBoard config file defaults to NC.  If you wire any of the switch(es) NO, you have to invert their inputs in the config file.  Refer to the SmoothieWare endstop configuration documentation here.

Be sure to plug the endstop switches into the appropriate inputs on the controller board.  For example, if the Y axis endstop is at the maximum end of the Y axis, plug that endstop switch into the Ymax endstop input.

The Duet controller boards have only one endstop input per axis, and it is defined as a minimum or maximum using the M574 command as above.

15 comments:

  1. I am having problems setting up my homing/end stops.



    When homing X or Y the opposite motor keeps on travelling, i.e if I home X axis, once the end stop is triggered the X motor stops but the Y motor keeps turning.



    I have tested the end stops with G code and they're all working as they should. I have also reduced the homing speed, to no avail. Please follow paste bin link for config. apologies if I have missed any other information. https://pastebin.com/9iP1DPyx



    Specs are as follows:

    Frame is a Ratrig coreXY

    Smoothie board

    Silencioso external drivers

    Nema 17 steppers



    I have been trying to figure out WTF is wrong for a while now and it is doing my head in! Any help would be greatly appreciated! :)

    Comment

    ReplyDelete
    Replies
    1. Check line 188: #corexy_homing true
      Remove the # and I think it will work.

      Delete
  2. Hi. Wanted to say a big thanks to you! I struggled with my corexy (HEVO) stupidly long, but as soon as I saw your direction rotation table, everything was fixed within 5 minutes. Thanks!

    ReplyDelete
  3. Hi, great write up! A silly question: In your picture, you refer to the stepper motors as alhpa and beta. The boards mark the sockets with X and Y. Am I correct in thinking that the alpha stepper goes into the X socket and the beta stepper into the Y one? Cheers.

    ReplyDelete
    Replies
    1. Yes, I used the alpha and beta designations because in a corexy mechanism there is no X motor and no Y motor. The controller boards are usually labeled X and Y, so yes, plug the alpha motor into the X driver and the beta motor into the Y driver.

      Delete
  4. The following is for a cube XY printer with a Z travel bed with "zero" at the top.

    I may figure this out on my own before you see this, but where does the Z endstop switch go in relation to the hot end? Obviously the bed needs to be able to get very close to the hot end, if not touch it "just to be sure." At the same time, the Z endstop switch keeps the Z steppers from driving the bed into the hard stops. But, the hot end is slightly lower than that, so it seems like the controller board has to stop the bed short of the endstop switch so that it doesn't crash into the hot end, yes? I'm guessing that the offset is set during configuration somewhere, true?
    This still leaves the nagging situation of "homing" the Z-bed... where does it go. If it's right after power up, it seems like it'll drive upward until it sees the endstop switch, but per the above, it means that it'll smack the hot end, so I'm missing something! Thanks

    ReplyDelete
    Replies
    1. The Z endstop usually goes at the top of the Z axis where Z=0. In my printer, the XY home position is off the bed so it can't crash when homing Z. If your XY home position is on the bed, you'll have to be careful about homing Z for the first time.

      When I set up my printer, with the bed well below the nozzle, I moved the nozzle to (0,0) in XY space (the center of the bed) and then moved the Z=0 endstop so it would trigger about 5 mm above the bed, then used the M564 command to disable motion limits, then slowly raised the bed until it just touched the nozzle. Then I physically moved the Z=0 switch to the position that just barely triggered it and bolted it down.

      I think you can place the switch so that it triggers when the nozzle is a few mm away from the bed and then assign a positive offset to the Z ordinate (say 5 mm or so). If you set the Z minimum value to zero, it should be possible to travel to Z=0 even though the endstop is at Z=5.

      Delete
    2. Oh, and somewhat related, where do people put their Z stop if they have three Z steppers? I mean, I realize they pick one stepper and use that, but then that leaves two steppers that the controller doesn't know where they are. I'll guess that an auto level figures it out off the one endstop switch and the bed sensor.

      Delete
    3. I haven't built an auto-leveled machine, so I am not really familiar with the techniques used, but I think that in machines with 3 independent Z axis motors and auto bed leveling, the bed sensor on the extruder carriage is used to locate the Z=0 point as well as to handle the leveling and mesh compensation.

      Delete
  5. I know that the Z endstop switch "synchronizes" the bed so that the controller knows where the bed is, THEN it can continue upward past that point slightly to end up right at the nozzle, correct?

    ReplyDelete
    Replies
    1. Yes, the purpose of homing any axis is to the extruder nozzle at a known location with respect to the bed in all three dimensions. That known location doesn't have to be at the ends of the axes.

      Delete
  6. The "light went on for me" when I realized that the endstop switch actually serves two purposes:
    1. Tells the controller the part is at a known point in its travel.
    2. Prevents the controller from driving the part into a hard stop.

    #2 only prevent the issue at one end. It's left to the controller to count the steps needed to get to the other end, but stop short since there is no switch at that end.

    ReplyDelete
    Replies
    1. The endstops define a single point (home) at which the coordinates are known. All other locations are counted from that point. AFAIK, 3D printing firmware only activates the endstops when homing, so it wouldn't do any good to put more endstop switches at the home-opposite end of each axis. In a properly functioning machine, counting works fine. problems start when the machine malfunctions and the extruder/bed end up at a different location from where the controller thinks they are. That sort of thing can lead to layer shifting, head crashes, etc. Fortunately, those sorts of problems are easily avoided by careful printer design and construction, and proper configuration- don't set jerk/acceleration too high, etc.

      Delete
  7. Thanks for the quick replies. Later, I found this on the Duet3D pages regarding an example of a two-stepper Z bed:
    "... Make sure that the two endstops are defined in the same order in the M574 command as the corresponding Z motors in your M584 command. For the example above, M584 Z2:4 would be correct, assuming one Z motor is plugged into driver 2 (Z driver on Duet 2) and its endstop is plugged into zstop, while the second Z motor is plugged into driver 4 (E1 driver on Duet 2) and its endstop is plugged into the E1 endstop pins..."

    So it appears that they expect a stopswitch on every stepper.

    The above quote came from: https://duet3d.dozuki.com/Wiki/Bed_levelling_using_multiple_independent_Z_motors#Section_In_RepRapFirmware_Num_3

    ReplyDelete

Leave comments or a questions here and I'll try to post a response as soon as I can.