Stepdance Software Library
Loading...
Searching...
No Matches
Homing Class Reference

Used for running a homing routine on a machine. More...

#include <homing.hpp>

Inheritance diagram for Homing:

Public Member Functions

void begin ()
 Initialize the Homing plugin. Must be called during setup().
void add_axis (uint8_t limit_switch_port, DecimalPosition value_at_limit, int direction, DecimalPosition velocity, BlockPort *target)
 Register an axis to home. The homing routine will go through the regisered axes and home each one in the order in which they are registered.
void start_homing_routine ()
 Launch the homing routine (machine will move until it hits the limit switch for each registered axis).

Protected Member Functions

void loop ()

Detailed Description

Used for running a homing routine on a machine.

The Homing plugin lets the user define a number of axes they want to home Here's an example of how to configure and run a homing routine :

#define module_driver
// Machine Selection
// Choose one of the two machines below
// #define axidraw
#define pocket_plotter
#include "stepdance.hpp" // Import the stepdance library
// -- Define Input Ports --
InputPort input_a;
// -- Define Output Ports --
// Output ports generate step and direction electrical signals
// Here, we control two stepper drivers and a servo driver
// We choose names that match the labels on the PCB
OutputPort output_a; // Axidraw left motor
OutputPort output_b; // Axidraw right motor
// -- Define Motion Channels --
// Channels track target positions and interface with output ports
// Generally, we need a channel for each output port
// We choose names that match the axes of the AxiDraw's motors
Channel channel_a; //AxiDraw "A" axis --> left motor motion
Channel channel_b; // AxiDraw "B" axis --> right motor motion
// -- Define Kinematics --
// Kinematics convert between two coordinate spaces.
// We think in XY, but the axidraw moves in AB according to "CoreXY" (also "HBot") kinematics
KinematicsCoreXY axidraw_kinematics;
// -- Time based interpolator (used for testing the coordinate system) --
// -- Homing --
Homing homing;
// -- RPC Interface --
RPC rpc;
void setup() {
// -- Configure and start the output ports --
output_a.begin(OUTPUT_A); // "OUTPUT_A" specifies the physical port on the PCB for the output.
output_b.begin(OUTPUT_B);
// Enable the output drivers
enable_drivers();
// -- Configure and start the channels --
channel_a.begin(&output_a, SIGNAL_E); // Connects the channel to the "E" signal on "output_a".
// We choose the "E" signal because it results in a step pulse of 7us,
// which is more than long enough for the driver IC
channel_a.invert_output(); // CALL THIS TO INVERT THE MOTOR DIRECTION IF NEEDED
channel_b.begin(&output_b, SIGNAL_E);
channel_b.invert_output();
#ifdef axidraw
channel_a.set_ratio(25.4, 2032);
channel_b.set_ratio(25.4, 2032);
#endif
#ifdef pocket_plotter
channel_a.set_ratio(40, 3200); // Sets the input/output transmission ratio for the channel.
channel_b.set_ratio(40, 3200);
#endif
// This provides a convenience of converting between input units and motor (micro)steps
// For the pocket plotter, 40mm == 3200 steps (1/16 microstepping)
// -- Configure and start the kinematics module --
axidraw_kinematics.begin();
axidraw_kinematics.output_a.map(&channel_a.input_target_position);
axidraw_kinematics.output_b.map(&channel_b.input_target_position);
// -- Configure Homing --
init_homing();
// TBI (can be used to test that the homing works properly)
tbi.begin();
tbi.output_x.map(&axidraw_kinematics.input_x);
tbi.output_y.map(&axidraw_kinematics.input_y);
rpc.begin();
// Start the homing routine: axes will move until the limit switch button is hit
// See init_homing() function to configure the homing routine and axes
// {"name": "home_axes"}
rpc.enroll("home_axes", home_axes);
// {"name": "go_to_xy", "args": [6, 5, 10]}
// args are: absolute X, absolute Y, speed (mm/s)
rpc.enroll("go_to_xy", go_to_xy);
// -- Start the stepdance library --
// This activates the system.
dance_start();
}
void loop() {
dance_loop(); // Stepdance loop provides convenience functions, and should be called at the end of the main loop
}
// This function registers the two axes we want to home in (X and Y)
// and provides specific info about the physical machine setup (homing button pins, home coordinates).
// The order in which the axes are added specifies the order in which they will be homed (eg first X then Y here).
// Note that the axes to home are workspace axes (XY) and not stepper motor axes (AB).
// Generally, we want to home in the axes that we think of as "design" axes, those in which we want to be able to specify absolute coordinates in.
void init_homing() {
Serial.println("Initialized homing");
homing.add_axis(
LIMIT_A, // Stepdance board port for the limit switch
0, // Coordinate value we want to assign at the limit switch
HOMING_DIR_BWD, // Direction in which the machine should jog (backward or forward?) to hit the switch
5, // Speed at which the machine should jog to find the limit
&axidraw_kinematics.input_x // Blockport corresponding to the axis to home
);
homing.add_axis(
LIMIT_B, // Stepdance board port for the limit switch
0, // Coordinate value we want to assign at the limit switch
HOMING_DIR_BWD, // Direction in which the machine should jog (backward or forward?) to hit the switch
5, // Speed at which the machine should jog to find the limit
&axidraw_kinematics.input_y // Blockport corresponding to the axis to home
);
homing.begin();
}
void home_axes() {
// Calling this method launches the homing routine (machine will move until it hits its limit switches)
Serial.println("start homing");
}
void go_to_xy(float x, float y, float v) {
tbi.add_move(GLOBAL, v, x, y, 0, 0, 0, 0); // mode, vel, x, y, 0, 0, 0, 0
}

Member Function Documentation

◆ add_axis()

void Homing::add_axis ( uint8_t limit_switch_port,
DecimalPosition value_at_limit,
int direction,
DecimalPosition velocity,
BlockPort * target )

Register an axis to home. The homing routine will go through the regisered axes and home each one in the order in which they are registered.

Parameters
limit_switch_portStepdance board port for the limit switch.
value_at_limitCoordinate value we want to assign at the limit switch.
directionDirection in which the machine should jog (backward or forward?) to hit the switch.
velocitySpeed at which the machine should jog to find the limit.
targetBlockport corresponding to the axis to home.

The documentation for this class was generated from the following file: