Subroutines

O-word subroutines are not available in Smoothieware V1. SmoothieV2 implements a small subset of LinuxCNC-style O-word subroutines: definitions and calls. Parameters, expressions, conditionals, loops, and the full LinuxCNC O-code language are not supported.

Subroutines group several commands under one alphanumeric name. If you keep sending the same group of commands, give it a name and call it when you need it. Start with o <name> sub and finish with o <name> endsub. To run those lines, send o <name> call.

o park sub
G0 Z20
G0 X0 Y0
M5
o park endsub

o park call

A space is required between o and the name. The name may contain letters or numbers.

Commands

Command Result
o <name> sub Starts a definition and replaces an existing routine with the same name
o <name> endsub Ends the active definition
o <name> call Dispatches each stored line in order
o <name> list Prints the stored lines; intended as a development aid
o <name> save Writes the definition to <name>.sub in the current directory; intended as a development aid

Smoothie stores definitions in RAM. They disappear on reset unless you save and load them from storage.

Loading saved routines

o park save creates park.sub with the sub and endsub lines included. After a reset, use the Player module (play) to read the file back into RAM, then call the routine when you need it. Playing the definition records its lines; it does not call the routine.

The save command overwrites a file of the same name in the current working directory. Use cd to choose the directory before saving.

Limits

  • Only one definition can be active on a console connection.
  • Defining a name again replaces its old lines.
  • Calling an undefined name reports an error.
  • Calls dispatch stored commands without waiting for each move to finish before dispatching the next line. Normal planner ordering still applies.
  • LinuxCNC parameters, expressions, conditionals, and loops are unavailable, and so are nested language constructs from LinuxCNC.

Source

CommandShell.cpp implements the O-word command subset.

This is a wiki! If you'd like to improve this page, you can edit it on GitHub.