Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use dronekit with SITL vagrant VM from dev Wiki

I am following the getting started instructions in DroneKit-Python to set up DroneKit in a VM. To make things easier for myself I started by Setting up SITL using Vagrant. However I can't work out how to have SITL running and talk to it from the example scripts.

What I did:

  1. Ran SITL vagrant script and got SITL working (tested connection to Mission Planner running on Windows).
  2. Tested it as discussed in "Setting up on Linux" by doing:

    param load ../Tools/autotest/copter_params.parm

    param set ARMING_CHECK 0

NOTE - not "STABILIZE>" prompt visible in my MAVProxy prompt. These ran (what appeared to be) successfully

  1. Then I did Ctrl+D to exit the SITL simulation, and vagrant ssh to open my prompt to the virtual machine.
  2. I installed the dependencies as described here (after fixing up the pip specification):

    sudo apt-get install python-pip python-numpy python-opencv python-serial python-pyparsing python-wxgtk2.8

Then MAVProxy

sudo pip install MAVProxy

Then droneapi (note, had to be installed using "sudo")

sudo pip install droneapi

Then from command prompt (vagrant@vagrant-ubuntu-trusty-32:/vagrant/ArduCopter$) I got the git clone and navigated to the demo:

git clone http://github.com/diydrones/droneapi-python.git
cd droneapi-python/example/small_demo

I started MavProxy using "mavproxy.py" (correct type for Linux VM communicating by USB). Got the following:

Auto-detected serial ports are:
/dev/ttyS31
/dev/ttyS30
...
/dev/ttyS1
/dev/ttyS0
Logging to mav.tlog
libdc1394 error: Failed to initialize libdc1394

Finally, despite error above I tried to load and use the module.

MAV> module load droneapi.module.api
MAV> DroneAPI loaded
Loaded module droneapi.module.api
api start small_demo.py
MAV> Exception in APIThread-0:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/droneapi/module/api.py", line 322, in run
self.fn()
File "/usr/local/lib/python2.7/dist-packages/droneapi/module/api.py", line 593, in <lambda>
APIThread(self, lambda: execfile(args[1], g), args[1])
...

NOTE "MAV>" prompt not "MANUAL>" as listed in the docs.

The question is "why has this failed, and what do I need to get it to work?" I am guessing the problem is that SITL is not actually running.

Thanks!

like image 671
Hamish Willee Avatar asked Apr 01 '15 09:04

Hamish Willee


People also ask

How to connect Mission Planner to SITL?

In Mission Planner connect to SITL by selecting TCP and then the Connect button. Enter the remote host and remote Port of the machine running SITL. Mission Planner will then connect and can be used just as before.

What is DroneKit SITL?

DroneKit-SITL is the simplest, fastest and easiest way to run SITL on Windows, Linux (x86 architecture only), or Mac OS X. It is installed from Python's pip tool on all platforms, and works by downloading and running pre-built vehicle binaries that are appropriate for the host operating system.


1 Answers

Starting from a fresh checkout of the ardupilot code, in your host OS.

droneapi-python will get installed, but lets get the sample scripts:

ardupilot$ git clone http://github.com/diydrones/droneapi-python.git

Bring up the vagrant box:

ardupilot$ vagrant up

Start the SITL as described in "Setting up SITL using Vagrant":

ardupilot$ vagrant ssh -c "sim_vehicle.sh -j 2"

There will be a lot of output, but at the end I see this:

+ mavproxy.py --master tcp:127.0.0.1:5760 --sitl 127.0.0.1:5501 --out 10.0.2.2:14550 --out 127.0.0.1:14550 --out 127.0.0.1:14551 --cmd=
Connect tcp:127.0.0.1:5760 source_system=255
Logging to mav.tlog
libdc1394 error: Failed to initialize libdc1394
MAV> 

Init APM:Copter V3.3-dev (e1be8148)
Free RAM: 4096
FW Ver: 120
----------------------------------------

Firmware change: erasing EEPROM...
done.
0 0 0 online system 1
STABILIZE> Mode STABILIZE
APM: APM:Copter V3.3-dev (e1be8148)
APM: Frame: QUAD
APM: Calibrating barometer
APM: Initialising APM...
APM: barometer calibration complete
APM: GROUND START
Init Gyro**
INS
----------------------------------------
G_off: 0.00, 0.00, 0.00
A_off: 0.00, 0.00, 0.00
A_scale: 1.00, 1.00, 1.00

Ready to FLY  ublox Received 473 parameters
fence breach
GPS lock at 0 meters
APM: PreArm: RC not calibrated

Load the droneapi module. See "Loading DroneKit" for information on how to do this automatically when mavproxy starts.

STABILIZE> module load droneapi.module.api
STABILIZE> DroneAPI loaded

Run the DroneKit small_demo.py script:

STABILIZE> api start ../droneapi-python/example/small_demo/small_demo.py 

Output:

STABILIZE> Mode: VehicleMode:STABILIZE
Location: Location:lat=-35.3632609,lon=149.1652299,alt=-0.280000001192,is_relative=False
Attitude: Attitude:pitch=-0.0046319803223,yaw=-0.571676075459,roll=-0.00480426847935
Velocity: [0.11, -0.06, -0.06]
GPS: GPSInfo:fix=3,num_sat=10
Armed: False
groundspeed: 0.0
airspeed: 0.0
Requesting 0 waypoints t=Fri May  1 02:18:50 2015 now=Fri May  1 02:18:50 2015
Home WP: MISSION_ITEM {target_system : 255, target_component : 0, seq : 0, frame : 0, command : 16, current : 0, autocontinue : 1, param1 : 0.0, param2 : 0.0, param3 : 0.0, param4 : 0.0, x : -35.3632621765, y : 149.165237427, z : 584.33001709}
Current dest: 0
Disarming...
Arming...
Overriding a RC channel
Current overrides are: {'1': 900, '4': 1000}
RC readback: {'1': 1500, '3': 1000, '2': 1500, '5': 1800, '4': 1500, '7': 1000, '6': 1000, '8': 1800}
Cancelling override
APIThread-0 exiting...
Got MAVLink msg: COMMAND_ACK {command : 400, result : 0}
APM: PreArm: RC not calibrated
Got MAVLink msg: COMMAND_ACK {command : 400, result : 4}
Got MAVLink msg: COMMAND_ACK {command : 11, result : 0}
AUTO> Mode AUTO
like image 126
John Wiseman Avatar answered Sep 30 '22 16:09

John Wiseman