-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Welcome to the DronologyCourse wiki!
If you haven't already done so: git clone -b dronekit_gettingstarted https://github.com/SAREC-Lab/DronologyCourse.git
Visualizing Drone movements on map
Step 1: Add dependencies to run a web server. - This is only required once. ONLY needed if you are running on your own computer. Otherwise it is installed for you.
pip install simple_websocket_server
pip install websocket
pip install websocket-client
We are using this python package to create a light-weight server. The drones will broadcast their location to this server and the client (html) will listen it to update the location of markers on the map.
Before running any of the python files, please run the server. go to the root directory (gettingstarted) in a terminal and run python server.py . Do not close or write anything new in this terminal.
Step 2 : Run your drone-kit script in a separate terminal where one or more drones are flying.
Ex: python simple_goto.py
This simple_goto.py has been modified and will work as-is.
Please refer to multiple_drones1.py file to check how each drone/vehicle send their latitude and longitude to the server.
connect to the server through a websocket on port 8000
from websocket import create_connection
ws = create_connection("ws://localhost:8000")
import drone_model - this is the object that is passed over the socket.
from drone_model import Drone_Model
Create instance of the model/object while vehicle starts connecting to the autopilot
data_model = Drone_Model(instance+1,home[0],home[1])
Make sure that the first argument (drone_id for client) starts from 1.
Finally, sending data/object over the socket. Call the below function while the drone is flying and the python code is waiting for it to reach a waypoint. you can write similar fucntion based on your need and your logic to fly drones.
def custom_sleep(vehicle,drone_model, sleep_time): current_time = 0 while(current_time<sleep_time): drone_model.update_status(vehicle.location.global_relative_frame.lat, vehicle.location.global_relative_frame.lon) ws.send(drone_model.toJSON()) time.sleep(1) current_time+=1
Step 3 : Go to the webApp folder in the project directory and open map.html file in a browser.
Things to remember:
-
Line3 map.js
number_drones = 1 (Replace it with the number of drones you are flying in step 2) -
Line 8 - 13
var myLatLng = new google.maps.LatLng( 41.714469, -86.241786 ) myOptions = { zoom: 4, center: myLatLng, mapTypeId: google.maps.MapTypeId.ROADMAP }
Make changes to manipulate the properties of the map such as center of the map, zoom level - increase value to zoom deeper.
In the above code, 41.714469, -86.241786 coordinate is the center of the map and zoom level is 17.