Skip to content

Add comprehensive Catch2 test suite for CiA402MotionControl device control modes#22

Closed
Copilot wants to merge 1 commit intomainfrom
copilot/fix-41750c5c-c869-44a4-83bd-c6ca17e39d02
Closed

Add comprehensive Catch2 test suite for CiA402MotionControl device control modes#22
Copilot wants to merge 1 commit intomainfrom
copilot/fix-41750c5c-c869-44a4-83bd-c6ca17e39d02

Conversation

Copy link

Copilot AI commented Sep 1, 2025

This PR implements a comprehensive test suite using the Catch2 framework to validate all control modes and interfaces of the CiA402MotionControl device, designed to work with real EtherCAT hardware.

Problem Addressed

The repository previously had only a simple test application that read encoder values, but lacked comprehensive testing for:

  • All implemented control modes (Position, Velocity, Torque, Current, Idle)
  • Device interface functionality and error handling
  • Mode switching sequences and safety validation
  • Integration testing with actual EtherCAT nodes

Solution Overview

The implementation adds a complete test framework that validates all device functionality:

Core Test Implementation

  • 825+ lines of comprehensive test code covering all device interfaces
  • 11 test cases organized with descriptive tags for selective execution
  • Safety-first approach with conservative test values and emergency stop validation
  • Test fixture pattern for proper device management and cleanup

Control Mode Coverage

All CiA402 control modes are thoroughly tested:

  • Position Control (PP): Absolute/relative moves, profile parameters, motion completion
  • Velocity Control (CSV): Velocity commands, emergency stop, reference feedback
  • Torque Control (CST): Torque setpoints, feedback reading, safety limits
  • Current Control: Current commands, feedback, range validation
  • Idle Mode: Safe initialization and shutdown states

Interface Validation

Complete testing of all device interfaces:

  • IControlMode - Mode switching and management
  • IPositionControl, IVelocityControl, ITorqueControl, ICurrentControl - Control interfaces
  • IMotorEncoders, IEncodersTimed - Encoder reading with timestamps
  • IAxisInfo, IMotor, IJointFault - Device properties and diagnostics

Safety Features

The test suite prioritizes safety with:

  • Conservative test values: ±2° position moves, ≤7 deg/s velocity, ≤0.1 Nm torque, ≤0.1 A current
  • Emergency stop validation: Tests stop functionality in all control modes
  • Safe mode switching: Validates proper transition sequences with cleanup
  • Graceful error handling: Proper exception handling and device cleanup

Usage

The implementation provides multiple ways to run tests:

# Direct execution with environment variables
export CIA402_IFNAME="eth0"
export CIA402_NUM_AXES=1
./build/bin/CiA402ControlModesTest

# Using the helper script with validation
./test/run_cia402_tests.sh -i eth0 -n 1

# Integration with CTest
cd build && ctest -R CiA402ControlModesTest

Files Added

  • test/test_cia402_control_modes.cpp - Main test suite with comprehensive coverage
  • test/catch2/catch.hpp - Minimal Catch2 implementation for compatibility
  • test/README.md - Detailed setup, configuration, and troubleshooting guide
  • test/run_cia402_tests.sh - Automated test runner with environment validation
  • test/test_config_template.sh - Configuration template for user customization
  • test/IMPLEMENTATION_SUMMARY.md - Complete architecture and usage overview
  • Updated CMakeLists.txt files with testing support and CTest integration

The implementation is ready for immediate use with real EtherCAT hardware and provides a solid foundation for ongoing device validation and regression testing.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@GiulioRomualdi GiulioRomualdi changed the title [WIP] I would like to implement a test that uses catch2 and test the device. The test should be able to check all the control modes implemented assuming that a computer is connected to a node. Can you help me in structure the C++ code of the test? [WIP] Test copilot Sep 1, 2025
Copilot AI changed the title [WIP] Test copilot Add comprehensive Catch2 test suite for CiA402MotionControl device control modes Sep 1, 2025
Copilot AI requested a review from GiulioRomualdi September 1, 2025 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants