APIs, concepts, guides, and more
axis-motion.py
Note
See Axis: Basic Motion 📜 for a detailed explanation of this sample code.
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.
1""" Sample application that demonstrates basic Axis motion.
2"""
3
4import sys
5from _imports import RapidCode, helpers, time, config, constants
6
7print("⬤ Axis Basic Motion")
8
9exit_code = 0
10
11# Motion Constants
12DISTANCE = 2 # distance to move (in user units)
13VELOCITY = 10 # velocity (in user units per second)
14ACCELERATION = 5 # acceleration (in user units per second squared)
15DECELERATION = 3 # deceleration (in user units per second squared)
16JERK_PERCENTAGE = 50 # jerk percentage (0-100%)
17
18# Axis Constants
19AXIS_INDEX = 0
20
21def print_status(axis: RapidCode.Axis):
22 print(f"State: {helpers.enum_to_name(axis.StateGet(), 'RSIState')}, Position: {axis.CommandPositionGet():.5f}, Velocity: {axis.CommandVelocityGet():.5f}, Acceleration: {axis.CommandAccelGet():.5f}")
23
24# get/create the motion controller
25creation_params: RapidCode.CreationParameters = helpers.get_creation_parameters()
26controller: RapidCode.MotionController = RapidCode.MotionController.Create(creation_params)
27
28try:
29 helpers.check_errors(controller)
30
31 # type hints enable IDE autocomplete for RapidCode objects
32 print(f"This object is a {type(controller)}")
33
34 # Prepare the controller as defined in _config.py depending on the configuration
35 config.setup_controller(controller, numAxes=AXIS_INDEX + 1)
36
37 # get axis
38 axis: RapidCode.Axis = controller.AxisGet(AXIS_INDEX)
39 helpers.check_errors(axis)
40
41 # ready axis for motion
42 axis.ClearFaults()
43 enable_ms = axis.AmpEnableSet(True, 750)
44 print(f'Amplifier took {enable_ms}ms to enable')
45 helpers.verify_idle_state(axis)
46
47 print_status(axis)
48
49 # execute a relative move (distance, velocity, accel, decel, jerk%)
50 axis.MoveRelative(DISTANCE, VELOCITY, ACCELERATION, DECELERATION, JERK_PERCENTAGE)
51
52 # monitor motion
53 while not axis.MotionDoneGet():
54 print_status(axis)
55 time.sleep(0.1)
56
57 print_status(axis)
58
59 # clean up
60 helpers.verify_idle_state(axis)
61
62 exit_code = constants.EXIT_SUCCESS
63except Exception as e:
64 print(f"❌ Error: {e}")
65 exit_code = constants.EXIT_FAILURE
66finally:
67 controller.Delete()
68
69sys.exit(exit_code)