How to Change Firmware Parameters Pre-Flash/From Source?

Hello,

I have been using PX4 for a while to make custom drones but only recently started to delve deeper as a software developer. In short, how can one change the Firmware Parameters, that would normally be changed via QGC, before flashing the Firmware onto the board? Perhaps even including calibration parameters?

Long Story. To allow my custom drone to work, I need to change various parameters in the PX4 firmware. For example, to communicate with the Companion computer and to enable additional sensors (PX4 Flow). Now, I would also like to develop and test my own PX4 software module but it would be very cumbersome to have to re-calibrate the drone and change almost a dozen parameters after every flash, just to be able to perform a test flght of the module.

Hopefully, there is some file somewhere that has all the parameters conveniently listed out but any help would be appreciated. I look forward to hearing any advice. Thank you in advance.

Take a look in Firmware/src/lib/parameters/parameters_injected.xml

Hello and Thank you @jimdgit for your quick reply.

Unfortunately, those are not the parameters I was hoping for. In the file, I noticed parameters that seemed lower level in the Firmware such as mot_v_max which configures the motor voltage limits. After double checking inside QGC, I can confirm that mot_v_max, (likely along with the rest of the parameters in parameters_injected.xml) are not the same parameters that are normally editable through QGC.

For example, I normally need to change about 7 parameters in QGC to enable the PX4 Firmware to work with an additional sensor (PX4 Flow Sensor) I have embedded in my custom drone design. Below are a few of the parameters:

  1. SENS_FLOW_ROT | Configures the orientation of the sensor.
  2. SENS_FLOW_MAXHGT | Configures the max height to consider the sensor in sensor fusion.
  3. SENS_FLOW_MINHGT | Configures the min height to consider the sensor in sensor fusion.
  4. SENS_EN_PX4FLOW | Boolean that enables the Sensor in Firmware
  5. SYS_MC_EST_GROUP | Select Sensor Fusion Algorithm (Select Local Position Estimator)
  6. LPE_FUSION | Select Sensors to include in Sensor Fusion (Include PX4 Optical Flow)

I would like to be able to adjust these parameters^^, along with any other parameter normally accessible through QGC, before flashing the firmware to the board. Ideally, this would also include sensor calibration parameters so that I do not have to recalibrate the drone after every time I change/improve my custom software module.

Thank you again, and I would really appreciate any help/guidance.

I see.
Look in /Firmware/build/px4_sitl_default/src/lib/parameters/px4_parameters.c

Wouldn’t the airframes folder be the more suitable choice? https://github.com/PX4/Firmware/tree/master/ROMFS/px4fmu_common/init.d/airframes

You can specify any parameter you want and it will be loaded if you set SYS_AUTOCONFIG to 1.

That is a much better idea - just change the airframe you are using.
Can you set any parameter there?

Thank you both for the quick reply and @Georacer-avy for the new piece of great information.

I’d like to confirm how to change parameters via an example. Since I am using a custom drone, the airframe configuration file associated with my airframe would be found in /Firmware/ROMFS/px4fmu_common/init.d/airframes/4001_quad_x

The original file, looks like this:

#!/bin/sh
#
# @name Generic Quadcopter
#
# @type Quadrotor x
# @class Copter
#
# @output MAIN1 motor 1
# @output MAIN2 motor 2
# @output MAIN3 motor 3
# @output MAIN4 motor 4
# @output MAIN5 feed-through of RC AUX1 channel
# @output MAIN6 feed-through of RC AUX2 channel
#
# @output AUX1 feed-through of RC AUX1 channel
# @output AUX2 feed-through of RC AUX2 channel
# @output AUX3 feed-through of RC AUX3 channel
# @output AUX4 feed-through of RC FLAPS channel
#
# @maintainer Lorenz Meier <lorenz@px4.io>
#

sh /etc/init.d/rc.mc_defaults

set MIXER quad_x

set PWM_OUT 1234

To make things easy, let’s just say I want to adjust one parameter, SENS_EN_PX4FLOW, and make sure it is loaded by default. I would just have to add two lines to the file to make it look like this:

#!/bin/sh

#
#----I removed code that was commented out----- 
#

sh /etc/init.d/rc.mc_defaults

set MIXER quad_x

set PWM_OUT 1234

set SENS_EN_PX4FLOW 1

set SYS_AUTOCONFIG 1

Is this correct?

Thank you very much.

Take a look at some more (derived) airframe files. Most have a conditional clause on SYS_AUTOCONFIG, as there’s no need to re-set parameters at each boot; they are saved anyway.

You just need them to be read only once, or every time you set SYS_AUTOCONFIG=1 manually and reboot.

For example, the rover file contains:

sh /etc/init.d/rc.rover_defaults

if [ $AUTOCNF = yes ]
then
	param set GND_L1_DIST 5
	param set GND_SP_CTRL_MODE 1
	param set GND_SPEED_D 3
	param set GND_SPEED_I 0.001
	param set GND_SPEED_IMAX 0.125
	param set GND_SPEED_P 0.25
	param set GND_SPEED_THR_SC 1
	param set GND_SPEED_TRIM 4
	param set GND_THR_CRUISE 0.3
	param set GND_THR_IDLE 0
	param set GND_THR_MAX 0.5
	param set GND_THR_MIN 0

	param set MIS_LTRMIN_ALT 0.01
	param set MIS_TAKEOFF_ALT 0.01
	param set NAV_ACC_RAD 0.5
	param set NAV_LOITER_RAD 2

	param set CBRK_AIRSPD_CHK 162128

	param set GND_MAX_ANG 0.6
	param set GND_WHEEL_BASE 2.0

fi

set MAV_TYPE 10

set MIXER_FILE etc/mixers-sitl/rover_sitl.main.mix

Hello @Georacer-avy and thank you for the quick reply.

I think I understand what you are saying. To be sure, I’d like to rephrase.

  1. Identify the airframe file associated with your vehicle. In my case it is located under
    /Firmware/ROMFS/px4fmu_common/init.d/airframes/4001_quad_x
  2. Modify the file to include a conditional if-statement and custom parameters, as shown in your example above.
  3. Connect Flight Controller (Pixhawk 4) to the Dev Computer via USB
  4. Compile and flash firmware onto the Pixhawk 4 (Flight Controller).
  5. Open QGGroundControl and wait for the Flight Controller to connect. Next, go to Parameters, and set SYS_AUTOCONFIG=1
  6. Reboot Flight Controller.
  7. All Subsequent startups will load the new custom parameters, outlined in the airframe file.

Does that just about sum it up? Please correct me if I am wrong.

Yes, this is what I have in mind. Try and see if it works!