A building block on my journey to a full-on, hardware-in-the-loop flight simulator was a simple software-in-the-loop flight simulator.
While there is passable documentation over here, I found that much of the documentation was outdated and lacked important notes.
After you have configured everything following the steps below, you can open two Cygwin windows and run the following commands to quickly start SITL.
Plane Guide Both windows:
cd /your-ardupilot-directory
FlightGear window:
cd Tools/autotest
fg_plane_view.bat
ArduPlane window:
sim_vehicle.py --console --out YOUR_IP_ADDRESS:14550 -L MEX -v ArduPlane
Start Mission Planner. Find the automatic connection.
You must install MAVProxy to be able to use these services. Go here for a full installation guide. If on Windows, go here for the executable.
You must set up Cygwin with the packages recommended by the ArduPilot Documentation.
ln -s /cygdrive/c /c
adds a new alias to your Cygwin directory.
/dardu
is /docs/delia/ardupilot
.
sim_vehicle.py
automatically builds with Waf. You do not need to run this step.
Waf is the tool used to build your build of Ardupilot. More information can be found on GitHub.
Before using Waf to configure with the Pixhawk2, I needed to install the GCC compiler as described here. Make sure to add to path and restart Cygqin afterwards.
./waf configure --board CubeBlack
configures the build for a particular board; in this case, the Pixhawk2. To get a full list of boards, run ./waf list
.
./waf copter
will build for a specific airframe. At first, I chose to use copter because it was easier to land and take off and I just wanted to get something working.
To run the simulator, I had to add ardupilot/Tools/autotest
to my path so it could be searched. For more information on how to add a directory to your path in Windows, look here.
Then, to run the simulator, I had to first change the directory to the version of ardupilot I wanted to run: ArduPlane, ArduCopter, etc.
Then, all I had to do was run sim_vehicle.py --map --console
. This opened three windows: first, the map of the flying drone.
Then, I could get my copter flying! In Mavlink, some key commands for the copter are:
mode guided
arm throttle
takeoff 40
At this point, I have noticed that changing the mode to loiter
or circle
both caused the autopilot to lose altitude dramatically. Hover throttle was 34
, but the throttle was consistently set to 29
, which was low enough to cause a crash.
One fix I saw on the Internet was to rc 3 1500
, which sets the throttle to be mimicked from the pilot, but this doesn't seem like a long-term fix and more like a short-term workaround. Work still needs to be done to get a plane flying, but I wanted to integrate with FlightGear to see what my challenges with that respect would be before moving on.
Connecting to FlightGear turned out to be fairly simple; I just had to enable the automatic download of terrain in order to get scenery and textures for the airports.
- Open new command prompt and run the batch file in
/ardupilot/Tools/autotest/fg_plane_view.bat
for a plane or/ardupilot/Tools/autotest/fg_quad_view.bat
for a quadcopter (Note: you will have to change into the appropriate directory before running this script). - Start SITL from Cygwin but specifying a default location as follows:
sim_vehicle.py -L KSFO
.
MavLink is nice, but it doesn't really allow custom missions.
I found a reference online that suggested you could connect to Mission Planner by specifying an 'out' port in the sim_vehicle
script. This follows the format of -- out IP:14550
. To find your IP, simply type ipconfig
in Cygwin on Windows.
Adding New Locations
The first thing that I did was change the default location of FlightGear in the bash script. To do so, I opened the file ardupilot/Tools/autotest/fg_plane_view.bat
and added a few options:
--lat=20.819083 ^
--long=-100.414276 ^
--altitude=2023 ^
I then changed the locations.txt
file, adding this line:
MEX=20.819083,-100.414276,2023,360
Now, FlightGear Plane View defaults to the test location in Mexico.
To run Mavlink at this location, simply enter the command
sim_vehicle.py --console --out IP:14550 -L MEX
.