PX4的mix文件是怎么被使用的呢?

启动

怎么到启动这里的就不说了
在这里插入图片描述

2 作为MIXER_FILE被mixer load的

src/systemcmds/mixer/mixer.cpp实现mixer load
Mixer load调用函数:
load(const char *devname, const char *fname, bool append)

3 将mix文件传给设备

然后调用
int load_mixer_file(const char *fname, char *buf, unsigned maxlen),将文件加载到buff

然后调用
int ret = px4_ioctl(dev, MIXERIOCLOADBUF, (unsigned long)buf);
将buf传给设备,给io或者fmu都行,io的话是经src/drivers/px4io/到了src/modules/px4iofirmware/,fmu的话到了src/drivers/pwm_out/

例如fmu

在设备fmu pwm中
src/drivers/pwm_out/PWMOut.cpp调用:
ret = _mixing_output.loadMixerThreadSafe(buf, buflen);
在这里插入图片描述
load函数中,将loadmixer存储为command
然后等待_command去执行,执行完成后自动将command清除为none
下面是执行load指令的过程代码

到了
int MixingOutput::loadMixer(const char *buf, unsigned len)

4 从buf里解析mixer

传递的cb_handle就是本类MixerGroup指针this
->
MixerGroup::load_from_buf(Mixer::ControlCallback control_cb, uintptr_t cb_handle, const char *buf, unsigned &buflen)

以多旋翼为例

MultirotorMixer::from_text(Mixer::ControlCallback control_cb, uintptr_t cb_handle, const char *buf, unsigned &buflen)
->
return new MultirotorMixer(control_cb, cb_handle, geometry);
->
MultirotorMixer(control_cb, cb_handle, _config_index[(int)geometry], _config_rotor_count[(int)geometry])

这样,就建立了一个多旋翼的mixer

5 混控输出

而一个mix文件中可以有多个mixer,例如多个简单mixer加一个多旋翼mixer

# ROMFS/px4fmu_common/mixers/babyshark.main.mix
Aileron mixer (roll)
---------------------------------
M: 1
S: 1 0  -10000  -10000      0 -10000  10000


A-tail mixer right
------------------
M: 2
S: 1 2  -7000  -7000      0 -10000  10000
S: 1 1   8000   8000      0 -10000  10000


Motor speed mixer
-----------------
This mixer generates a full-range output (-1 to 1) from an input in the (0 - 1)
range.  Inputs below zero are treated as zero.

M: 1
S: 1 3      0  20000 -10000 -10000  10000


A-tail mixer left
-----------------
M: 2
S: 1 2  -7000  -7000      0 -10000  10000
S: 1 1  -8000  -8000      0 -10000  10000


Quad motors 1 - 4
-----------------
R: 4x

这些mixer都被放在一个List里

// src/lib/mixer/MixerGroup.hpp
private:
	List<Mixer *>			_mixers;	/**< linked list of mixers */

最终逐个混控:

unsigned
MixerGroup::mix(float *outputs, unsigned space)
{
	unsigned index = 0;

	for (auto mixer : _mixers) {
		index += mixer->mix(outputs + index, space - index);

		if (index >= space) {
			break;
		}
	}

	return index;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值