Hi,

I'm trying to add a waypoint using the APM built in python script option. I've tried to send Mavlink commands, with no success so far.

Can anybody share his/hers python code(mavlink commands) for adding/changing waypoints?

Haven't been able to find a code that actually works(I looked everywhere).

Thanx in advance

Views: 1778

Reply to This

Replies to This Discussion

I'm trying to do this as well... if you figure out how, please share! I'll be sure to do the same.

Thanx, no problem.

So, based on my perusing of code, I've pieced together the script below, but I don't have a way to test it... do you have a Hardware-In-the-Loop (HIL) setup you can test it in to see if it works?

think that just you copy & paste the following script into a text document, save it as "testscript.py" (in a location you can find once in Mission Planner), then once you have your HIL + Mission Planner up & running & you connect to your auto-pilot, go to the "Scripts" tab in the "Flight Data" main window, choose "Select Script" and navigate to the script you saved ("testscript.py"). All this script should do is set the next waypoint, then go to it, wait 30 seconds, repeat 3 more times (to 4 different points)...

import sys
import time
import clr
from ArdupilotMega import *
print 'Starting Mission'
item = Locationwp()
Script.ChangeMode(auto)
Locationwp.lat.SetValue(item,39.343674)
Locationwp.lng.SetValue(item,-86.029741)
Locationwp.alt.SetValue(item,45.720000)
MAV.setGuidedModeWP(item)
sleep(30)
Locationwp.lat.SetValue(item,39.345358)
Locationwp.lng.SetValue(item,-86.029054)
Locationwp.alt.SetValue(item,76.199999)
MAV.setGuidedModeWP(item)
sleep(30)
Locationwp.lat.SetValue(item,39.342106)
Locationwp.lng.SetValue(item,-86.031371)
Locationwp.alt.SetValue(item,53.340000)
MAV.setGuidedModeWP(item)
sleep(30)
Locationwp.lat.SetValue(item,39.343540)
Locationwp.lng.SetValue(item,-86.028732)
Locationwp.alt.SetValue(item,76.199999)
MAV.setGuidedModeWP(item)
sleep(30)
Script.ChangeMode(rtl)

Let me know if this works!

[Note: The reason I don't have a way to test it is because (1) I don't have an airframe, just an APM 2.5 & 3DR radios for lab testing & (2) I cannot get a HIL or SITL with simulator to work on this system]

I have an airframe to test this on. 

However, I tried to upload a new waypoint using ur code and I got this error:

" Error running script. No module named ArdupilotMega "

Does this have to do with establishing a heartbeat? 

No, I think it's just an incorrectly identified class... I'm not at my system right now, but I'll take a look when I go to it and see if I can correct that. I pulled that part of the script from the post by the original developer of Mission Planner, Michael Oborne. It's possible that either (a) this functionality hasn't been implemented yet, or (b) the class was just misidentified in his post (which is what I will examine later)

Here's a script that doesn't give me any errors on setting waypoints, but I do get an error at the end when trying to change the mode to "RTL" (still working on resolving that issue):

import sys
import clr
import time
import MissionPlanner #import *
clr.AddReference("MissionPlanner.Utilities") # from MissionPlanner.Utilities import *
print 'Starting Mission'
item = MissionPlanner.Utilities.Locationwp() # item = Utilities.Locationwp()
lat = 39.343674
lng = -86.029741
alt = 45.720000
MissionPlanner.Utilities.Locationwp.lat.SetValue(item,lat)
MissionPlanner.Utilities.Locationwp.lng.SetValue(item,lng)
MissionPlanner.Utilities.Locationwp.alt.SetValue(item,alt)
print 'WP 1 set'
MAV.setGuidedModeWP(item)
print 'Going to WP 1'
time.sleep(15)
print 'Ready for next WP'
lat = 39.345358
lng = -86.029054
alt = 76.199999
MissionPlanner.Utilities.Locationwp.lat.SetValue(item,lat)
MissionPlanner.Utilities.Locationwp.lng.SetValue(item,lng)
MissionPlanner.Utilities.Locationwp.alt.SetValue(item,alt)
print 'WP 2 set'
MAV.setGuidedModeWP(item)
print 'Going to WP 2'
time.sleep(15)
print 'Ready for next WP'
lat = 39.342106
lng = -86.031371
alt = 53.340000
MissionPlanner.Utilities.Locationwp.lat.SetValue(item,lat)
MissionPlanner.Utilities.Locationwp.lng.SetValue(item,lng)
MissionPlanner.Utilities.Locationwp.alt.SetValue(item,alt)
print 'WP 3 set'
MAV.setGuidedModeWP(item)
print 'Going to WP 3'
time.sleep(15)
print 'Ready for next WP'
lat = 39.343540
lng = -86.028732
alt = 53.199999
MissionPlanner.Utilities.Locationwp.lat.SetValue(item,lat)
MissionPlanner.Utilities.Locationwp.lng.SetValue(item,lng)
MissionPlanner.Utilities.Locationwp.alt.SetValue(item,alt)
print 'WP 4 set'
MAV.setGuidedModeWP(item)
print 'Going to WP 4'
time.sleep(15)
print 'Mission Complete'
MAV.setMode(RETURN_TO_LAUNCH)
#Script.ChangeMode(RETURN_TO_LAUNCH)
print 'Returning to Launch'

I posted my fully working script here. Hope it helps you!

Reply to Discussion

RSS

Groups

Season Two of the Trust Time Trial (T3) Contest 
A list of all T3 contests is here. The current round, the Vertical Horizontal one, is here

© 2017   Created by Chris Anderson.   Powered by

Badges  |  Report an Issue  |  Terms of Service