APIs, concepts, guides, and more
Controller: Create

Create a controller in 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:


📜 Controller Create

Learn how to create a controller in Python.

""" Sample application that creates an RMP Motion Controller object and prints its information.
"""
from _imports import RapidCode, helpers
# METHODS
def print_topology(controller:RapidCode.MotionController):
stringBuilder = []
overview = "EtherCAT: {} Nodes, {} {}".format(controller.NetworkNodeCountGet(), controller.NetworkTypeGet(), controller.NetworkStateGet())
stringBuilder.append(overview)
Nodes = []
for i in range(controller.NetworkNodeCountGet()):
io = controller.IOGet(i)
helpers.check_errors(io)
if(io.NetworkNode.Exists()):
Nodes.append(io.NetworkNode)
for node in Nodes:
stringBuilder.append("") # for spacing
stringBuilder.append("Node[{}] - {} ______________________________________________".format(node.NumberGet(), node.NameGet()))
stringBuilder.append(" Vendor: {} ".format(node.VendorNameGet() + "Product: {}".format(node.ProductNameGet())))
stringBuilder.append(" VendorID: 0x{:08X} ProductCode: 0x{:08X}".format(node.VendorIdGet(), node.ProductCodeGet()))
stringBuilder.append(" HardwareRev: 0x{:08X} SerialNumber: {}".format(node.RevisionGet(), node.SerialNumberGet()))
stringBuilder.append(" StationAlias: 0x{:08X} AxisCount: {}".format(node.StationAliasGet(), node.AxisCountGet()))
stringBuilder.append(" SegmentCount: {}".format(node.SegmentCountGet()))
stringBuilder.append(" DI: {} DO: {} AI: {} AO: {}".format(node.DigitalInCountGet(), node.DigitalOutCountGet(), node.AnalogInCountGet(), node.AnalogOutCountGet()))
stringBuilder.append("") # spacing
pdoInputs = controller.NetworkInputCountGet()
stringBuilder.append("NetworkInputs count: {} _________________________________".format(pdoInputs))
for i in range(pdoInputs):
stringBuilder.append(" [{}] - {} Bits: {}".format(i, controller.NetworkInputNameGet(i).ljust(70), controller.NetworkInputBitSizeGet(i)))
pdoOutputs = controller.NetworkOutputCountGet()
stringBuilder.append("NetworkOutputs count: {} _________________________________".format(pdoOutputs))
for i in range(pdoOutputs):
stringBuilder.append(" [{}] - {} Bits: {}".format(i, controller.NetworkOutputNameGet(i).ljust(70), controller.NetworkOutputBitSizeGet(i)))
print("\n".join(stringBuilder))
# MAIN
print("⬤ Controller Create")
creation_params: RapidCode.CreationParameters = helpers.get_creation_parameters()
controller: RapidCode.MotionController = RapidCode.MotionController.Create(creation_params)
helpers.check_errors(controller)
# type hints enable IDE autocomplete for RapidCode objects
print(f"This object is a {type(controller)}")
# print some controller info
print(f"RapidCode Version: {controller.VersionGet()}")
print(f"Serial Number: {controller.SerialNumberGet()}")
print(f"Axis Count: {controller.AxisCountGet()}")
# print network topology
if controller.NetworkStateGet() == RapidCode.RSINetworkState_RSINetworkStateOPERATIONAL:
print_topology(controller)
# clean up
controller.Delete()