Using custom mixes
« on: November 29, 2015, 09:40:42 pm »
Hello,

Before I start asking questions - thank you for starting this fork and all the hard work you've put to make LibrePilot for all of us rc hobbyists.

I've been playing a bit with custom mixes recently, but it was a bit in the dark and I'm not sure I understand it correctly.

1. Why does the "Quad X" setting has 50% mix level by default?

2. I use this to calculate my mix values: https://www.iforce2d.net/mixercalc/ , as you might notice there's no openpilot type kind of output listed, so I was calculating that myself. Assuming the example ZMR frame that provides me with output:

Code: [Select]
cmix <motor> <throttle> <roll> <pitch> <yaw>
cmix 1 1 -1 0.772 -1
cmix 2 1 -1 -0.772 1
cmix 3 1 1 0.772 1
cmix 4 1 1 -0.772 -1

Am I correct to translate it like that to LibrePilot custom mixes? (note that signs are different)

Code: [Select]
Channel 1
THROTTLE (Curve 1): 127
Roll: 64
Pitch: (64*0.772) ~= 49
Yaw: -64

Channel 2
THROTTLE (Curve 1): 127
Roll: -64
Pitch: (64*0.772) ~= 49
Yaw: 64

Channel 3
THROTTLE (Curve 1): 127
Roll: -64
Pitch: (-64*0.772) ~= -49
Yaw: -64

Channel 2
THROTTLE (Curve 1): 127
Roll: 64
Pitch: (-64*0.772) ~= -49
Yaw: 64

I'll be extremely grateful if you can enlighten / correct me if I'm wrong with above calculations. :) Thanks.

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Using custom mixes
« Reply #1 on: November 29, 2015, 09:57:30 pm »
Hi,

This calc looks very strange for me, it reduces the pitch mixing (based in geometry only) while this axis is the more hard to move due to weight placement.
As a test, try to rotate your quad by hand on Pitch axis and Roll axis...
Pitch PID are already more high using Pitch50%/Roll50%

If you put this values on mixer, i'm sure you find more higher Pitch PID values after tuning.

More complex frames like Hexacopter or Octocopter do not use the same logic like your online mixercalc but this one: http://wiki.paparazziuav.org/wiki/RotorcraftMixing

« Last Edit: November 29, 2015, 10:01:12 pm by f5soh »

Re: Using custom mixes
« Reply #2 on: November 30, 2015, 08:09:36 am »
@muchzill4

1. Why does the "Quad X" setting has 50% mix level by default?
A. One would think it really should be 33%, so that full output from all three flight control directions at the same time can never add up to more than 100%.  It's a compromise.

2. I use this to calculate my mix values: https://www.iforce2d.net/mixercalc/ , as you might notice there's no openpilot type kind of output listed, so I was calculating that myself. Assuming the example ZMR frame that provides me with output:
A. A picture or description of the motor configuration would help us help you  :)  but let me add that I have never really looked at the mixer stuff and looking at it I must say that it isn't clear to me why it is done that way.  And I'm a dev with a math degree.  :)  My assumptions would be that the values can run from +127 to -128 (maybe use -127 for symmetry).  That + quad should use +127 or -128 in all slots.  That X quad should use .707 times those values in all slots.  (well except for throttle which should always be 127)  And that mix level should be 33% for a quad (50% for a tricopter since yaw doesn't affect motor RPM).  If someone used higher values there to get more response, then I worry what happens when stabilization asks for max everything in the wrong direction and it overflows.  I think I see that in some flip recoveries and I will try the values that math says should work.  Be aware that we do have code that handles overflow from throttle by e.g. automatically reducing throttle to give enough head room for the desired stabilization.

Generally for a strange multicopter, it takes trig to calculate the correct values with .707 being sine(45)=cosine(45) and the 45 being the angle of the quad X arm from straight ahead / straight to the side...

Re: Using custom mixes
« Reply #3 on: November 30, 2015, 09:53:07 am »
Thanks for you replies!

@TheOtherCliff

Unfortunately I don't have my quad at hand, but this topic is very interesting to me so I might continue on an example.



Code: [Select]
Where:
b = 2/3a

I hope that not providing exact values is fine - I think we have enough, but please correct me if I'm wrong. :)

1. Does that mean that each motor mix should be equal to sin(α) * -/+127?
2. What about roll axis not being equal in length to pitch axis?
3. With what you said about handling overflow - is it better to go with 33% or stick to the 50% compromise? Does that affect full power output anyhow?

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Using custom mixes
« Reply #4 on: November 30, 2015, 11:43:47 am »
Some calc using the http://wiki.paparazziuav.org/wiki/RotorcraftMixing method :



Python script attached.

Re: Using custom mixes
« Reply #5 on: November 30, 2015, 11:54:25 am »
@f5soh, thanks for that, that's very descriptive. :)

It does seem strange to me though, that ZMR has the same motor mixing as the QuadX. The shapes are different. Shouldn't that be accounted for?

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Using custom mixes
« Reply #6 on: November 30, 2015, 12:34:03 pm »
The frame is symmetrical into the two axis, if you really want take in account all thing you should also put weight in equation.
Paparazzi script take care all matrix is balanced.

Re: Using custom mixes
« Reply #7 on: November 30, 2015, 01:58:07 pm »
@f5soh - What do you mean by "Paparazzi script take care all matrix is balanced."? :)

f5soh

  • *****
  • 4572
    • LibrePilot
Re: Using custom mixes
« Reply #8 on: November 30, 2015, 02:01:12 pm »
Look the python script attached to previous post and follow the link to the Paparazzi page with all the math.

Re: Using custom mixes
« Reply #9 on: November 30, 2015, 07:03:20 pm »
Those mixer tables with only/mostly 64,-64 don't look correct for the quads that are asymmetric.

Re: Using custom mixes
« Reply #10 on: November 30, 2015, 07:13:57 pm »
@TheOtherCliff - That's my thinking too, although I have little understanding of how that works. :)

Can you please elaborate a bit and answer my questions with the example I've given?

liftbag

  • *****
  • 215
    • LibrePilot
Re: Using custom mixes
« Reply #11 on: November 30, 2015, 07:18:03 pm »
Those mixer tables with only/mostly 64,-64 don't look correct for the quads that are asymmetric.
You are right, but paparazzi script tends to round small differences.

Re: Using custom mixes
« Reply #12 on: November 30, 2015, 07:49:40 pm »
@liftbag - What is considered a small difference? I have a frame that is 180mm on roll axis and 150mm on pitch axis.

liftbag

  • *****
  • 215
    • LibrePilot
Re: Using custom mixes
« Reply #13 on: November 30, 2015, 08:45:45 pm »
@liftbag - What is considered a small difference? I have a frame that is 180mm on roll axis and 150mm on pitch axis.
If your cog is positioned in center of both axes you don't need a custom matrix.
The different axes weights in the error correction is compensated by the PIDs that, if properly calculated, take into account the asymmetries in the distribution of weight or differences in the lever arm.

Re: Using custom mixes
« Reply #14 on: November 30, 2015, 10:22:32 pm »
Damn.  Wrong button and lost a lot of typing...

@muchzill4
Speaking from math and not LP here...
Measure the distance from each motor shaft both roll and pitch axis.  Scale so that the longest one is 1.0 and all the others are less than 1.
All your motors are the same distance to the roll axis and that distance is the longest so your roll factor is 1.0
All your motors are the same distance to the pitch axis and that scaled distance is b/a.
All your motors are the same distance to the yaw axis so you will use 127 there.
All your roll values will be +-127
All your pitch values will be (+-)127b/a
All your yaw values will be +-127
All your roll values for motors on the right size will have plus signs and left side minus signs
All your pitch values for motors in front will have plus signs and in back minus signs
All your yaw values for counter clockwise motors will have plus signs and clockwise will have minus signs.

I searched and read the source code and the "Mix Level" is not even used any more.

These above values _may_ have the effect of making the stabilization more sensitive, and thus the default PIDs may be too high.

Everything is immediately converted to floating point and scaled automatically.  This includes throttle head room at high and low throttle.  If you have 100% throttle and stabilization needs +-10% roll, then the throttle will be reduced 10% so that the motors can be set to 80% and 100%.

As Liftbag said, for most frames, you can simply use different PIDs for roll and pitch, and that should even work for A frame (trapezoid) quads if you adjust PIDs empirically.  Still, there are some multicopter designs that need mixer table changes.
« Last Edit: November 30, 2015, 10:33:23 pm by TheOtherCliff »