This document explains the implementation of a stepper motor controller used in robotics applications. The system provides comprehensive control over stepper motors with built-in safety features and precise movement control.
1. Motor Configuration
The motor controller is initialized with specific parameters for each motor:
CtrlStepMotor::CtrlStepMotor(CAN_HandleTypeDef* _hcan, uint8_t _id, bool _inverse,
uint8_t _reduction, float _angleLimitMin, float _angleLimitMax)
Each motor has:
- A unique ID for communication
- Direction settings (normal or inverse)
- Gear reduction ratio
- Angle limits for safety
2. Communication Protocol
The system uses CAN bus communication with a specific message format:
txHeader = {
.StdId = 0,
.IDE = CAN_ID_STD,
.RTR = CAN_RTR_DATA,
.DLC = 8,
}
This protocol enables:
- Unique message identification
- Standard data format
- Real-time communication
- Status feedback
3. Basic Control Functions
Core Control Methods
void CtrlStepMotor::SetEnable(bool _enable)
void CtrlStepMotor::SetCurrentSetPoint(float _val)
void CtrlStepMotor::SetVelocitySetPoint(float _val)
void CtrlStepMotor::SetPositionSetPoint(float _val)
These functions provide fundamental control:
- Enable/disable motor operation
- Current control for torque adjustment
- Velocity control
- Position control
4. Advanced Movement Control
Sophisticated Motion Control
void CtrlStepMotor::SetPositionWithVelocityLimit(float _pos, float _vel)
void CtrlStepMotor::SetAcceleration(float _val)
These methods enable:
- Position control with speed limits
- Acceleration/deceleration control
- Smooth movement profiles
5. Safety Features
Protection Systems
void CtrlStepMotor::SetCurrentLimit(float _val)
void CtrlStepMotor::SetEnableStallProtect(bool _enable)
void CtrlStepMotor::GetTemp()
Safety mechanisms include:
- Current limiting for overheating prevention
- Stall protection
- Temperature monitoring
- Automatic shutdown on fault conditions
6. Motor Tuning (PID Control)
PID Parameters
void CtrlStepMotor::SetDceKp(int32_t _val)
void CtrlStepMotor::SetDceKi(int32_t _val)
void CtrlStepMotor::SetDceKd(int32_t _val)
PID control enables:
- Precise position control
- Error elimination
- Oscillation reduction
- Optimal response characteristics
7. Configuration Management
System Configuration
void CtrlStepMotor::ApplyPositionAsHome()
void CtrlStepMotor::SetEnableOnBoot(bool _enable)
void CtrlStepMotor::EraseConfigs()
Configuration features:
- Home position setting
- Boot behavior configuration
- Factory reset capabilities
- Persistent settings storage
8. Angle Calculations
Position Control
void CtrlStepMotor::SetAngle(float _angle)
{
_angle = inverseDirection ? -_angle : _angle;
float stepMotorCnt = _angle / 360.0f * (float) reduction;
SetPositionSetPoint(stepMotorCnt);
}
This system handles:
- Angle to step conversion
- Direction compensation
- Gear ratio calculations
- Precise positioning
Key Features Summary
-
Real-time Control
- CAN bus communication
- Immediate response
- Status feedback
-
Safety Systems
- Current limitation
- Temperature monitoring
- Stall protection
- Emergency stop capability
-
Movement Control
- Precise positioning
- Velocity control
- Acceleration management
- Smooth motion profiles
-
Configuration Options
- Persistent settings
- Boot behavior
- Home position
- System calibration
-
Protection Mechanisms
- Overheating prevention
- Stall detection
- Current limiting
- Position limits
System Benefits
The implementation ensures:
- Precise movement control through PID tuning
- Safe operation with multiple protection layers
- Flexible configuration for different applications
- Reliable communication through CAN bus
- Comprehensive status monitoring
- Easy integration with larger systems