# How to modify the mixer for a quadrotor to account for bidirectional motors?

**URL:** <https://discuss.px4.io/t/how-to-modify-the-mixer-for-a-quadrotor-to-account-for-bidirectional-motors/6571>\
**Category:** Uncategorized\
**Created:** [May 7, 2018, 5:13pm UTC](https://discuss.px4.io/t/how-to-modify-the-mixer-for-a-quadrotor-to-account-for-bidirectional-motors/6571 "2018-05-07T17:13:55Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![coreysmiles](https://discuss.px4.io/letter_avatar_proxy/v4/letter/c/5daacb/32.png) [@coreysmiles](https://discuss.px4.io/u/coreysmiles)\
**Post date:** [May 7, 2018, 5:13pm UTC](https://discuss.px4.io/t/how-to-modify-the-mixer-for-a-quadrotor-to-account-for-bidirectional-motors/6571/1 "2018-05-07T17:13:55Z")

</div>

Hi,  
I am trying to modify the Px4 firmware for a quadrotor that has bidirectional motors, to enable inverted flight (so that the quadrotor can fly upside down). The basic principle is that since the motors can operate in both directions, the scaling for the output PWM has changed. Normally, 1000 is the minimum PWM corresponding to no power, 2000 is the maximum PWM corresponding to full power. With the bidirectional motors, 1000 corresponds to full power in the reverse direction, and thus the middle value, 1500 results in no power. I have configured the ESC’s for the bidirectional capability using BLHeli, and now I’m trying to understand how to account for this in the firmware. I have been trying to understand the file mixer\_multirotor.cpp, to see if I can modify the mapping of the outputs to the range [-1,1], and have not had much success. I’ve also looked through mc\_att\_control\_main.cpp, pwm.cpp, pwm\_limit.c and motor\_ramp.cpp. It’s a bit confusing and I don’t fully understand the process to get from the controller to the commands actually sent to the actuators. If someone can clarify any of this or point me in the right direction it would be much appreciated.  
Thanks!

---

<div class="post-metadata">

**Author:** ![RicardoM17](https://discuss.px4.io/user_avatar/discuss.px4.io/ricardom17/32/4040_2.png) [@RicardoM17](https://discuss.px4.io/u/RicardoM17)\
**Post date:** [May 8, 2018, 8:35pm UTC](https://discuss.px4.io/t/how-to-modify-the-mixer-for-a-quadrotor-to-account-for-bidirectional-motors/6571/2 "2018-05-08T20:35:19Z")

</div>

Have you looked at

[https://dev.px4.io/en/airframes/adding\_a\_new\_frame.html](https://dev.px4.io/en/airframes/adding_a_new_frame.html)

and

[https://dev.px4.io/en/concept/mixing.html](https://dev.px4.io/en/concept/mixing.html)

It should have all that you need.

No need to look at any .cpp files at all. Just write a new mixer (maybe create a new airframe because why not) and should be good to go (but make sure you test it safely ofc)

---

<div class="post-metadata">

**Author:** ![adavis](https://discuss.px4.io/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@adavis](https://discuss.px4.io/u/adavis)\
**Post date:** [May 9, 2018, 2:07am UTC](https://discuss.px4.io/t/how-to-modify-the-mixer-for-a-quadrotor-to-account-for-bidirectional-motors/6571/3 "2018-05-09T02:07:40Z")

</div>

I am having a similar problem with a bidirectional motor. It clips the negative range [1000,1500), or when reversed, clips the positive range (1500, 2000]. I have read both documents but its not clear to me what is happening.

---

<div class="post-metadata">

**Author:** ![RicardoM17](https://discuss.px4.io/user_avatar/discuss.px4.io/ricardom17/32/4040_2.png) [@RicardoM17](https://discuss.px4.io/u/RicardoM17)\
**Post date:** [May 9, 2018, 2:42am UTC](https://discuss.px4.io/t/how-to-modify-the-mixer-for-a-quadrotor-to-account-for-bidirectional-motors/6571/4 "2018-05-09T02:42:01Z")

</div>

do you have any logs? When you say clips you mean it doesn’t output in that range when in a certain mode etc?

I have no experience with bidirectional robots, but I believe that all it requires is for the correct PWM to be sent to the motor or ESC. And if the mixer is properly built then it shouldn’t be an issue.

You two just need to figure out when do you want the the motor to reverse and write the respective mixer (the mixer writing part is in the links I sent explained).

---

<div class="post-metadata">

**Author:** ![Shea](https://discuss.px4.io/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@Shea](https://discuss.px4.io/u/Shea)\
**Post date:** [May 9, 2018, 2:02pm UTC](https://discuss.px4.io/t/how-to-modify-the-mixer-for-a-quadrotor-to-account-for-bidirectional-motors/6571/5 "2018-05-09T14:02:11Z")

</div>

> [@adavis](#):
>
> I am having a similar problem with a bidirectional motor. It clips the negative range [1000,1500), or when reversed, clips the positive range (1500, 2000]. I have read both documents but its not clear to me what is happening.

I am having the same problem.

 ![](https://discuss.px4.io/uploads/default/original/2X/c/c75d4b6fa94e39daa65efa97d348e83c7656146e.png)

I am using a custom airframe - UGV - and have tried many different mixer combinations and continue to see that when negative values are given by the RC controller the PWM out does not reflect those values. This only happens on the throttle channel, other servos and channels respond as expected. I have tried multiple mixer control groups including the straight passthrough which also did the same thing.

I have also tried incorporating VTOL attitude control, specifically trying to get the VT\_B\_TRANS\_THR parameter as in the text it says "3D ESCs assume 0 thrust at 50% throttle, positive (forward) thrust above 50% and negative thrust (reverse) below 50%. " and this is exactly the type ESC I am using. Note, no luck with this endeavor.

I am not sure where to go next in trying to troubleshoot this issue. I know I have put in about 20+ hours trying to troubleshoot the issue and would love to hear some other ideas.

I think coreysmiles has it right →

> [@coreysmiles](#):
>
> It’s a bit confusing and I don’t fully understand the process to get from the controller to the commands actually sent to the actuators. If someone can clarify any of this or point me in the right direction it would be much appreciated.

It seems multiple people are encountering this issue, so any guidance and direction would be much appreciated.

Thanks.

---

<div class="post-metadata">

**Author:** ![BUZER](https://discuss.px4.io/letter_avatar_proxy/v4/letter/b/ecccb3/32.png) [@BUZER](https://discuss.px4.io/u/BUZER)\
**Post date:** [May 9, 2018, 2:40pm UTC](https://discuss.px4.io/t/how-to-modify-the-mixer-for-a-quadrotor-to-account-for-bidirectional-motors/6571/6 "2018-05-09T14:40:32Z")

</div>

If you succeed with your project let us know because I wonder how quad will behave if you put him upsidedown, I mean from physical point of view it would be very hard to stop motors and make them run to reverse so quickly that quadcopter will not fall few meters down or crush. Propeller and motor’s momentum is very high, so to stop such a force even if diameter and weight of it is small will influence rapidly bearing lifetime and inrush currents would be overloading everything -ESC, motor windings and battery.  
Wouldn’t be better, simpler and more reilable to do the same propeller controller system like in the helicopter?

---

<div class="post-metadata">

**Author:** ![adavis](https://discuss.px4.io/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@adavis](https://discuss.px4.io/u/adavis)\
**Post date:** [May 9, 2018, 3:17pm UTC](https://discuss.px4.io/t/how-to-modify-the-mixer-for-a-quadrotor-to-account-for-bidirectional-motors/6571/7 "2018-05-09T15:17:33Z")

</div>

@Shea have you tried it on a non-throttle channel? I used control group 0 and ran my bidirectional ESC on the yaw channel by physically changing the hardware connection. I am able to get the expected response or rotors turning one direction and then the other. I do not know why it doesn’t seem to work on the throttle channel.

@BUZER, I agree. That’s sort of what I am wanting to look at. Using the bidirectional motor I expect would make this very feasible. I just don’t understand why the throttle channel appears to be treated differently and how this can be changed.

---

<div class="post-metadata">

**Author:** ![Shea](https://discuss.px4.io/letter_avatar_proxy/v4/letter/s/3ab097/32.png) [@Shea](https://discuss.px4.io/u/Shea)\
**Post date:** [May 9, 2018, 4:25pm UTC](https://discuss.px4.io/t/how-to-modify-the-mixer-for-a-quadrotor-to-account-for-bidirectional-motors/6571/8 "2018-05-09T16:25:06Z")

</div>

> [@adavis](#):
>
> @Shea have you tried it on a non-throttle channel? I used control group 0 and ran my bidirectional ESC on the yaw channel by physically changing the hardware connection. I am able to get the expected response or rotors turning one direction and then the other. I do not know why it doesn’t seem to work on the throttle channel.

I was successful getting the full PWM range corresponding the RC using another channel. I swapped the wiring and was able to control the esc/motor as intended using the RC. Problem is running a Mission, which would be the next step. The esc/motor needs to be on channel 3 for throttle control and that is the channel I cannot get to work properly.

---

<div class="post-metadata">

**Author:** ![adavis](https://discuss.px4.io/letter_avatar_proxy/v4/letter/a/e9bcb4/32.png) [@adavis](https://discuss.px4.io/u/adavis)\
**Post date:** [May 9, 2018, 6:14pm UTC](https://discuss.px4.io/t/how-to-modify-the-mixer-for-a-quadrotor-to-account-for-bidirectional-motors/6571/9 "2018-05-09T18:14:37Z")

</div>

Good point. I don’t understand why the channels aren’t configured the same such that the user could define their behavior. Do you think this potentially qualifies a reportable bug in the firmware?

---

<div class="post-metadata">

**Author:** ![RicardoM17](https://discuss.px4.io/user_avatar/discuss.px4.io/ricardom17/32/4040_2.png) [@RicardoM17](https://discuss.px4.io/u/RicardoM17)\
**Post date:** [May 9, 2018, 11:02pm UTC](https://discuss.px4.io/t/how-to-modify-the-mixer-for-a-quadrotor-to-account-for-bidirectional-motors/6571/10 "2018-05-09T23:02:46Z")

</div>

> [@BUZER](#):
>
> dly bearing lifetime and inrush currents would be overloading everything -ESC, motor windings and battery.

if you search for the omnicopter videos you will see how the motors change directions mid flight. However that system is overactuated so if one engine is down for an instant it doesnt really matter much. So I’m curious for this aswell. However I believe that the direction reversal is not as slow as you’d think
