I'm pushing vizzy farther than I probably should by making a quadcopter flight controller. Every section of the program works in isolation, but with everything running at the same time the process takes too long to update, causing instability. I know the issue is because of update rate, because running the linked craft in slow-motion shows perfect stability.

I've already broken it up into multiple threads, but that made minimal difference compared to the version with one giant while() loop. How can I get Vizzy to run faster without just removing parts of it?

Tags
Vizzy

12 Comments

  • Log in to leave a comment
  • Profile image
    2,542 zzazza

    If you are on PC, install the Overload mod. Then, move your program into other part other than command pod/chip (cuz Overload can't save the xml of command pod/chip). Then click the part you put program in, click the "EDIT XML" button on the top of the menu. In "FlightProgram" section, you should find a property called "maxInstructionsPerFrame", change it to a larger number and your program should run faster.


    edit:
    Thanks for pinning my answer! If you are on mobile, you need to add this "maxInstructionsPerFrame" property to your craft's XML manually. Find the part's XML where you store your program (part id may help you find), then write maxInstructionsPerFrame="the number you want it to be" after FlightProgram.
    Like this: <FlightProgram maxInstructionsPerFrame="30">

    Pinned 4.3 years ago
  • Profile image
    2,966 LofiTurtle

    @CodeCaptain It opens an in-game screen to edit xml values

    4.3 years ago
  • Profile image
    Mod sflanker

    @Shmexysmpilot That's correct. A wait 0 will wait just until the next frame (how long that is will depend on settings and CPU).

    4.3 years ago
  • Profile image
    2,966 LofiTurtle

    @sflanker Pinned! Forgot I could do that. And that's interesting, so any wait for [x] seconds will wait until at least the next frame before continuing?

    4.3 years ago
  • Profile image
    Mod sflanker

    @Shmexysmpilot I suggest you pin the answer from zzazza which appears to have been the most useful to you, that way it will be easier for others who see this thread to find the answer.

    4.3 years ago
  • Profile image
    Mod sflanker

    A note on loops (even though I realize it is not relevant for you @Shmexysmpilot). I would use stronger wording than @CodeCaptain did below: every loop (that isn't doing iterative math*) should have at least a wait for [0] seconds. The reason is this: let's say you have a loop for a gravity turn that computes a formula for pitch based on altitude and sets craft pitch. Without a wait for [0] seconds such a loop will run multiple iterations during a single frame, and within the same frame altitude will not change and therefore the value for pitch will not change, and you will have simply recomputed the exact same value for pitch several times for no reason.


    * The only reason to run multiple iterations within the same frame is if you are not calculating something directly from some game state value, but instead doing some iterative math (a.k.a. numeric methods) to solve equations with no closed form solution, such as finding Eccentric or True Anomaly from the Mean Anomaly, or dealing with some complicated differential equations.

    +2 4.3 years ago
  • Profile image
    2,966 LofiTurtle

    @CodeCaptain no problem! I'm learning things too.

    4.3 years ago
  • Profile image
    2,966 LofiTurtle

    @CodeCaptain Its a setting in the XML, so it'll work that way for everyone. It's a property on the part that is running the program

    4.3 years ago
  • Profile image
    2,966 LofiTurtle

    @CodeCaptain I had already taken the program down to it's bare essentials. There were 4 controllers, 1 for each axis (plus throttle), so any less would mean no stabilization. Thankfully, the tip below about maxInstructionsPerFrame did the trick

    4.3 years ago
  • Profile image
    2,542 zzazza

    @Shmexysmpilot No problem :)

    4.3 years ago
  • Profile image
    2,966 LofiTurtle

    @zzazza THANK YOU! That was exactly what I needed :)

    4.3 years ago
  • Profile image
    2,966 LofiTurtle

    @zzazza thanks! I am on pc, I'll give that a shot

    4.3 years ago

7 Upvotes

Log in in to upvote this post.