Drive Test Examples
Feedback tests example
import logging
import argparse
from ingeniamotion import MotionController
def setup_command():
parser = argparse.ArgumentParser(description="Run feedback test")
parser.add_argument("feedback", help="feedback to test", choices=["HALLS", "QEI", "QEI2"])
parser.add_argument("dictionary_path", help="path to drive dictionary")
parser.add_argument("-ip", default="192.168.2.22", help="drive ip address")
parser.add_argument("--axis", default=1, help="drive axis")
parser.add_argument(
"--debug", action="store_true", help="with this flag test doesn't apply any change"
)
return parser.parse_args()
def main(args):
# Create MotionController instance
mc = MotionController()
# Connect Servo with MotionController instance
mc.communication.connect_servo_eoe(args.ip, args.dictionary_path)
result = None
if args.feedback == "HALLS":
# Run Digital Halls feedback tests
result = mc.tests.digital_halls_test(axis=args.axis, apply_changes=not args.debug)
if args.feedback == "QEI":
# Run Incremental Encoder 1 feedback tests
result = mc.tests.incremental_encoder_1_test(axis=args.axis, apply_changes=not args.debug)
if args.feedback == "QEI2":
# Run Incremental Encoder 2 feedback tests
result = mc.tests.incremental_encoder_2_test(axis=args.axis, apply_changes=not args.debug)
logging.info(result["result_message"])
mc.communication.disconnect()
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
args = setup_command()
main(args)
Commutation example
import logging
import argparse
from ingeniamotion import MotionController
def setup_command():
parser = argparse.ArgumentParser(description="Run commutation test")
parser.add_argument("dictionary_path", help="path to drive dictionary")
parser.add_argument("-ip", default="192.168.2.22", help="drive ip address")
parser.add_argument("--axis", default=1, help="drive axis")
parser.add_argument(
"--debug", action="store_true", help="with this flag test doesn't apply any change"
)
return parser.parse_args()
def main(args):
# Create MotionController instance
mc = MotionController()
# Connect Servo with MotionController instance
mc.communication.connect_servo_eoe(args.ip, args.dictionary_path)
# Run Commutation test
result = mc.tests.commutation(axis=args.axis, apply_changes=not args.debug)
logging.info(result["result_message"])
mc.communication.disconnect()
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
args = setup_command()
main(args)
Commutation with different feedbacks configurations examples
from ingeniamotion import MotionController
from ingeniamotion.enums import SensorType
def set_feedbacks(mc: MotionController):
"""Feedbacks configuration.
All feedbacks can be set either the same encoder or different encoders.
In this example we are using an Incremental Encoder (SensorType.QEI) and
a Digital Halls (SensorType.HALLS).
Args:
mc: Controller to configure the type of encoder for each feedback
"""
mc.configuration.set_auxiliar_feedback(SensorType.HALLS)
mc.configuration.set_commutation_feedback(SensorType.QEI)
mc.configuration.set_position_feedback(SensorType.HALLS)
mc.configuration.set_velocity_feedback(SensorType.QEI)
mc.configuration.set_reference_feedback(SensorType.QEI)
def main() -> None:
mc = MotionController()
interface_ip = "192.168.2.1"
slave_id = 1
dictionary_path = "test_directory/dictionary_file.xdf"
mc.communication.connect_servo_ethercat_interface_ip(interface_ip, slave_id, dictionary_path)
set_feedbacks(mc)
# -------------------------------------------------------------
# Run Commutation test
result = mc.tests.commutation()
print(f"Commutation Result: {result['result_message']} - {result['result_severity']}")
mc.communication.disconnect()
if __name__ == "__main__":
main()