T3

X-Plane simulator for Lego NXT AutoPilot

Here's a auto pilot simulator for NXT AutoPilot based on Michal B's ArduSim.All you need is Lego NXT, RobotC and bluetooth-abled computer to run this simulator. You don't need any of the sensors NXT AutoPilot requires to be able to fly. Although you can add servo controller if you like. As before this simulator is based on X-Plane simulator.Here's how it basically works:-LegoSim.exe communicates between X-Plane (thorugh UDP) and NXT (through bluetooth).-NXT receives GGA sentence (1hz) and the planes attitude (10hz) from LegoSim and sends back servo positions and the telemetry it received as a double check.-LegoSim saves the co-ordinates it received to a .kml file which you can then open in google earth.-LegoSim sends the servo positions to X-Plane.Which closes the circle, so to speak...You should note when using this simulator that the real AutoPilot updates it's attitude and servo positions at almost 300 hz so you can't use the same PID values for your stabilization when flying for real.To replicate this simulation you need:- X-Plane (set it up as described in THIS blog post BUT USE 49003 as the port you define in the settings!!)-Now pair your NXT with your computers bluetooth and memorize the COM port it uses to connect.-Download LegoSim_v.0.0.zip-You can run the LegoSim already and set the IP to 127.0.0.1 and the port to 49003. Set the COM port to the one that NXT uses with your computer and the baud rate to maximum.-Next you need to download and compile with RobotC (ver. 1.45 or above) the AutoPilot for your NXT: NXT AutoPilot Simulator v.0.0.zip- Now in X-Plane set your loaction to Innsbruck and your aircraft to Cessna.- Finally: Press start in LegoSim and then start the AutoPilot program in NXT (you may need to start the AutoPilot several times before it runs OK due to some bugs in my code). Now just release your breaks in X-Plane by pressing b and the auto pilot will take off. (After you have started the AutoPilot you can also hit the "Google Earth"-button in LegoSim..Here are some screenshots of the simulation:Waiting for NXT AutoPilot to start:

Take off...

In flight:

And finally here's a snap shot of two different fly paths one in perfect conditions and the other in heavy wind/turbulence:

E-mail me when people leave their comments –

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

Join diydrones

Comments

  • T3
    @will, I've abandoned the project since I sold my NXT to afford a tried and true autopilot (Paparazzi v3). There are so many advantages a purpose built ap has over systems like NXT. Besides the code isn't flyable in real world. The simulator flies perfectly but the IMU/AHRS can't handle turns; it doesn't properly compensate centripetal forces. As long as it flew in straight lines it worked fine (i.e. the stabilization worked) but once it started steep turns it didn't stop. Who knows it might've work with proper correction for centripetal acceleration (and maybe one more DOF). Also because the HW can't over sample the sensors often enough (accelerometer is the main problem) and the HW doesn't have filters what so ever, I experiensed some pretty severe problems with vibration and had to overcome those problems by means of installing the sensors in foam with lead plates to make them physically "slower".

    The concept of making a UAV with NXT is exciting, granted, but the fact is that NXT isn't very well suited for such a task.

    And because I don't have my NXT anymore I'm sorry but I'm unable to help you with the programming.
  • Hey could you make one for Microsoft flight simulator please and can it also be connected via usb instead of bluetooth
  • T3
    Here's the new source code of the NXT AutoPilot: NXT AutoPilot v0.2b.zip

    // -Changes in 0.2 BETA:
    // -Fully rewritten IMU and stabilization code.
    // -Altitude control (with PID) given that your GPS module sends GSA.
    // -Moved all the settings into one place for easy configuration.
    //
    // -Support for compass and barometer removed.

    Sami F.
    https://storage.ning.com/topology/rest/1.0/file/get/3691920018?profile=original
  • T3
    Just a clarification: the simulator code for NXT is otherwise identical to the real deal aside from the IMU part so now it all really boils down to the quality of the IMU..
  • T3
    I'm quite confident with the IMU I now have in my NXT AutoPilot.. While my Lego IMU is missing one degree of freedom I'd say that in level flight the IMU data is never off more than 3-4 degrees and even that only momentarily (probably only hundreds of ms).

    The tricky part is when the aircraft turns; I had a nasty bug in my gyro integrator that caused the pitch data to go nuts when the aircraft was turning to steep but, I believe, that I have now fixed that issue and it remains to be seen how accurate the pitch data will prove to be. If I had to quess, I'd say that I'll be able to get the error of the IMU data to be less than 5 degrees in the worst case scenario which is far less than that of the X-Plane simulator when you take the 10hz refresh rate into consideration.

    All in all, I'd say that this baby is ready for the skies..
  • 3D Robotics
    That is awesome on so many levels! How close do you think this is the actual data you'd be getting from the NXT sensors? Aside from the refresh rate,are you more or less testing a flyable autopilot?
This reply was deleted.