!REDIRECT “https://docs.px4.io/master/zh/middleware/modules_driver.html

模块参考:驱动

子分类

adc

Source: drivers/adc/board_adc

描述

ADC driver.

Usage

  1. adc <command> [arguments...]
  2. Commands:
  3. start
  4. test
  5. stop
  6. status print status info

ads1115

Source: drivers/adc/ads1115

Usage

  1. ads1115 <command> [arguments...]
  2. Commands:
  3. start
  4. [-I] Internal I2C bus(es)
  5. [-X] External I2C bus(es)
  6. [-b <val>] board-specific bus (default=all) (external SPI: n-th bus
  7. (default=1))
  8. [-f <val>] bus frequency in kHz
  9. [-q] quiet startup (no message if no device found)
  10. [-a <val>] I2C address
  11. default: 72
  12. stop
  13. status print status info

atxxxx

Source: drivers/osd/atxxxx

Description

OSD driver for the ATXXXX chip that is mounted on the OmnibusF4SD board for example.

It can be enabled with the OSD_ATXXXX_CFG parameter.

Usage

  1. atxxxx <command> [arguments...]
  2. Commands:
  3. start
  4. [-s] Internal SPI bus(es)
  5. [-S] External SPI bus(es)
  6. [-b <val>] board-specific bus (default=all) (external SPI: n-th bus
  7. (default=1))
  8. [-c <val>] chip-select index (for external SPI)
  9. default: 1
  10. [-m <val>] SPI mode
  11. [-f <val>] bus frequency in kHz
  12. [-q] quiet startup (no message if no device found)
  13. stop
  14. status print status info

batt_smbus

Source: drivers/batt_smbus

Description

Smart battery driver for the BQ40Z50 fuel gauge IC.

Examples

To write to flash to set parameters. address, number_of_bytes, byte0, … , byteN

  1. batt_smbus -X write_flash 19069 2 27 0

Usage

  1. batt_smbus <command> [arguments...]
  2. Commands:
  3. start
  4. [-I] Internal I2C bus(es)
  5. [-X] External I2C bus(es)
  6. [-b <val>] board-specific bus (default=all) (external SPI: n-th bus
  7. (default=1))
  8. [-f <val>] bus frequency in kHz
  9. [-q] quiet startup (no message if no device found)
  10. [-a <val>] I2C address
  11. default: 11
  12. man_info Prints manufacturer info.
  13. unseal Unseals the devices flash memory to enable write_flash
  14. commands.
  15. seal Seals the devices flash memory to disbale write_flash commands.
  16. suspend Suspends the driver from rescheduling the cycle.
  17. resume Resumes the driver from suspension.
  18. write_flash Writes to flash. The device must first be unsealed with the
  19. unseal command.
  20. [address] The address to start writing.
  21. [number of bytes] Number of bytes to send.
  22. [data[0]...data[n]] One byte of data at a time separated by spaces.
  23. stop
  24. status print status info

blinkm

Source: drivers/lights/blinkm

Usage

  1. blinkm <command> [arguments...]
  2. Commands:
  3. start
  4. [-I] Internal I2C bus(es)
  5. [-X] External I2C bus(es)
  6. [-b <val>] board-specific bus (default=all) (external SPI: n-th bus
  7. (default=1))
  8. [-f <val>] bus frequency in kHz
  9. [-q] quiet startup (no message if no device found)
  10. [-a <val>] I2C address
  11. default: 9
  12. systemstate
  13. ledoff
  14. list
  15. script
  16. -n <val> Script file name
  17. values: <file>
  18. stop
  19. status print status info

bst

Source: drivers/telemetry/bst

Usage

  1. bst <command> [arguments...]
  2. Commands:
  3. start
  4. [-I] Internal I2C bus(es)
  5. [-X] External I2C bus(es)
  6. [-b <val>] board-specific bus (default=all) (external SPI: n-th bus
  7. (default=1))
  8. [-f <val>] bus frequency in kHz
  9. [-q] quiet startup (no message if no device found)
  10. [-a <val>] I2C address
  11. default: 118
  12. stop
  13. status print status info

dshot

Source: drivers/dshot

Description

This is the DShot output driver. It is similar to the fmu driver, and can be used as drop-in replacement to use DShot as ESC communication protocol instead of PWM.

It supports:

  • DShot150, DShot300, DShot600, DShot1200
  • 通过独立的串口遥控,并且发布esc_status消息
  • 通过命令行接口发送 DShot 命令

Examples

Permanently reverse motor 1:

  1. dshot reverse -m 1
  2. dshot save -m 1

After saving, the reversed direction will be regarded as the normal one. So to reverse again repeat the same commands.

Usage

  1. dshot <command> [arguments...]
  2. Commands:
  3. start Start the task (without any mode set, use any of the mode_*
  4. cmds)
  5. All of the mode_* commands will start the module if not running already
  6. mode_gpio
  7. mode_pwm Select all available pins as PWM
  8. mode_pwm8
  9. mode_pwm6
  10. mode_pwm5
  11. mode_pwm5cap1
  12. mode_pwm4
  13. mode_pwm4cap1
  14. mode_pwm4cap2
  15. mode_pwm3
  16. mode_pwm3cap1
  17. mode_pwm2
  18. mode_pwm2cap2
  19. mode_pwm1
  20. telemetry Enable Telemetry on a UART
  21. <device> UART device
  22. reverse Reverse motor direction
  23. [-m <val>] Motor index (1-based, default=all)
  24. normal Normal motor direction
  25. [-m <val>] Motor index (1-based, default=all)
  26. save Save current settings
  27. [-m <val>] Motor index (1-based, default=all)
  28. 3d_on Enable 3D mode
  29. [-m <val>] Motor index (1-based, default=all)
  30. 3d_off Disable 3D mode
  31. [-m <val>] Motor index (1-based, default=all)
  32. beep1 Send Beep pattern 1
  33. [-m <val>] Motor index (1-based, default=all)
  34. beep2 Send Beep pattern 2
  35. [-m <val>] Motor index (1-based, default=all)
  36. beep3 Send Beep pattern 3
  37. [-m <val>] Motor index (1-based, default=all)
  38. beep4 Send Beep pattern 4
  39. [-m <val>] Motor index (1-based, default=all)
  40. beep5 Send Beep pattern 5
  41. [-m <val>] Motor index (1-based, default=all)
  42. esc_info Request ESC information
  43. -m <val> Motor index (1-based)
  44. stop
  45. status print status info

fake_gyro

Source: examples/fake_gyro

Description

Usage

  1. fake_gyro <command> [arguments...]
  2. Commands:
  3. start
  4. stop
  5. status print status info

fake_magnetometer

Source: examples/fake_magnetometer

Description

Publish the earth magnetic field as a fake magnetometer (sensor_mag). Requires vehicle_attitude and vehicle_gps_position.

Usage

  1. fake_magnetometer <command> [arguments...]
  2. Commands:
  3. start
  4. stop
  5. status print status info

gps

Source: drivers/gps

Description

GPS driver module that handles the communication with the device and publishes the position via uORB. It supports multiple protocols (device vendors) and by default automatically selects the correct one.

The module supports a secondary GPS device, specified via -e parameter. The position will be published on the second uORB topic instance, but it’s currently not used by the rest of the system (however the data will be logged, so that it can be used for comparisons).

Implementation

There is a thread for each device polling for data. The GPS protocol classes are implemented with callbacks so that they can be used in other projects as well (eg. QGroundControl uses them too).

Examples

For testing it can be useful to fake a GPS signal (it will signal the system that it has a valid position):

  1. gps stop
  2. gps start -f

Starting 2 GPS devices (the main GPS on /dev/ttyS3 and the secondary on /dev/ttyS4):

  1. gps start -d /dev/ttyS3 -e /dev/ttyS4

Initiate warm restart of GPS device

  1. gps reset warm

Usage

  1. gps <command> [arguments...]
  2. Commands:
  3. start
  4. [-d <val>] GPS device
  5. values: <file:dev>, default: /dev/ttyS3
  6. [-b <val>] Baudrate (can also be p:<param_name>)
  7. default: 0
  8. [-e <val>] Optional secondary GPS device
  9. values: <file:dev>
  10. [-g <val>] Baudrate (secondary GPS, can also be p:<param_name>)
  11. default: 0
  12. [-f] Fake a GPS signal (useful for testing)
  13. [-s] Enable publication of satellite info
  14. [-i <val>] GPS interface
  15. values: spi|uart, default: uart
  16. [-j <val>] secondary GPS interface
  17. values: spi|uart, default: uart
  18. [-p <val>] GPS Protocol (default=auto select)
  19. values: ubx|mtk|ash|eml
  20. stop
  21. status print status info
  22. reset Reset GPS device
  23. cold|warm|hot Specify reset type

ina226

Source: drivers/power_monitor/ina226

Description

Driver for the INA226 power monitor.

Multiple instances of this driver can run simultaneously, if each instance has a separate bus OR I2C address.

For example, one instance can run on Bus 2, address 0x41, and one can run on Bus 2, address 0x43.

If the INA226 module is not powered, then by default, initialization of the driver will fail. To change this, use the -f flag. If this flag is set, then if initialization fails, the driver will keep trying to initialize again every 0.5 seconds. With this flag set, you can plug in a battery after the driver starts, and it will work. Without this flag set, the battery must be plugged in before starting the driver.

Usage

  1. ina226 <command> [arguments...]
  2. Commands:
  3. start
  4. [-I] Internal I2C bus(es)
  5. [-X] External I2C bus(es)
  6. [-b <val>] board-specific bus (default=all) (external SPI: n-th bus
  7. (default=1))
  8. [-f <val>] bus frequency in kHz
  9. [-q] quiet startup (no message if no device found)
  10. [-a <val>] I2C address
  11. default: 65
  12. [-k] if initialization (probing) fails, keep retrying periodically
  13. [-t <val>] battery index for calibration values (1 or 2)
  14. default: 1
  15. stop
  16. status print status info

irlock

Source: drivers/irlock

Usage

  1. irlock <command> [arguments...]
  2. Commands:
  3. start
  4. [-I] Internal I2C bus(es)
  5. [-X] External I2C bus(es)
  6. [-b <val>] board-specific bus (default=all) (external SPI: n-th bus
  7. (default=1))
  8. [-f <val>] bus frequency in kHz
  9. [-q] quiet startup (no message if no device found)
  10. [-a <val>] I2C address
  11. default: 84
  12. stop
  13. status print status info

lsm303agr

Source: drivers/magnetometer/lsm303agr

Usage

  1. lsm303agr <command> [arguments...]
  2. Commands:
  3. start
  4. [-s] Internal SPI bus(es)
  5. [-S] External SPI bus(es)
  6. [-b <val>] board-specific bus (default=all) (external SPI: n-th bus
  7. (default=1))
  8. [-c <val>] chip-select index (for external SPI)
  9. default: 1
  10. [-m <val>] SPI mode
  11. [-f <val>] bus frequency in kHz
  12. [-q] quiet startup (no message if no device found)
  13. [-R <val>] Rotation
  14. default: 0
  15. stop
  16. status print status info

paw3902

Source: drivers/optical_flow/paw3902

Usage

  1. paw3902 <command> [arguments...]
  2. Commands:
  3. start
  4. [-s] Internal SPI bus(es)
  5. [-S] External SPI bus(es)
  6. [-b <val>] board-specific bus (default=all) (external SPI: n-th bus
  7. (default=1))
  8. [-c <val>] chip-select index (for external SPI)
  9. default: 1
  10. [-m <val>] SPI mode
  11. [-f <val>] bus frequency in kHz
  12. [-q] quiet startup (no message if no device found)
  13. [-Y <val>] custom yaw rotation (degrees)
  14. default: 0
  15. stop
  16. status print status info

pca9685

Source: drivers/pca9685

Usage

  1. pca9685 <command> [arguments...]
  2. Commands:
  3. start
  4. [-I] Internal I2C bus(es)
  5. [-X] External I2C bus(es)
  6. [-b <val>] board-specific bus (default=all) (external SPI: n-th bus
  7. (default=1))
  8. [-f <val>] bus frequency in kHz
  9. [-q] quiet startup (no message if no device found)
  10. reset
  11. test enter test mode
  12. stop
  13. status print status info

pca9685_pwm_out

Source: drivers/pca9685_pwm_out

Description

This module is responsible for generate pwm pulse with PCA9685 chip.

It listens on the actuator_controls topics, does the mixing and writes the PWM outputs.

Implementation

This module depends on ModuleBase and OutputModuleInterface. IIC communication is based on CDev::I2C

Examples

It is typically started with:

  1. pca9685_pwm_out start -a 64 -b 1

Use the mixer command to load mixer files. mixer load /dev/pwm_outputX etc/mixers/quad_x.main.mix The number X can be acquired by executing pca9685_pwm_out status when this driver is running.

Usage

  1. pca9685_pwm_out <command> [arguments...]
  2. Commands:
  3. start Start the task
  4. [-a <val>] device address on this bus
  5. default: 64
  6. [-b <val>] bus that pca9685 is connected to
  7. default: 1
  8. [-r <val>] schedule rate limit
  9. default: 400
  10. stop
  11. status print status info

pcf8583

Source: drivers/rpm/pcf8583

Usage

  1. pcf8583 <command> [arguments...]
  2. Commands:
  3. start
  4. [-I] Internal I2C bus(es)
  5. [-X] External I2C bus(es)
  6. [-b <val>] board-specific bus (default=all) (external SPI: n-th bus
  7. (default=1))
  8. [-f <val>] bus frequency in kHz
  9. [-q] quiet startup (no message if no device found)
  10. stop
  11. status print status info

pmw3901

Source: drivers/optical_flow/pmw3901

Usage

  1. pmw3901 <command> [arguments...]
  2. Commands:
  3. start
  4. [-s] Internal SPI bus(es)
  5. [-S] External SPI bus(es)
  6. [-b <val>] board-specific bus (default=all) (external SPI: n-th bus
  7. (default=1))
  8. [-c <val>] chip-select index (for external SPI)
  9. default: 1
  10. [-m <val>] SPI mode
  11. [-f <val>] bus frequency in kHz
  12. [-q] quiet startup (no message if no device found)
  13. [-R <val>] Rotation
  14. default: 0
  15. stop
  16. status print status info

pwm_out

Source: drivers/pwm_out

Description

This module is responsible for driving the output and reading the input pins. For boards without a separate IO chip (eg. Pixracer), it uses the main channels. On boards with an IO chip (eg. Pixhawk), it uses the AUX channels, and the px4io driver is used for main ones.

It listens on the actuator_controls topics, does the mixing and writes the PWM outputs.

The module is configured via mode_* commands. This defines which of the first N pins the driver should occupy. By using mode_pwm4 for example, pins 5 and 6 can be used by the camera trigger driver or by a PWM rangefinder driver. Alternatively, pwm_out can be started in one of the capture modes, and then drivers can register a capture callback with ioctl calls.

Implementation

By default the module runs on a work queue with a callback on the uORB actuator_controls topic.

Examples

It is typically started with:

  1. pwm_out mode_pwm

To drive all available pins.

Capture input (rising and falling edges) and print on the console: start pwm_out in one of the capture modes:

  1. pwm_out mode_pwm3cap1

This will enable capturing on the 4th pin. Then do:

  1. pwm_out test

Use the pwm command for further configurations (PWM rate, levels, …), and the mixer command to load mixer files.

Usage

  1. pwm_out <command> [arguments...]
  2. Commands:
  3. start Start the task (without any mode set, use any of the mode_*
  4. cmds)
  5. All of the mode_* commands will start pwm_out if not running already
  6. mode_gpio
  7. mode_pwm Select all available pins as PWM
  8. mode_pwm8
  9. mode_pwm6
  10. mode_pwm5
  11. mode_pwm5cap1
  12. mode_pwm4
  13. mode_pwm4cap1
  14. mode_pwm4cap2
  15. mode_pwm3
  16. mode_pwm3cap1
  17. mode_pwm2
  18. mode_pwm2cap2
  19. mode_pwm1
  20. sensor_reset Do a sensor reset (SPI bus)
  21. [<ms>] Delay time in ms between reset and re-enabling
  22. peripheral_reset Reset board peripherals
  23. [<ms>] Delay time in ms between reset and re-enabling
  24. i2c Configure I2C clock rate
  25. <bus_id> <rate> Specify the bus id (>=0) and rate in Hz
  26. test Test inputs and outputs
  27. stop
  28. status print status info

pwm_out_sim

Source: drivers/pwm_out_sim

Description

Driver for simulated PWM outputs.

Its only function is to take actuator_control uORB messages, mix them with any loaded mixer and output the result to the actuator_output uORB topic.

It is used in SITL and HITL.

Usage

  1. pwm_out_sim <command> [arguments...]
  2. Commands:
  3. start Start the module
  4. [-m <val>] Mode
  5. values: hil|sim, default: sim
  6. stop
  7. status print status info

px4flow

Source: drivers/optical_flow/px4flow

Usage

  1. px4flow <command> [arguments...]
  2. Commands:
  3. start
  4. [-I] Internal I2C bus(es)
  5. [-X] External I2C bus(es)
  6. [-b <val>] board-specific bus (default=all) (external SPI: n-th bus
  7. (default=1))
  8. [-f <val>] bus frequency in kHz
  9. [-q] quiet startup (no message if no device found)
  10. [-a <val>] I2C address
  11. default: 66
  12. [-R <val>] Rotation (default=downwards)
  13. default: 25
  14. stop
  15. status print status info

rc_input

Source: drivers/rc_input

Description

This module does the RC input parsing and auto-selecting the method. Supported methods are:

  • PPM
  • SBUS
  • DSM
  • SUMD
  • ST24
  • TBS Crossfire (CRSF)

Usage

  1. rc_input <command> [arguments...]
  2. Commands:
  3. start
  4. [-d <val>] RC device
  5. values: <file:dev>, default: /dev/ttyS3
  6. bind Send a DSM bind command (module must be running)
  7. stop
  8. status print status info

rgbled

Source: drivers/lights/rgbled_ncp5623c

Usage

  1. rgbled <command> [arguments...]
  2. Commands:
  3. start
  4. [-I] Internal I2C bus(es)
  5. [-X] External I2C bus(es)
  6. [-b <val>] board-specific bus (default=all) (external SPI: n-th bus
  7. (default=1))
  8. [-f <val>] bus frequency in kHz
  9. [-q] quiet startup (no message if no device found)
  10. [-a <val>] I2C address
  11. default: 57
  12. stop
  13. status print status info

roboclaw

Source: drivers/roboclaw

Description

This driver communicates over UART with the Roboclaw motor driver. It performs two tasks:

  • Control the motors based on the actuator_controls_0 UOrb topic.
  • Read the wheel encoders and publish the raw data in the wheel_encoders UOrb topic

In order to use this driver, the Roboclaw should be put into Packet Serial mode (see the linked documentation), and your flight controller’s UART port should be connected to the Roboclaw as shown in the documentation. For Pixhawk 4, use the UART & I2C B port, which corresponds to /dev/ttyS3.

Implementation

The main loop of this module (Located in RoboClaw.cpp::task_main()) performs 2 tasks:

  1. Write actuator_controls_0 messages to the Roboclaw as they become available
  2. Read encoder data from the Roboclaw at a constant, fixed rate.

Because of the latency of UART, this driver does not write every single actuator_controls_0 message to the Roboclaw immediately. Instead, it is rate limited based on the parameter RBCLW_WRITE_PER.

On startup, this driver will attempt to read the status of the Roboclaw to verify that it is connected. If this fails, the driver terminates immediately.

Examples

The command to start this driver is:

$ roboclaw start

<device> is the name of the UART port. On the Pixhawk 4, this is /dev/ttyS3. <baud> is te baud rate.

All available commands are:

  • $ roboclaw start <device> <baud>
  • $ roboclaw status
  • $ roboclaw stop

Usage

  1. roboclaw <command> [arguments...]
  2. Commands:

safety_button

Source: drivers/safety_button

Description

This module is responsible for the safety button. Pressing the safety button 3 times quickly will trigger a GCS pairing request.

Usage

  1. safety_button <command> [arguments...]
  2. Commands:
  3. start
  4. stop
  5. status print status info

tap_esc

Source: drivers/tap_esc

Description

This module controls the TAP_ESC hardware via UART. It listens on the actuator_controls topics, does the mixing and writes the PWM outputs.

Implementation

Currently the module is implementd as a threaded version only, meaning that it runs in its own thread instead of on the work queue.

Example

The module is typically started with: tap_esc start -d /dev/ttyS2 -n <1-8>

Usage

  1. tap_esc <command> [arguments...]
  2. Commands:
  3. start Start the task
  4. [-d <val>] Device used to talk to ESCs
  5. values: <device>
  6. [-n <val>] Number of ESCs
  7. default: 4

tone_alarm

Source: drivers/tone_alarm

Description

This module is responsible for the tone alarm.

Usage

  1. tone_alarm <command> [arguments...]
  2. Commands:
  3. start
  4. stop
  5. status print status info

vmount

Source: modules/vmount

Description

Mount (Gimbal) control driver. It maps several different input methods (eg. RC or MAVLink) to a configured output (eg. AUX channels or MAVLink).

Documentation how to use it is on the gimbal_control page.

Implementation

Each method is implemented in its own class, and there is a common base class for inputs and outputs. They are connected via an API, defined by the ControlData data structure. This makes sure that each input method can be used with each output method and new inputs/outputs can be added with minimal effort.

Examples

Test the output by setting a fixed yaw angle (and the other axes to 0):

  1. vmount stop
  2. vmount test yaw 30

Usage

  1. vmount <command> [arguments...]
  2. Commands:
  3. start
  4. test Test the output: set a fixed angle for one axis (vmount must
  5. not be running)
  6. roll|pitch|yaw <angle> Specify an axis and an angle in degrees
  7. stop
  8. status print status info

voxlpm

Source: drivers/power_monitor/voxlpm

Usage

  1. voxlpm [arguments...]
  2. start
  3. [-I] Internal I2C bus(es)
  4. [-X] External I2C bus(es)
  5. [-b <val>] board-specific bus (default=all) (external SPI: n-th bus
  6. (default=1))
  7. [-f <val>] bus frequency in kHz
  8. [-q] quiet startup (no message if no device found)
  9. [-T <val>] Type
  10. values: VBATT|P5VDC|P12VDC, default: VBATT
  11. [-k] if initialization (probing) fails, keep retrying periodically
  12. stop
  13. status print status info