APIs, concepts, guides, and more
Axis: Basic Motion

Basics for getting up and running with Axis motion in RapidCode for Python.

Warning
This is a sample program to assist in the integration of the RMP motion controller with your application. It may not contain all of the logic and safety features that your application requires. We recommend that you wire an external hardware emergency stop (e-stop) button for safety when using our code sample apps. Doing so will help ensure the safety of you and those around you and will prevent potential injury or damage.

The sample apps assume that the system (network, axes, I/O) are configured prior to running the code featured in the sample app. See the Configuration page for more information.


In this page:


📜 Axis Basic Motion

Learn how to command basic Axis motion in Python.

""" Sample application that demonstrates basic Axis motion.
"""
import sys
from _imports import RapidCode, helpers, time, config, constants
print("⬤ Axis Basic Motion")
exit_code = 0
# Motion Constants
DISTANCE = 2 # distance to move (in user units)
VELOCITY = 10 # velocity (in user units per second)
ACCELERATION = 5 # acceleration (in user units per second squared)
DECELERATION = 3 # deceleration (in user units per second squared)
JERK_PERCENTAGE = 50 # jerk percentage (0-100%)
# Axis Constants
AXIS_INDEX = 0
def print_status(axis: RapidCode.Axis):
print(f"State: {helpers.enum_to_name(axis.StateGet(), 'RSIState')}, Position: {axis.CommandPositionGet():.5f}, Velocity: {axis.CommandVelocityGet():.5f}, Acceleration: {axis.CommandAccelGet():.5f}")
# get/create the motion controller
creation_params: RapidCode.CreationParameters = helpers.get_creation_parameters()
controller: RapidCode.MotionController = RapidCode.MotionController.Create(creation_params)
try:
helpers.check_errors(controller)
# type hints enable IDE autocomplete for RapidCode objects
print(f"This object is a {type(controller)}")
# Prepare the controller as defined in _config.py depending on the configuration
config.setup_controller(controller, numAxes=AXIS_INDEX + 1)
# get axis
axis: RapidCode.Axis = controller.AxisGet(AXIS_INDEX)
helpers.check_errors(axis)
# ready axis for motion
axis.ClearFaults()
enable_ms = axis.AmpEnableSet(True, 750)
print(f'Amplifier took {enable_ms}ms to enable')
helpers.verify_idle_state(axis)
print_status(axis)
# execute a relative move (distance, velocity, accel, decel, jerk%)
axis.MoveRelative(DISTANCE, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENTAGE)
# monitor motion
while not axis.MotionDoneGet():
print_status(axis)
time.sleep(0.1)
print_status(axis)
# clean up
helpers.verify_idle_state(axis)
exit_code = constants.EXIT_SUCCESS
except Exception as e:
print(f"❌ Error: {e}")
exit_code = constants.EXIT_FAILURE
finally:
controller.Delete()
sys.exit(exit_code)