Hi, friends
How to import the position (latitude and longitude) from Mission Planner in python?
Thank you
Hi, friends
How to import the position (latitude and longitude) from Mission Planner in python?
Thank you
Just create a listener for the GLOBAL_POSITION_INT mavlink message:
http://python.dronekit.io/guide/mavlink_messages.html
Can you show me how (and where) do I have to write this in my code?
import sys
import clr
import time
import math
import MissionPlanner #import *
clr.AddReference(“MissionPlanner.Utilities”) # includes the Utilities class
print 'Starting Mission’
Script.ChangeMode(“Guided”) # changes mode to "Guided"
print 'Guided Mode’
item = MissionPlanner.Utilities.Locationwp() # creating waypoint
lat1=-3.780854
lon1=-38.541491
lat2=-3.779830
lon2=-38.541590 # Longitude value
alt = 100 # altitude value
dla=(lat1-lat2)601852
dlo=(lon1-lon2)601852
dist=math.sqrt(dla2+dlo2)
MissionPlanner.Utilities.Locationwp.lat.SetValue(item,lat2) # sets latitude
MissionPlanner.Utilities.Locationwp.lng.SetValue(item,lon2) # sets longitude
MissionPlanner.Utilities.Locationwp.alt.SetValue(item,alt) # sets altitude
MAV.setGuidedModeWP(item) # tells UAV “go to” the set lat/long @ alt
print ‘Going to Point 1’
Take a look at http://ardupilot.org/planner/docs/using-python-scripts-in-mission-planner.html
Longitude and latitude are stored at Class Name: CurrentState.cs Python Variable: cs. You can access them via cs.lng and cs.lat.
Example:
print 'Start Script'
import clr
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
from System.Windows.Forms import Application, Form
from System.Windows.Forms import ComboBox, Label, Button
from System.Drawing import Size, Point
from MissionPlanner import MAVLinkInterface
class IForm(Form):
def __init__(self):
self.Text = "Script Check"
self.Size = Size(240, 240)
self.button1 = Button()
self.button1.Text = 'Press Me'
self.button1.Location = Point(25, 125)
self.button1.Click += self.update
self.Controls.Add(self.button1)
def update(self, sender, event):
print "button clicked\ncurrent position lat, lng: %.2f , %.2f" % (cs.lat, cs.lng)
Application.Run(IForm())