Monday, October 21, 2013

Configuring Multiple Home Switches on LCNC

Back in July, I showed how to configure a home switch with a BeBoPr board.  That blog post is a bit out of date now, as Charles has integrated many of the needed changes (including additions to the device tree config and setup.sh) into the main MachineKit branch.  Nice!

Still, you need to modify the default configuration a bit, and that post only showed how to set up a single axis.  This post will show how to configure multiple home switches in a few ways:

  • Axis-at-a-time: press the home key for each axis.  Common on machine tools; homing each axis separately avoids crashing a milling head into a vise or workpiece.
  • Sequential: each axis moves until it presses a home switch, in turn.  Common with 3D printers; the Z axis is typically homed last, so that the hotend doesn't scratch up the print surface.
  • Combined: all axes moves simultaneously, until each one hits the switch. Necessary with delta robot 3D printers, where moving just one axis might smash the head into one of the tower.  
You can follow the full explanation, or just skip to the bottom section and pull in the config changes for combined homing.



Which pins do I use?

The device tree config file has both pin and GPIO assignments together, with names.

In ~/linuxcnc/configs/ARM/BeagleBone/BeBoPr/BB-LCNC-BEBOPR-00A0.dts:

...
"P8.31", /* gpio0.10 X_Min */
"P8.32", /* gpio0.11 X_Max */
"P8.33", /* gpio0.9 Y_Max */
"P8.35", /* gpio0.8 Y_Min */
"P8.36", /* gpio2.16 J4_PWM  */
"P8.37", /* gpio2.14 Z_Max */
"P8.38", /* gpio2.15 Z_Min */
...

For reference, here are the relevant GPIO pins for the switch inputs, which are useful for verifying switch operation:

gpio-11 Xmax (closest to PWMs)
gpio-10 Xmin (next closest to PWMs)
gpio-9 Ymax
gpio-8 Ymin
gpio-78 Zmax  [gpio2.14] (78 = 2 * 32 + 14)
gpio-79 Zmin [gpio2.15] (79 = 2 * 32 + 15)


Note that XMax is closest to the side of the BeBoPr with the PWM outputs.  We'll need these GPIO numbers shortly.

Wiring the switches

I wired my switches NC, normally closed.  When the endstop triggers, the connection is open.  This way, if a wire breaks, the endstop will trigger as pressed.  The alternative is NO, normally open.

For each switch, use the two pins of the three that are closest to the stepper drivers.  Note that this layout does not match that used on the Printrboard, so I have to remove these from the connector using a tiny screwdriver to press on each pin latch.

Testing the switches

To show status:

sudo cat /sys/kernel/debug/gpio

Since I wired my endstops NC, they should show lo when pressed.  

Configuring One Axis

We need to do a few things for each axis:

  • Tell LinuxCNC that a specific IO pin will have a home switch connected and should be used with a particular axis.
  • Tell LinuxCNC that the switch is connected NC (inverted).
  • Tell LinuxCNC the direction and speed to move an axis until it homes.  

This requires changing two files, BeBoPr.ini, and BeBoPr.hal, both in: linuxcnc/configs/ARM/BeagleBone/BeBoPr/.

In the .hal file, at the bottom of the X axis config, add two lines:

--- a/configs/BeagleBone/BeBoPr/BeBoPr.hal
+++ b/configs/BeagleBone/BeBoPr/BeBoPr.hal
@@ -92,6 +92,11 @@ setp [PRUCONF](DRIVER).stepgen.00.steppin         0xA2
 # P8.44 PRU1.out4
 setp [PRUCONF](DRIVER).stepgen.00.dirpin          0xA3

+net home-x bb_gpio.p8.in-32 => axis.0.home-sw-in
+setp bb_gpio.p8.in-32.invert 1
+

 # ################
 # Y [1] Axis



In the .ini file, in the X axis config section:

diff --git a/configs/BeagleBone/BeBoPr/BeBoPr.ini b/configs/BeagleBone/BeBoPr/Be
index f3b92a5..2bb64f7 100755
--- a/configs/BeagleBone/BeBoPr/BeBoPr.ini
+++ b/configs/BeagleBone/BeBoPr/BeBoPr.ini
@@ -165,8 +165,8 @@ MIN_FERROR = 0.25

 HOME =                  0.000
 HOME_OFFSET =           0.00
-#HOME_SEARCH_VEL =       0.10
-#HOME_LATCH_VEL =        -0.01
+HOME_SEARCH_VEL =       -10.0
+HOME_LATCH_VEL =        10.0
 #HOME_USE_INDEX =        YES
 #HOME_IGNORE_LIMITS =    YES


Note that the search velocity should be the opposite polarity as the latch velocity.

That's it.  Restart LinuxCNC, press the Home button for the X axis, and the axis should move until the endstop is pressed.  

The process for adding the other 2 axes is the same, just with different pins; see the table above for the GPIO numbers to use.  Make sure to increment the axis number.

Sequential Homing

From the integrator manual:

4.3.9 HOME_SEQUENCE
Used to define a multi-axis homing sequence HOME ALL and enforce homing order (e.g., Z may not be homed if X is not yet homed). An axis may be homed after all axes with a lower HOME_SEQUENCE have already been homed and are at the HOME_OFFSET. If two axes have the same HOME_SEQUENCE, they may be homed at the same time. If HOME_SEQUENCE is -1 or not specified then this joint will not be homed by the HOME ALL sequence. HOME_SEQUENCE numbers start with 0 and there may be no unused numbers.

This tells us pretty much all we need to know.  HOME_SEQUENCE controls the order when it is defined.  To set up sequential homing, set HOME_SEQUENCE for each axis in BeBoPr.ini, setting this value to 0 for the first axis to home (presumably X).  You will need to add a line to each axis section; unlike before, HOME_SEQUENCE is not in there already but commented out.

When you've defined HOME_SEQUENCE, the Home button becomes a Home All button.


Combined Homing

To get all axes to start homing at the same time and stop each axis when it triggers the home switch, simply set HOME_SEQUENCE to 0 for each axis.

Getting the Code

To grab a branch with the sequential homing from within a running MachineKit instance:

cd ~/linxucnc
git remote add brandonheller https://github.com/brandonheller/linuxcnc.git
git fetch brandonheller
git checkout -b MachineKit-ubc+endstops brandonheller/MachineKit-ubc+endstops

To see the changes, run git log -p.

References


LinuxCNC wiki entry on homing and limits switches:
http://wiki.linuxcnc.org/cgi-bin/wiki.pl?Homing_And_Limit_Switch

Homing Configuration in the Integrator Manual, p41.
http://www.linuxcnc.org/docs/LinuxCNC_Integrator_Manual.pdf



No comments:

Post a Comment