主要内容

开始使用ADC通道的PX4模拟输入块

此示例向您展示了如何使用PX4模拟输入块来读取Pixhawk系列控制器上ADC引脚上应用的电压。

介绍

无人机的工具箱支持包PX金宝app4蒙enables you to create Simulink models that read the voltage applied at the ADC pins on a Pixhawk Series controller.

A single PX4 Analog Input block measures the analog voltage at all the ADC channels on the Pixhawk Series controller, based on the supported FMU version of the hardware. The block outputs the voltages as a 1-by-12 array. Each value in the array corresponds to the analog voltage at a particular channel number.

在此示例中,您将学习如何使用PX4模拟输入块:

  • 观察所有通道的模拟电压

  • Detect which of the ADC channels of the FMU are exposed on the connected PX4 flight controller, and use the voltages from those channels only in the Simulink model.

Prerequisites

Required Hardware

要运行此示例,您将需要以下硬件:

  • Pixhawk系列飞行控制器

  • Micro USB型B电缆

  • 4针电缆或与Pixhawk系列控制器上的ADC引脚兼容的任何电缆

  • Micro-SD card (already used during the初始硬件设置)

任务1-观察ADC通道值

在此任务中,您将配置一个PX4模拟输入块,以输出FMU上存在的所有ADC通道的模拟数据。FMU上可用的所有ADC通道可能不会在Pixhawk系列控制器上公开。

1.From the MATLAB toolstrip, select HOME > New > Simulink Model to open the Simulink Start Page. ClickBlank Modelto launch a new Simulink model.

2.On the Simulink toolbar, select View > Library Browser to open the Simulink Library Browser. Click the UAV Toolbox Support Package for PX4 Autopilots tab (you can also type px4lib in MATLAB command window).

3.Drag and drop aPX4 Analog Inputblock to the model.

4.From the Simulink > Sinks tab in the Library Browser, drag and drop aDisplayblock to the model. Connect the output of the PX4 Analog Input block to the Display block.

5.Connect the Pixhawk Series controller to the host computer using the USB cable.

6.在里面ModelingSimulink工具条金宝app的选项卡,单击Model Settings.

7.在里面Configuration Parameters dialog box, navigate to the硬件实现窗格:

  • Set theHardware boardto the same Pixhawk series controller that you selected during Hardware Setup screens.

  • 在里面Target Hardware Resources部分,输入pixhawk系列控制器连接到的主机计算机的串行端口,固件上传的串行端口field.

  • ClickApplyand then好的.

8.在里面模拟tab, set the simulation Stop time toinf.

9.在里面Hardwaretab, clickMonitor & Tune开始信号监视和参数调整。

Wait for the code generation to be completed. Whenever the dialog box appears instructing you to reconnect the flight controller to the serial port, ensure that you click好的on the dialog box within5 secondsafter reconnecting the flight controller.

Observe the voltage array values in the Display block. It is a 1-by-12 array that shows all the ADC channels based on the FMU version of the PX4 flight controller.

Task 2 - Detect ADC channels that are exposed on Pixhawk Series controller

In this task, you will determine which of the ADC channels that are provided by the FMU version are exposed on the Pixhawk Series controller, and use those index values for further processing of signals.

Ensure that the Monitor and Tune process is still running (as done in Task 1) with the PX4 Analog Input block and the Display block.

1.Use the cable to connect an ADC pin on the Pixhawk Series controller to +3.3V Vcc.

2.观察显示块中任何单元格的值大约更改为 +3.3V。

The index of this cell in the array is the index of ADC channel that is exposed on the flight controller.

3.对于Pixhawk系列控制器中可能保留的所有其他ADC通道,重复步骤1和2。

After you identify the index numbers of all exposed ADC channels, you can stop Monitor and Tune process and remove the Display block connected at the output of the PX4 Analog Input block. You can now proceed with extracting the signal values from the block.

4.从库浏览器中的Si金宝appmulink>信号路由选项卡中,拖放一个Selectorblock to the model.

5.双击块,并设置输入端口大小to12. Set the value forIndexbased on the index values that you identified. For example, you can enter theIndex值为[6 7 8].

6.Connect the input of the Selector block to the output of the PX4 Analog Input block.

7.Connect the output of the Selector block to aDemuxblock. TheNumber of ports在Demux块中,可以将标识的ADC通道总数设置为总数。

The output of the Demux block can be used for further processing of logic.

The complete model will look like the pre-configured model(px4demo_ADC) available for your convenience.

open_system('px4demo_adc');