Motor Setup & Motor Mixing - heliflight3d/heliflight GitHub Wiki
The motor outputs for Heliflight are defined using the resource MOTOR <motor #> <pin>
command. This tells Heliflight which motors are assigned to which pins on the STM32 microcontroller. Each motor output pin must have a timer channel associated with it. Please see the Wiki page on Resource Assignments for more guidance on assigning motor pins and timers.
Motor output resources are assigned using numbers starting with 1. Typically, "MOTOR 1" is setup to be the main motor, and "MOTOR 2" is setup to be the tail motor (for motor-driven tail helicopters).
As an example, the line below will mix the output of our main motor governor (G1) into the output resource assigned to Motor 1 (M1).
mixer rule 9 set G1 M1 0 1000 0 1000
This rule will tell Heliflight that we want to control the output to a single speed controller. Heliflight will then use the main motor governor code to look at some other parameters and determine how to convert the Throttle RC command from the receiver into an output command to the Electronic Speed Control (ESC).
First, Heliflight's governor will check the gov_max_headspeed
setting to see if it is non-zero. If this setting is zero Heliflight will then pass-through the throttle signal to the ESC.
Second, Heliflight will check the spoolup_time
setting to see if it needs to slowly ramp up the throttle until the main motor is at full speed. If spoolup_time is zero, then the throttle signal will be directly passed through to the ESC without any change. This can work well for ESCs with an internal governor mode that includes a soft spool-up. If spoolup_time setting is greater than zero, the throttle signal will be slowly ramped up from zero to the Throttle RC command value over the course of spoolup_time seconds. This works well for ESCs running in Airplane mode or Helicopter external governor mode.
The motor mixer will use other settings depending on the ESC protocol chosen by the user. Standard PWM protocol uses min_command
and max_command
values to determine what the output PWM value will be. The min_throttle
command is not used for the main motor in Helflight for safety reasons. The min_command
value will always be the lowest output value for the main motor. The DSHOT protocol uses the dshot_idle_value
setting to set the minimum motor command while armed, but only for the tail motor. Again, for safety reasons the main motor will always use the absolute minimum value which corresponds with fully off.
If you need to calibrate the throttle endpoints for your ESC that uses standard PWM control, you can connect to the flight controller via a USB cable and then enter the Motor tab in Configurator. Enable the motor outputs with the switch and then set the motor 1 slider to whatever position is required by the ESC when it starts up. Now apply battery power to the ESC (with the blades and/or motor wires disconnected!) and then use the motor 1 slider to change the throttle output to the ESC as required by the ESC manufacturer's process to calibrate the throttle endpoints. You should only do this AFTER you have set the min_command
and max_command
values to your desired setting.
Heliflight can drive the main motor ESC in a variety of ways. Heliflight includes an internal governor mode to regulate headspeed, as well as a throttle pass-through mode for driving an ESC with an external governor or when using radio throttle curves.
Heliflight's internal governor includes an autorotation bailout feature, as well as support for assisting the tail motor on helicopters with a motor-driven tail. The internal governor requires a high-speed RPM source, which could be from DSHOT bi-directional RPM telemetry, an ESC RPM wire, or a cheap Hobbywing brushless motor RPM sensor.
Note that the mixer input should always be set to "G1" even if pass-through throttle mode is desired.
The internal governor is enabled by setting the gov_max_headspeed setting to the maximum RPM that you wish to govern to. It is suggested to use a calculator such as Mel's headspeed calculator to get a realistic idea of the maximum RPM that you should target for your setup. The example setting below would set 2200 rpm as the maximum headspeed.
set gov_max_headspeed = 2200
The throttle signal from your radio will now set the desired RPM. If you set the output of your radio to 70%, you will get 70% of the maximum headspeed setting. Heliflight will govern from 20% to 100% of the maximum headspeed setting. Below 20% is considered the autorotation range, and Heliflight will not spool up until throttle is increased above 20%. Once the governor is spooled up, a setting between 1% and 20% will allow for autorotation with a rapid bailout if the throttle is then increased above 20%. If you land the helicopter in this mode, please set the throttle to zero and/or disarm before re-engaging a throttle output above 20% or you risk folding the blades of the helicopter back.
You will need to setup the gear ratio of your heli so that the governor can interpret the RPM signal appropriately. Set the gov_gear_ratio
to 1000x the main gear ratio of your heli. For example, a gear ratio of 10.9:1 would be a setting of:
set gov_gear_ratio = 10900
You will want to enable Heliflight's soft spoolup by setting the gov_spoolup_time setting to the number of seconds that you desire the throttle to ramp up over. No matter the spoolup time setting, the governor will allow for a 5 second loss of throttle signal (0 throttle) before it requires a soft spool-up again.
set gov_spoolup_time = 6
Other internal governor settings:
gov_p_gain
gov_i_gain
gov_cyclic_ff_gain
gov_collective_ff_gain
gov_collective_ff_impulse_gain
gov_tailmotor_assist_gain
Only used for motor-driven tail helis
Pass-through throttle mode is enabled by disabling the internal governor in Heliflight. You do this by setting the gov_max_headspeed setting = 0.
set gov_max_headspeed = 0
If your ESC does not include a soft spool-up feature, then you will want to enable Heliflight's soft spoolup by setting the gov_spoolup_time setting to the number of seconds that you desire the throttle to ramp up over.
set gov_spoolup_time = 6
If you have set a soft-start spool-up time, the governor will allow a 5 second loss of throttle signal (0 throttle) before it requires a soft spool-up again.
While the throttle pass-through mode does not use an RPM signal to operate, it is highly enouraged to provide an RPM input to Heliflight so that it can be used for RPM-based vibration filtering. Please also set the gov_gear_ratio
setting appropriately. The setting should be 1000x the main gear ratio of your heli.
That is all it takes to get your throttle pass-through setup properly in Heliflight.
If you are using a helicopter with a motor-driven tail, you will need to configure the tail motor settings. Skip this section if you have a servo driven tail.
First, ensure that you have a motor resource setup for MOTOR 2. See the section at the top of this article if you have not done this yet. You will also want to check to be sure that you have the correct tail motor ESC settings. If it's a BlHeliS or BlHeli32 ESC, use the correct BlHeli Configurator to do make any changes. The tail ESC should be setup for DSHOT operation with braking enabled, damped mode enabled, and maximum ramp-up power.
Now that the tail ESC settings are configured properly, we will want to set the minimum throttle value for the tail motor. This is important so that we can ensure the tail motor will not stop in flight. We will set the default minimum throttle for the tail motor while armed using the dshot_idle_value
setting. Make sure that the main and tail blades are removed, and then power up the helicopter. Go into the "Motors" tab of Configurator and arm the flight controller using the switch in the GUI. Now, slowly increase the tail motor throttle until it just begins to spin. Note the throttle value shown. Go back into the CLI and se the following command to setup the tail motor idle value to the throttle value you just found:
set dshot_idle_value = <throttle_value>
-
save
your change.
This is also a good time to check and ensure the tail motor is rotating in the correct direction. The thrust from the tail propeller should counter-act the main motor torque (for clockwise main blade rotation the heli will try to rotate counter-clockwise, so the tail prop should push air to the right when looking down at the helicopter). If you need to reverse the tail motor rotation you can do this in your ESC configuration tool or by swapping any two of the tail motor wires, whichever way is easiest.
Next, add the mixer rule needed to pass the output of the PID controller's yaw axis calculations to the tail motor governor (G2). Check the mixer
command to see what rules you already have defined (if any). Delete any rules dealing with servo #4 (the tail servo) if they exist. If there is already a rule for the tail motor (input "G2" and output "M2"), check that it matches the rule below. If you need to change an existing rule, just send a new mixer command with the same rule number as the existing rule. If there is no existing rule, just choose the next available rule number and issue the command below:
mixer rule <rule_#> set G2 M2 0 1000 -1000 1000
Then we will configure the mixer scaling and pidsum_limit_yaw to give full output:
mixscale SY 1000
set pidsum_limit_yaw = 500
The next thing we need to do is configure the main motor governor so that it will assist the tail motor when the tail motor is asked to provide reverse thrust (which it cannot do). We'll set this to 46 by default:
set gov_tailmotor_assist_gain = 46
Finally, it is a good idea to setup a base thrust for the tail motor that will be used as a base for the PID controller to work off of.
set yaw_base_thrust = 100
save
your changes. You have completed the tail motor setup.
Head over to the PID Controller Tuning & Flight Settings article next.