SIM Development update - Now in 3D

3689466202?profile=originalThis is a quick update for the Arducopter SIM and 2.6.1 development:


There is quite a bit of development going on right now, but I thought I'd share what I'm working on. I'm using Flash to implement a simulator and test Arducopter code. What's on my site at is on the current Trunk. 

What isn't there is a whole lot of other work including Tridge's DCM core updates and Andreas' APM_limits code which is a geo-fencing library. 


You'll notice the sim has been updated to work in 3D now, so you can fly full missions, Yaw and Loiter in 3D. An orange line now indicates nav_yaw which is the yaw hold angle. A black circle indicates the GPS positions and the red box is the next waypoint location.


A new crosstrack algorithm:

Based on our flights in high winds at the Copter Rodeo, I set out to improve our crosstrack error correction. We had previously been using Arduplanes' track correction which turns the plane into the error to correct it. Of course copters can fly sideways and don't need to give up forward momentum to track correctly. The new algorithm solves this and acts very similar to the loiter control. Crosstrack gain will be lowered to a default of .2 because of new approach.


GPS lead filter:

Another idea from the rodeo, the lead filter takes into account the velocity and acceleration of the copter and the latency of the GPS to guess where the copter really is, not just where it was 1 second ago. This helps Loiter somewhat, but where it really shines is the Waypoint and RTL navigation. When you hit the WP it acts immediately, and not 1 second later which helps reduce overshoot.


Altitude hedging:

Phillip Jones suggested prioritizing the altitude over navigation when fighting wind to prevent the quad from loosing altitude during a hard pitch. This keeps the quad from hitting the ground during WP flight. Anything greater than a 1m error begins to level out nav_pitch to gain altitude. Still a WIP and not on the trunk yet.



RTL_altitude is now implemented. This will cause the copter to rise to the desired altitude in Loiter before heading home. The parameter rtl_approach_alt will change how the copter will land after RTL or a mission that doesn't end in a land command. Basically setting this param to 0 will cause a land, setting this to any other number will cause the copter to go to that altitude after RTLing. The param auto_land_timeout is used to trigger this altitude change. The RTL Approach altitude parameter is great for bringing the copter down without worrying about touching the ground.


Alternate Yaw control:

A new control method for Yaw goes back to the hybrid rate/stabilzie approach, but uses a timer to lock in the hold angle. This allows the rate controller to brake the Yaw and then set the new hold angle without much overshoot and dreaded snapback.


Better Yaw gains:

Testing the SIM with an out of alignment motor allowed me to test various I term settings. An iterm of .02 for BOTH Rate and Stabilize Yaw works best.


Discovered Yaw Bias issue:

While running missions in the sim I realized the copter would run off track while Yawing to the target. Turns out we change and update Yaw continuously, but the copter's nav_roll and nav_pitch is only updated 4x with GPS reads. This causes the copter to be pitching at at angle to the target instead of towards the target when Yawing. The nav_roll and nav_pitch are now updated at 50 hz instead of 4 which get's rid of most of the issues.


Self centering throttle:

This is very experimental, and probably won't be enabled by default. The throttle cruise value is calculated at all times, and the lower limit of throttle is raised to place that cruise value right at mid stick. 


Drag/velocity estimation:

Takes the desired velocity and outputs a pitch and roll that should match the drag of the copter. This lets the I-terms deal with just the wind and not the wind + drag combined. It also helps the track accuracy by about 30%.


Alt Hold:

"Angle boost" a more accurate algorithm in 2.6, but we found it didn't account for the inefficiency of the thrust pattern. A small correction has been added to account for this.


Throttle min and max 

Implemented the params for throttle min and max so you can change them from the MP.


What's new with the SIM:

Added new top view

Added 3D physics

Added the ability to run the SIM at up to 10x speed for running variations

Added a Score for integrating crosstrack error to use for gradient descent (machine learning)

Added a new joystick controller class that acts like a real radio, or allows user to adjust 1 axis only.

Added 2D wind

Added Yaw Gains

Added iteration # limit to stop the sim after N number of 100hz main loops.


What's next in the SIM:

Mission editor


If you are testing the trunk, please check the SIM and see if you can reproduce bugs. If not, please note that in bug reports.


Code is here:

Flash FLA project file available by request.




Video from WIP last week.






E-mail me when people leave their comments –

You need to be a member of diydrones to add comments!

Join diydrones


  • I have seen guys doing all kinds of 'aerobatics' using their thumbs...flip loops etc

    They kind of fly them more like an airplane.....

    I would also like to have very responsive manual control for some FUN and safety(). ..




  • Developer

    I think you may have it backwards... I would have never attempted a flip on my own. Now, maybe I will!

    Can you get a video of it in action?


  • Developer

    Awesome Jason, but I think initially we should be able to do aerobatics with the thumbs, this can save the quad in some bad situation........ :-)

  • Developer

    I just updated the SIM to reflect work to date on 2.7 which is about to be released as Beta. I've been almost exclusively working in the SIM, then porting that code Arducopter and have been able to replicate behavior in the air almost perfectly. This has allowed me to do a lot of development that I just couldn't do before and in a fraction of the time. 

    Yesterday I tested the new Flip code developed and flown in the SIM. To my surprise it worked, just a it does in SW. This will be my favorite new feature of 2.7!

    After this we're going to have a bunch of scriptable acrobatics.

  • Developer

    This is a custom sim, but it's very similar to I hope to move some of what I've done back to the Python sim later this month.

    The altitude code has the efficiency boost that the SIM doesn't need. I need to update that to reduce the SIM's output or disable the boost. Will do that today.


  • Incredible work Jason. I can help out if needed as3 side (optims/iPad port), although you do seem quite fine so far.

    This sim is invaluable as it saves so much dev time compared to the previous classic implement-trial&error with copter-correction cycle; arducopter gets a huge boost thanks to you.

  • Thanks for the great work!
  • 3D Robotics

    Incredible work! Just a reminder to users: if you like this, don't forget to donate to its development fund

    ArduCopter SIM
  • Developer

    This is simply amazing work Jason. 

    Does it use SITL in the background? Does it use or are you running your own physics sim?

  • Moderator

    Thanks for all your hard work!  Hope that 3DR are rewarding you in some way for all your efforts!

    About the sim, I was just testing it out.  I only changed some of the wind settings, all other settings are default.  However when this is done the copter holds its position, but constantly gains altitude.  Is this a bug with arducopter code, or just something wierd with the sim?  Just thought I should let you know!  But I dont know if I will ever be flying in 14km/h winds.

    Below is the parameters I changed.



    The above graph plots WP distance, and altitude which seems to constantly grow.


This reply was deleted.