apm 3.4.6 四轴混控代码解析
来源:互联网 发布:蓝牙音响 知乎 编辑:程序博客网 时间:2024/04/28 16:00
AP_MotorsMatrix::output_armed_stabilizing:
1、针对每个舵机,计算roll和pitch占用的控制量,并按油门量最大不超过0.5计算yaw最大可使用的控制量
// calculate roll and pitch for each motor
// calculate the amount of yaw input that each motor can accept
for (i=0; i<AP_MOTORS_MAX_NUM_MOTORS; i++) {
if (motor_enabled[i] && (_test_order[i] != 0xff)) {
_thrust_rpyt_out[i] = roll_thrust * _roll_factor[i] + pitch_thrust * _pitch_factor[i];
if (!is_zero(_yaw_factor[i])){
if (yaw_thrust * _yaw_factor[i] > 0.0f) {
unused_range = fabsf((1.0f - (throttle_thrust_best_rpy + _thrust_rpyt_out[i]))/_yaw_factor[i]);
if (yaw_allowed > unused_range) {
yaw_allowed = unused_range;
}
} else {
unused_range = fabsf((throttle_thrust_best_rpy + _thrust_rpyt_out[i])/_yaw_factor[i]);
if (yaw_allowed > unused_range) {
yaw_allowed = unused_range;
}
}
}
}
}
2、针对每个舵机,计算roll、pitch和yaw占用的控制量,并统计rpy_low,rpy_high。 rpy_low <=0:为最小的负控制量;rpy_high>=0:最大的正控制量
// add yaw to intermediate numbers for each motor
rpy_low = 0.0f;
rpy_high = 0.0f;
for (i=0; i<AP_MOTORS_MAX_NUM_MOTORS; i++) {
if (motor_enabled[i] && (_test_order[i] != 0xff)) {
_thrust_rpyt_out[i] = _thrust_rpyt_out[i] + yaw_thrust * _yaw_factor[i];
// record lowest roll+pitch+yaw command
if (_thrust_rpyt_out[i] < rpy_low) {
rpy_low = _thrust_rpyt_out[i];
}
// record highest roll+pitch+yaw command
if (_thrust_rpyt_out[i] > rpy_high) {
rpy_high = _thrust_rpyt_out[i];
}
}
}
3、throttle_thrust_best_rpy为正;
rpy_scale为1.0f的情况下:保持前面计算的rpy控制不变,加上油门控制量,这个油门控制量基本上为throttle_thrust,但要修改满足最后算出的每个舵机的控制量在(0.0,1.0)范围内;
rpy_scale<1.0:这种情况发生在计算出来的油门量 throttle_thrust_best_rpy<(-rpy_low)。假设throttle_thrust_best_rpy=0.5f - (rpy_low+rpy_high)/2.0,此时会导致
(throttle_thrust_best_rpy+rpy_high)>1.0,所以需要将前面计算出来的rpy控制量乘以rpy_scale比例较小,满足每个舵机的控制量在(0.0,1.0)。
// check everything fits
throttle_thrust_best_rpy = MIN(0.5f - (rpy_low+rpy_high)/2.0, _throttle_avg_max);
if (is_zero(rpy_low)){
rpy_scale = 1.0f;
} else {
rpy_scale = constrain_float(-throttle_thrust_best_rpy/rpy_low, 0.0f, 1.0f);
}
// calculate how close the motors can come to the desired throttle
thr_adj = throttle_thrust - throttle_thrust_best_rpy;
if (rpy_scale < 1.0f){
// Full range is being used by roll, pitch, and yaw.
limit.roll_pitch = true;
limit.yaw = true;
if (thr_adj > 0.0f) {
limit.throttle_upper = true;
}
thr_adj = 0.0f;
} else {
if (thr_adj < -(throttle_thrust_best_rpy+rpy_low)){
// Throttle can't be reduced to desired value
thr_adj = -(throttle_thrust_best_rpy+rpy_low);
} else if (thr_adj > 1.0f - (throttle_thrust_best_rpy+rpy_high)){
// Throttle can't be increased to desired value
thr_adj = 1.0f - (throttle_thrust_best_rpy+rpy_high);
limit.throttle_upper = true;
}
}
// add scaled roll, pitch, constrained yaw and throttle for each motor
for (i=0; i<AP_MOTORS_MAX_NUM_MOTORS; i++) {
if (motor_enabled[i] && (_test_order[i] != 0xff)) {
_thrust_rpyt_out[i] = throttle_thrust_best_rpy + thr_adj + rpy_scale*_thrust_rpyt_out[i];
}
}
- apm 3.4.6 四轴混控代码解析
- APM飞控解析
- APM项目实例解析
- APM原生代码编译流程
- APM
- APM
- 每天读一点儿APM(PIX)代码
- 移植APM代码之PID调节
- APM代码中MAVLINK的初步分析。
- 每天读一点儿APM(PIX)代码之外传:apm固件尺寸问题
- 每天读一点儿APM(PIX)代码之一:调度总线AP_Scheduler
- 每天读一点儿APM(PIX)代码之三:飞行控制
- 每天读一点儿APM(PIX)代码之四:minimosd
- Pixhawk源码笔记一:APM代码基本结构
- Pixhawk源码笔记一:APM代码基本结构
- 每天读一点儿APM(PIX)代码之四:minimosd
- Android APM方案(一)完成代码注入
- apm飞控代码学习日记(一)
- a++与++a的区别!!!!!!
- 万能密码大全
- 使用极光即时通讯发送、接收好友请求
- 线性布局与相对布局的混合使用
- Math和Random
- apm 3.4.6 四轴混控代码解析
- MyEclipse安装hadoop-eclipse-plugin,配置本地hadoop开发环境
- 为什么sqlplus访问oracle不需要用到监听器
- Linux 通配符
- 电话本
- 括号匹配
- H5新表单
- linux利用pxe实现自动装机
- kernel 启动流程之 【设备驱动加载】 学习笔记_好