Odrive 电机控制代码 update 函数解析
update 函数概述
update 函数是 Odrive 电机控制代码中的核心函数之一,负责在每个控制循环中更新电机的状态和控制参数。该函数根据当前配置和输入信号计算并输出电机所需的转矩,同时处理错误和特殊情况。
函数逻辑解析
1. 获取估计值
std::optional<float> pos_estimate_linear = pos_estimate_linear_src_.present();
std::optional<float> pos_estimate_circular = pos_estimate_circular_src_.present();
std::optional<float> pos_wrap = pos_wrap_src_.present();
std::optional<float> vel_estimate = vel_estimate_src_.present();
std::optional<float> anticogging_pos_estimate = axis_->encoder_.pos_estimate_.present();
std::optional<float> anticogging_vel_estimate = axis_->encoder_.vel_estimate_.present();
- 获取位置、速度和反齿槽位置估计值。
- 处理线性、圆形位置估计和位置环绕值。
2. 处理步进方向激活情况
if (axis_->step_dir_active_) {
// 处理步进方向激活情况
}
3. 反齿槽校准
if (config_.anticogging.calib_anticogging) {
// 进行反齿槽校准
}
- 如果启用了反齿槽校准,则根据当前位置和速度进行校准。
|