Home | API Reference | Developer Guide | Code Analysis | Usage Examples —
Draco4 is a high-performance, real-time EtherCAT motor control system designed for complex robotics applications. This guide will help you understand and use the system to build a ROS2 SDK for humanoid robot control.
RobotController (Robot-wide coordination)
├── NetworkController (per EtherCAT interface)
│ ├── MotorController (individual motors)
│ ├── MotorController
│ └── MotorController
└── NetworkController (another interface)
├── MotorController
└── MotorController
Why this architecture?
Critical: The system requires precise timing for stable control.
// Main control loop - MUST run at configured frequency
auto next_cycle = std::chrono::steady_clock::now();
const auto cycle_time = std::chrono::microseconds(4000); // 250Hz = 4ms
while (operational) {
robot->updateAllNetworks(); // EtherCAT communication
// Your control logic here
processROS2Messages();
updateMotorCommands();
publishFeedback();
// Sleep until next cycle
next_cycle += cycle_time;
std::this_thread::sleep_until(next_cycle);
}
OutputPDO (Commands to motor):
struct OutputPDO {
uint16_t controlword; // CIA402 control
uint8_t modes_of_operation; // Control mode
uint16_t target_torque; // Torque command
uint32_t target_position; // Position command
uint32_t target_velocity; // Velocity command
// ... additional fields
};
InputPDO (Feedback from motor):
struct InputPDO {
uint16_t statusword; // CIA402 status
uint32_t position_actual; // Current position
uint32_t velocity_actual; // Current velocity
uint16_t torque_actual; // Current torque
// ... additional fields
};
struct NetworkStatus {
bool initialized; // EtherCAT master ready
bool operational; // Network in OP state
int slave_count; // Number of motors found
int expected_wkc; // Expected working counter
int actual_wkc; // Actual working counter
uint64_t cycle_count; // Total cycles completed
std::string last_error; // Error message
};
// Monitor cycle timing
auto start = std::chrono::high_resolution_clock::now();
robot->updateAllNetworks();
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
if (duration.count() > 3000) { // Warn if > 3ms (75% of 4ms cycle)
std::cout << "Cycle time exceeded: " << duration.count() << "μs" << std::endl;
}
For Development:
Network Setup:
# Configure EtherCAT interface
sudo ip link set eth0 up
sudo ethtool -s eth0 speed 100 duplex full autoneg off
# Check EtherCAT slaves
sudo ethercat slaves
1. “Failed to initialize EtherCAT master”
ip link show eth0
sudo
or add user to netdev
group2. “No slaves detected”
ethercat slaves
to debug3. “Working counter mismatch”
4. Motor not enabling
Enable detailed logging:
// In motor_controller.hpp, change line 16:
#define MOTOR_DEBUG_LOGGING 1
/joint_states
- Current robot state/joint_trajectory
- Motion commands/emergency_stop
- Safety trigger/diagnostics
- System health/enable_motors
- Enable/disable motors/home_robot
- Move to home position/clear_faults
- Reset motor faultsThe Draco4 system provides a robust foundation for your humanoid robot control. Focus on understanding the hierarchical architecture and building your ROS2 layer incrementally on top of the existing real-time motor control capabilities.