APIs, concepts, guides, and more
controller-create.py
Note
See Controller: Create 📜 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 creates an RMP Motion Controller object and prints its information.
2"""
3
4import sys
5from _imports import RapidCode, helpers, constants
6
7exit_code = 0
8
9# METHODS
10def print_topology(controller:RapidCode.MotionController):
11 stringBuilder = []
12 overview = "EtherCAT: {} Nodes, Type: {}, State: {}".format(
13 controller.NetworkNodeCountGet(),
14 helpers.enum_to_name(controller.NetworkTypeGet(), "RSINetworkType"),
15 helpers.enum_to_name(controller.NetworkStateGet(), "RSINetworkState")
16 )
17 stringBuilder.append(overview)
18
19 Nodes = []
20 for i in range(controller.NetworkNodeCountGet()):
21 io = controller.IOGet(i)
22 helpers.check_errors(io)
23 if(io.NetworkNode.Exists()):
24 Nodes.append(io.NetworkNode)
25
26 for node in Nodes:
27 stringBuilder.append("") # for spacing
28 stringBuilder.append("Node[{}] - {} ______________________________________________".format(node.NumberGet(), node.NameGet()))
29 stringBuilder.append(" Vendor: {} ".format(node.VendorNameGet() + "Product: {}".format(node.ProductNameGet())))
30 stringBuilder.append(" VendorID: 0x{:08X} ProductCode: 0x{:08X}".format(node.VendorIdGet(), node.ProductCodeGet()))
31 stringBuilder.append(" HardwareRev: 0x{:08X} SerialNumber: {}".format(node.RevisionGet(), node.SerialNumberGet()))
32 stringBuilder.append(" StationAlias: 0x{:08X} AxisCount: {}".format(node.StationAliasGet(), node.AxisCountGet()))
33 stringBuilder.append(" SegmentCount: {}".format(node.SegmentCountGet()))
34 stringBuilder.append(" DI: {} DO: {} AI: {} AO: {}".format(node.DigitalInCountGet(), node.DigitalOutCountGet(), node.AnalogInCountGet(), node.AnalogOutCountGet()))
35
36 stringBuilder.append("") # spacing
37 pdoInputs = controller.NetworkInputCountGet()
38 stringBuilder.append("NetworkInputs count: {} _________________________________".format(pdoInputs))
39 for i in range(pdoInputs):
40 stringBuilder.append(" [{}] - {} Bits: {}".format(i, controller.NetworkInputNameGet(i).ljust(70), controller.NetworkInputBitSizeGet(i)))
41
42 pdoOutputs = controller.NetworkOutputCountGet()
43 stringBuilder.append("NetworkOutputs count: {} _________________________________".format(pdoOutputs))
44 for i in range(pdoOutputs):
45 stringBuilder.append(" [{}] - {} Bits: {}".format(i, controller.NetworkOutputNameGet(i).ljust(70), controller.NetworkOutputBitSizeGet(i)))
46
47 print("\n".join(stringBuilder))
48
49
50# MAIN
51print("⬤ Controller Create")
52
53creation_params: RapidCode.CreationParameters = helpers.get_creation_parameters()
54controller: RapidCode.MotionController = RapidCode.MotionController.Create(creation_params)
55
56try:
57 helpers.check_errors(controller)
58
59 # type hints enable IDE autocomplete for RapidCode objects
60 print(f"This object is a {type(controller)}")
61
62 # print some controller info
63 print(f"RapidCode Version: {controller.VersionGet()}")
64 print(f"Serial Number: {controller.SerialNumberGet()}")
65 print(f"Axis Count: {controller.AxisCountGet()}")
66
67 # print network topology
68 if controller.NetworkStateGet() == RapidCode.RSINetworkState_RSINetworkStateOPERATIONAL:
69 print_topology(controller)
70
71 exit_code = constants.EXIT_SUCCESS
72except Exception as e:
73 print(f"❌ Error: {e}")
74 exit_code = constants.EXIT_FAILURE
75finally:
76 # clean up
77 controller.Delete()
78
79sys.exit(exit_code)