关于px4 1.15.0电机控制有效矩阵的更新

下面这段代码是PX4飞控根据_handled_motor_failure_bitmask的值, 更新无人机的有效性矩阵的代码。

bash 复制代码
// Handle failed actuators
		if (_handled_motor_failure_bitmask) {
			actuator_idx = 0;
			memset(&actuator_idx_matrix, 0, sizeof(actuator_idx_matrix));

			for (int motors_idx = 0; motors_idx < _num_actuators[0] && motors_idx < actuator_motors_s::NUM_CONTROLS; motors_idx++) {
				int selected_matrix = _control_allocation_selection_indexes[actuator_idx];

				if (_handled_motor_failure_bitmask & (1 << motors_idx)) {
					ActuatorEffectiveness::EffectivenessMatrix &matrix = config.effectiveness_matrices[selected_matrix];

					for (int i = 0; i < NUM_AXES; i++) {
						matrix(i, actuator_idx_matrix[selected_matrix]) = 0.0f;
					}
				}

				++actuator_idx_matrix[selected_matrix];
				++actuator_idx;
			}
		}

假设我们停的是5号电机。 那么_handled_motor_failure_bitmask = 0x10

那么如果六旋翼的原始矩阵是

bash 复制代码
Row 0: [-6.500  6.500  3.250 -3.250 -3.250  3.250 ]
Row 1: [ 0.000  0.000  5.629 -5.629  5.629 -5.629 ]
Row 2: [-0.325  0.325 -0.325  0.325  0.325 -0.325 ]
Row 3: [ 0.000  0.000  0.000  0.000  0.000  0.000 ]
Row 4: [ 0.000  0.000  0.000  0.000  0.000  0.000 ]
Row 5: [-6.500 -6.500 -6.500 -6.500 -6.500 -6.500 ]

那么经过上面的一段代码之后

最新的矩阵就是这个

bash 复制代码
Row 0: [-6.500  6.500  3.250 -3.250  0.000  3.250 ]
Row 1: [ 0.000  0.000  5.629 -5.629  0.000 -5.629 ]
Row 2: [-0.325  0.325 -0.325  0.325  0.000 -0.325 ]
Row 3: [ 0.000  0.000  0.000  0.000  0.000  0.000 ]
Row 4: [ 0.000  0.000  0.000  0.000  0.000  0.000 ]
Row 5: [-6.500 -6.500 -6.500 -6.500  0.000 -6.500 ]

过程是这样的

bash 复制代码
电机失效处理逻辑:  
1. 电机编号对应: 
 • motors_idx = 0 → 第1列 (电机0) 
  • motors_idx = 1 → 第2列 (电机1) 
 • motors_idx = 2 → 第3列 (电机2) 
  • motors_idx = 3 → 第4列 (电机3)  
• motors_idx = 4 → 第5列 (电机4) ← 失效 
 • motors_idx = 5 → 第6列 (电机5)  
 2. 失效处理:  
 3. • 当 motors_idx = 4 时,_handled_motor_failure_bitmask & (1 <<4) = 0x10 & 0x10 = 0x10 (非零,条件成立)

有效矩阵怎么在飞控代码中打印出来呢?

bash 复制代码
--- a/src/modules/control_allocator/ActuatorEffectiveness/ActuatorEffectivenessRotors.cpp
+++ b/src/modules/control_allocator/ActuatorEffectiveness/ActuatorEffectivenessRotors.cpp
@@ -221,6 +221,22 @@ ActuatorEffectivenessRotors::computeEffectivenessMatrix(const Geometry &geometry
                }
        }
 
+
+
+       // 打印根据机体结构计算的初始有效矩阵
+       PX4_INFO("=== Initial Effectiveness Matrix (from Geometry) ===");
+       PX4_INFO("Actuator start index: %d, Num actuators: %d", actuator_start_index, num_actuators);
+       for (int row = 0; row < 6; row++) {
+               char row_str[200] = "";
+               for (int col = 0; col < num_actuators; col++) {
+                       char temp[20];
+                       snprintf(temp, sizeof(temp), "%.3f ", (double)effectiveness(row, col + actuator_start_index));
+                       strcat(row_str, temp);
+               }
+               PX4_INFO("Row %d: [%s]", row, row_str);
+       }
+
+
        return num_actuators;
 }
 

更新后的矩阵,应该在下面的函数中,打印的, 但是打印代码始终不对,后面再添加。

bash 复制代码
diff --git a/src/modules/control_allocator/ControlAllocator.cpp b/src/modules/control_allocator/ControlAllocator.cpp
index 6ac6f318..1c9a5739 100644
--- a/src/modules/control_allocator/ControlAllocator.cpp
+++ b/src/modules/control_allocator/ControlAllocator.cpp
@@ -539,6 +539,8 @@ ControlAllocator::update_effectiveness_matrix_if_needed(EffectivenessUpdateReaso
                        }
                }
 
+               printf("cuigaosheng  _handled_motor_failure_bitmask: 0x%x", _handled_motor_failure_bitmask);
+
                // Handle failed actuators
                if (_handled_motor_failure_bitmask) {
                        actuator_idx = 0;
@@ -594,6 +596,7 @@ ControlAllocator::update_effectiveness_matrix_if_needed(EffectivenessUpdateReaso
                trims.timestamp = hrt_absolute_time();
                _actuator_servos_trim_pub.publish(trims);
        }
相关推荐
西西弗Sisyphus1 小时前
线性代数 - 线性方程组的原始解法(高斯消元法)
线性代数·矩阵·线程方程组
程序员大雄学编程1 小时前
用Python来学微积分30-微分方程初步
开发语言·python·线性代数·数学·微积分
kyle~4 小时前
数学基础---刚体变换(旋转矩阵与平移矩阵)
线性代数·矩阵·机器人·旋转矩阵·平移矩阵
feiyangqingyun4 小时前
Qt实时绘制飞行轨迹/移动轨迹实时显示/带旋转角度/平滑移动/效果一级棒/地面站软件开发/无人机管理平台
qt·无人机·集群地面站
EriccoShaanxi8 小时前
加速度计如何助力大型无人机飞得更稳、更准、更智能?
无人机
云卓SKYDROID9 小时前
无人机电气隔离与抗干扰技术概述
无人机·智慧安防·高科技·云卓科技·四光吊舱
云望无线图传模块9 小时前
无人机远距离无线通信模块:突破空中通信的未来之钥
无人机·无线模块·无人机模块·远距离模块
A_SKYLINE9 小时前
低空无人机“一网统飞”深度解构:从技术内核到产业落地,重构低空经济操作系统
人工智能·重构·无人机·产品经理·低空经济
Olafur_zbj11 小时前
【IC】NoC设计入门 --交换矩阵
线性代数·矩阵
xier_ran1 天前
Transformer:Decoder 中,Cross-Attention 所用的 K(Key)和 V(Value)矩阵,是如何从 Encoder 得到的
深度学习·矩阵·transformer