设备驱动
NuttX device drivers are based on the Device framework.
创建驱动程序
PX4 几乎只消耗来自 uORB 的数据。 常见外设类型的驱动程序必须发布正确的 uORB 消息(例如: 陀螺仪、加速度计、压力传感器等)。
PX4 almost exclusively consumes data from uORB. Drivers for common peripheral types must publish the correct uORB messages (for example: gyro, accelerometer, pressure sensors, etc.).
PX4 is a reactive system and uses uORB publish/subscribe to transport messages. File handles are not required or used for the core operation of the system. Two main APIs are used: 文件句柄不是必需或用于系统的核心操作。
PX4 使用设备 ID 在整个系统中一致地识别单个传感器。 PX4 uses device IDs to identify individual sensors consistently across the system. These IDs are stored in the configuration parameters and used to match sensor calibration values, as well as to determine which sensor is logged to which logfile entry.
核心架构
PX4 is a reactive system and uses uORB publish/subscribe to transport messages. File handles are not required or used for the core operation of the system. Two main APIs are used:
Publish / subscribe 系统具有文件、网络或共享内存后端,具体取决于系统 PX4 运行。
The global device registry, which can be used to enumerate devices and get/set their configuration. This can be as simple as a linked list or map to the file system. 这可以像链接列表或映射到文件系统一样简单。
设备ID
For the example of three magnetometers on a system, use the flight log (.px4log) to dump the parameters. The three parameters encode the sensor IDs and MAG_PRIME
identifies which magnetometer is selected as the primary sensor. Each MAGx_ID is a 24bit number and should be padded left with zeros for manual decoding. 这三个参数解码传感器的 ID, 并且 MAG_PRIME
区分那个磁力计作为主传感器。
这是通过 I2C 总线1 的外部 HMC5983 连接在地址 0x1E
:会在日志文件中以 IMU.MagX
格式显示出来。
解码示例
This is the internal HMC5983 connected via SPI, bus 1, slave select slot 5. It will show up in the log file as IMU1.MagX
. 它将以 IMU1.MagX
显示在日志文件中。 Each MAGx_ID is a 24bit number and should be padded left with zeros for manual decoding.
This is the external HMC5983 connected via I2C, bus 1 at address 0x1E
: It will show up in the log file as IMU.MagX
.
根据此格式,设备 ID 是一个24bit 数字。 The device ID is a 24bit number according to this format. Note that the first fields are the least significant bits in the decoding example above.
And this is the internal MPU9250 magnetometer connected via SPI, bus 1, slave select slot 4. It will show up in the log file as IMU2.MagX
.
设备 ID 编码
The device ID is a 24bit number according to this format. Note that the first fields are the least significant bits in the decoding example above.
The bus_type
is decoded according to:
and devtype
is decoded according to:
调试
For general debugging topics see: Debugging/Logging.
使用操纵杆
Drivers (and other modules) output minimally verbose logs strings by default (e.g. for PX4_DEBUG
, PX4_WARN
, PX4_ERR
, etc.).
Log verbosity is defined at build time using the RELEASE_BUILD
(default), DEBUG_BUILD
(verbose) or TRACE_BUILD
(extremely verbose) macros.
Change the logging level using COMPILE_FLAGS
in the driver px4_add_module
function (CMakeLists.txt). The code fragment below shows the required change to enable DEBUG_BUILD level debugging for a single module or driver.
Verbose logging can also be enabled on a per-file basis, by adding #define DEBUG_BUILD
at the very top of a .cpp file (before any includes).
Last updated