LibrePilot Forum

General Category => General Discussion => Topic started by: muchzill4 on November 29, 2015, 09:40:42 pm

Title: Using custom mixes
Post by: muchzill4 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.
Title: Re: Using custom mixes
Post by: f5soh 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

Title: Re: Using custom mixes
Post by: TheOtherCliff 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...
Title: Re: Using custom mixes
Post by: muchzill4 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.

(http://i.imgur.com/54PhFWu.jpg)

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?
Title: Re: Using custom mixes
Post by: f5soh on November 30, 2015, 11:43:47 am
Some calc using the http://wiki.paparazziuav.org/wiki/RotorcraftMixing method :

(https://forum.librepilot.org/index.php?action=dlattach;topic=338.0;attach=662;image)

Python script attached.
Title: Re: Using custom mixes
Post by: muchzill4 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?
Title: Re: Using custom mixes
Post by: f5soh 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.
Title: Re: Using custom mixes
Post by: muchzill4 on November 30, 2015, 01:58:07 pm
@f5soh - What do you mean by "Paparazzi script take care all matrix is balanced."? :)
Title: Re: Using custom mixes
Post by: f5soh 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.
Title: Re: Using custom mixes
Post by: TheOtherCliff 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.
Title: Re: Using custom mixes
Post by: muchzill4 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?
Title: Re: Using custom mixes
Post by: liftbag 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.
Title: Re: Using custom mixes
Post by: muchzill4 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.
Title: Re: Using custom mixes
Post by: liftbag 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.
Title: Re: Using custom mixes
Post by: TheOtherCliff 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.
Title: Re: Using custom mixes
Post by: TheOtherCliff on November 30, 2015, 11:31:27 pm
One more slightly good reason to handle this in the mixing table is so that you can switch from quad X to quad + ("rotate virtual") without retuning PID's at all.  Quad + will have all 127's and quad X will have all 127x0.707=90.

I think this even works with asymmetric multicopters of any shape and size and any rotation angle you want.

A problem is that simple measuring doesn't handle asymmetrically distributed mass (e.g. heavy camera in front and heavy battery in back, but no added mass left-right).

External mag users, don't forget to rotate your aux mag too.
Title: Re: Using custom mixes
Post by: muchzill4 on December 01, 2015, 08:58:30 am
@all - Thank you for your answers. I understand it better now. :)
Title: Re: Using custom mixes
Post by: markus1234 on January 18, 2016, 04:58:56 pm
Hi, very interesting information. Can you tell me were I can find the mixer settings of the predefined frame types?
I want to expand the tricopter mixer to tilt the front motors for yaw and forward (nick==0)..
Title: Re: Using custom mixes
Post by: TheOtherCliff on January 19, 2016, 04:06:31 am
If you set up for instance quad X and then select the custom tab and press save, it will populate and you can see what is there.

Then go back and select another you are interested in such as quad + or tricopter and select custom and press save...
Title: Re: Using custom mixes
Post by: markus1234 on January 19, 2016, 05:00:31 am
Oh, thank you for this easy solution.
Title: Re: Using custom mixes
Post by: TheOtherCliff on January 19, 2016, 05:25:55 am
Be aware that this is just to see what the settings are.  Most people should probably not use Custom to actually fly.  I recall that there are some setup issues you would have to research to actually use Custom to fly.  You might look in the LP wiki.
Title: Re: Using custom mixes
Post by: markus1234 on January 19, 2016, 05:41:59 am
I have to use the custom mixer for my project (3 motors, 2 servos). At my first try, I expected the values to be -100 .. 100%. This already works on my desk, but the servos does maximum 30°...
I'll lookup the wiki, good hint.
Title: Re: Using custom mixes
Post by: slievar on January 19, 2016, 06:24:18 am
Each mixer value is represented as a signed 8bit integer in the code, hence the -128 - 127 range.
Title: Re: Using custom mixes
Post by: TheOtherCliff on January 19, 2016, 02:58:10 pm
At my first try, I expected the values to be -100 .. 100%. This already works on my desk, but the servos does maximum 30°...

Maximum of 30 degrees may be normal depending max roll rate, roll rate, and PIDs.  I remember setting up Attitude mode on a fixed wing on CC3D years ago and that ailerons did not get full servo travel with full stick, but it did get full servo travel if I forced roll in the wrong direction when hand testing.
Title: Re: Using custom mixes
Post by: markus1234 on January 20, 2016, 08:01:25 pm
I've attached a screenshot of the mixer and it seems to work.
I want to support 2 flight basic modes

1. normal tricopter: curve 2 is not used, input to curve 2 is 0, the servos are mounted mirrored, they are working in different directions for yaw only
2. tilt mode: works only stabilized, nick is fixed to 0, input for curve 2 comes from the nick-stick and sends tilt overlay to servos (same direction).

The problem: I've to switch the mode in the transmitter, so the channels for nick and accessory1 are swapped. I think this will work, but the mixer is split in a FC part and in a transmitter part. Do you have an idea for a better solution?
Title: Re: Using custom mixes
Post by: TheOtherCliff on January 23, 2016, 04:27:45 am
I have never done a tricopter.

If you truly just want to swap those RC controls, maybe you could rerun the transmitter wizard and move the other control this time (nick for acc1 and acc1 for nick)?

Or if you are using PWM inputs, just swap the two inputs.
Title: Re: Using custom mixes
Post by: markus1234 on January 23, 2016, 10:28:45 am
Tricopters are easy, even the default settings are ok for different sizes.
Tilting the rotors is different, not new, but unusual.
The Taranis transmitter can easily swap channels with a switch - thats what I'm doing now.
I use s.bus. Maybe I switch to ppm, if I'm running out of com ports.
Title: Re: Using custom mixes
Post by: markus1234 on January 24, 2016, 03:16:36 pm
It drives me crazy..
I have still trouble with "Curve 2". It's source is assigned to "Accessory1" (Channel 8 ). Accessory1 has a range from 1000us to 2000us, center position is 1500. I want the servo mixed with this "Curve 2" to get the same signal, 1000 .. 2000us, center position 1500us.
I've selected "Curve 2" to be linear from -1 to +1. The mixer can be seen on the picture 3 posts above.
The result is:
Stick=1000 -> Servo=2000
Stick=1250 -> Servo=1500
Stick=1500 -> Servo=1000
Stick=1750 -> Servo=1500
Stick=2000 -> Servo=2000
I've tried several setting of "Curve 2", but never got the expected 1:1 result. What is wrong?
Title: Re: Using custom mixes
Post by: markus1234 on January 24, 2016, 04:50:01 pm
If I change the mixer type from "servo" to "Accessory1", the stick will be mapped correct, but the yaw signal is not longer mixed :-(
Title: Re: Using custom mixes
Post by: markus1234 on January 24, 2016, 05:10:11 pm
Obviously it can be done, https://vimeo.com/64357725 (https://vimeo.com/64357725) show an older taulabs implementation. I think the mixer is nearly the same - or am I worng?
Title: Re: Using custom mixes
Post by: markus1234 on January 24, 2016, 06:10:46 pm
The solution: 
Select "Curve 2" to be linear from -1 to +1, was ok. But Accessory1 center position has to be 1000 (so the behaviour is the same as for throttle).
Thank you for reading.
Title: Re: Using custom mixes
Post by: Brunosanta on April 04, 2016, 01:46:04 pm
Hey guys, reading the wiki and checking the calculations, I understand we would need a mix change to one side or another talking Pitch or roll in two cases: one if the quad is unbalanced or only two motors tipped forward, and your PIDs are set low for a aerial photography, and second if your board isn't placed dead center on the frame. Then I have one big question myself, why do I have 127 as a mix when I understand it should be a maximum of 100 per cent? am I crazy on that one?
Title: Re: Using custom mixes
Post by: 12many on April 05, 2016, 09:05:02 am
...
A problem is that simple measuring doesn't handle asymmetrically distributed mass (e.g. heavy camera in front and heavy battery in back, but no added mass left-right).
...

Just a random idea, add the concept of moment of inertial (which I think you're referring to), probably in the PID and not the mixer.  To keep it simple probably a simple X to Y ratio would be sufficient for most needs.  It might be a good thing to neutralize this effect (not that it's really causing problems) since most vehicles have, as you say, heavy components mounted mid forward axis but little to nothing on the lateral axis.  Then experimentally find a good (probably fairly low) baseline default.  Just thinking out loud...

Title: Re: Using custom mixes
Post by: 12many on June 13, 2016, 02:14:53 am
    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

I just wanted to mention that the python script referenced on the paparazziuav page is scaled to +/-256 bu default but LibrePilot GCS uses +/-127, so people  trying to use the script should replace the mm.print_xml() line with mm.print_xml(scale=127).  Or you can just divide it's output by two.

Also, the easiest way to edit custom mixer settings is:  On the System page go to Settings / SystemSettings and change AirframeType to Custom.  This will enable editing of the mixer table  on the Configuration page.

Anyone, please correct me if you think the above is incorrect.

It took me a little while to figure this stuff out, so I hope this helps...
Title: Re: Using custom mixes
Post by: 12many on June 13, 2016, 03:33:40 am
I expect to be playing around with several new multi-copter frame configurations and am wondering if people might be interested if I added a motor mixing calculator to GCS?

Right now I'm thinking of hanging a new page off of the custom vehicle type page.  It would contain a table where the user could input X,Y,Direction & see entered rotors graphically depicted on the page as well as the calculated yaw, pitch, roll, etc values displayed.  Then allow the user to push the calculated values into the existing custom page's mixing table.   Basically it would be more or less a port of the paparazziuav.org RotorcraftMixing perl script, just tailored to GCS.  Sort of like https://www.iforce2d.net/mixercalc/ but not so funky.

I know such an enhancement isn't exactly a highly requested feature.  Would such a pull request be accepted?  If no, that's OK, but I'd probably not bother unless you guys think it might help others.
Title: Re: Using custom mixes
Post by: TheOtherCliff on June 25, 2016, 07:24:24 pm
I think it sounds like a good idea.

Maybe a "custom multicopter" configuration so the code could be made to know that it is actually a multicopter.  Currently the "custom" configuration does a few things differently than any of the multicopter configurations.

Define the center as the center of mass and it can even handle the different thrust levels required when a multicopter is not perfectly balanced.
Title: Re: Using custom mixes
Post by: 12many on June 25, 2016, 09:55:13 pm
Yeah, I've learned that 'custom mix' is pretty raw and not exactly a great UX, at least not right now.  Which is ok, what I'm doing isn't exactly mainstream.

What I (personally) like about my implementing a 'custom multi' page is that it will be a fairly isolated, seldom-used corner of GCS so my development 'efforts' :-[ won't effect mainstream users while I get up to speed.  I.e. I won't be crashing people's vehicles due to FC bugs.

@TheOtherCliff - side question:  I'm mulling over evaluating a counter-rotating coaxial prop configuration.  From what you know about mixing do you expect any issues with defining two motors at the same XY location but with opposite rotation direction?

Such a custom multi page would also be a good place to experiment with coaxial upper/lower prop throttle bias to find highest efficiency, which is on my to-do list.
Title: Re: Using custom mixes
Post by: TheOtherCliff on June 27, 2016, 09:42:01 pm
The way the mixer handles it, there wouldn't be a problem with it.  The mixer says: given these 4 transmitter controls, what does this particular motor do?

The other side of the question is whether a GUI would have a problem with it.  It could, but it would be simple to handle it.  For instance the GUI could be designed to use "angle and distance from the center".  Angle would be undefined in this case, so it would have to take that into account.

I created a tracking issue to implement this.  Of course it still needs someone who wants to do the work.
Title: Re: Using custom mixes
Post by: 12many on June 27, 2016, 09:54:05 pm
I would really like to contribute to this.  Wish I could devote more time and had more (any) Qt experience.  Not sure I'd be much of a help.  12-2am time slot?  May become a much higher priority in a few weeks depending how things develop.
Title: Re: Using custom mixes
Post by: MrKitty on August 10, 2016, 11:00:50 pm
How do i put this info into Libre Pilot so my quad will fly like a sports car instead of a school bus

mmix 0 1 -1 0.778 -1
mmix 1 1 -1 -0.788 1
mmix 2 1 1 0.778 1
mmix 3 1 1 -0.788 -1
Title: Re: Using custom mixes
Post by: f5soh on August 10, 2016, 11:11:33 pm
For school bus or sport you should take a look at Stabilization tab and adjust Rates.

https://librepilot.atlassian.net/wiki/display/LPDOC/Advanced+tuning