How to python script a time-based flight plan

Based on what I've discovered so far in my search for an answer (most pertinently here & here), it appears the only commands that can be scripted in python for Mission Planner to execute are: 

  • Script.ChangeParam(name, value)
  • Script.GetParam(name)
  • Script.ChangeMode(name)                   # i.e., mode = RTL
  • Script.WaitFor(string, timeout)              # unsure what this command does
  • Script.RC(channel, PWM, sendnow)     # automates emulated RC transmissions?

However, MAVProxy is written & executed in python and can accomplish a whole lot more... Also, if I understand correctly, during execution of an established flight plan, Mission Planner automates sending the next command to the UAV based on the telemetry received... (i.e., Mission Planner sends the next command in the established flight plan after the telemetry received indicates the UAV has completed the current command, e.g., it doesn't tell the UAV to go to waypoint 2 until it has reached waypoint 1).

So, my question is:

Is there a way to script a flight plan in Python that executes commands based on TIME instead of telemetry???

 

[i.e., What are the python scripting commands/functions to command the UAV "go to waypoint 1, sleep(30), go to waypoint 2, sleep(30), LOITER, sleep(30), go to waypoint 4, toggle servo 8, RTL" without caring if the UAV actually ever made it to the waypoint before following the next command]

(based on the comment from Mission Planner's creator here, I would think this is possible, but I need a list of all possible commands to send with the corresponding Python syntax.)

You need to be a member of diydrones to add comments!

Join diydrones

Email me when people reply –

Replies

  • Sir, can you share the scripts  for throttle raise, stabilizing, roll, pitch, yaw, land and disarm?

    you can contact me on my email id

    rijunk1995@gmail.com

    i'm doing my project on pixhawk and i need help  to land my arduplane automatically.

    VENKAT RAVI KISHORE said:

    Today I tested it and got the positive result. I mounted APM2.5 on a quad-copter and I connected it with Mission Planner via telemetry link. Before flying I developed codes for Arming motors, throttle raise, stabilizing, roll, pitch, yaw, land and disarm. I successfully run all those developed scripts of python and I completed preliminary tests. My next target is to test it for RTL, loiter, Guided modes.

    Thanks for your great support.

  • I have made progress on my project learning from your script.  Thanks.

    My challenge now is to over fly the waypoint without going into loiter or to begin loiter on the far side of the loiter radius allowing at least an initial overflight of the waypoint.

    Any ideas.

  • Today I tested it and got the positive result. I mounted APM2.5 on a quad-copter and I connected it with Mission Planner via telemetry link. Before flying I developed codes for Arming motors, throttle raise, stabilizing, roll, pitch, yaw, land and disarm. I successfully run all those developed scripts of python and I completed preliminary tests. My next target is to test it for RTL, loiter, Guided modes.

    Thanks for your great support.

    • Hi all,

      Does anyone know if it is possible to upload a whole mission through python (multiple waypoints). I was trying to use the code bellow to add multiple waypoints and do a AUTO mission. However it does not work.

      Relative = MAV.MAV_FRAME.GLOBAL_RELATIVE_ALT

      item = MissionPlanner.Utilities.Locationwp() # creating waypoint

      MissionPlanner.Utilities.Locationwp.lat.SetValue(item,lat) # sets latitude

      MissionPlanner.Utilities.Locationwp.lng.SetValue(item,lng) # sets longitude

      MissionPlanner.Utilities.Locationwp.alt.SetValue(item,alt) # sets altitude

      MAV.setWP(item, 2, Relative, 0) #add waypoint

      Script.ChangeMode("Auto") #Change mode to AUTO

      Thanks for the help,

      Sebastian

      • Hey, I'm trying to do the same thing. Have you gotten it to work?

  • I, thanks.

    After a few weeks working on an other project, I'm back to this project. But I've a problem, I can't run any python script anymore. As I try to run on of my script, which was working a few weeks ago, apm just freeze. Have you ever heard a problem like that ? I see only one modification between now and late january : I've updated apm.

    • Actually I've dowloaded an old version of Mission Planner and my scripts work with it, so I guess a changed in the last version has caused the freeze.

  • Nevermind... thanks to JakobSt, I developed a working time-based script.

    Here's the script that worked for me in using ArduPlane (which should work for ArduCopter too):

    import sys
    import clr
    import time
    import MissionPlanner #import *
    clr.AddReference("MissionPlanner.Utilities") # includes the Utilities class
    time.sleep(10)                                             # wait 10 seconds before starting
    print 'Starting Mission'
    Script.ChangeMode("Guided")                     # changes mode to "Guided"
    print 'Guided Mode'
    item = MissionPlanner.Utilities.Locationwp() # creating waypoint
    lat = 39.343674                                           # Latitude value
    lng = -86.029741                                         # Longitude value
    alt = 45.720000                                           # altitude value
    MissionPlanner.Utilities.Locationwp.lat.SetValue(item,lat)     # sets latitude
    MissionPlanner.Utilities.Locationwp.lng.SetValue(item,lng)   # sets longitude
    MissionPlanner.Utilities.Locationwp.alt.SetValue(item,alt)     # sets altitude
    print 'WP 1 set'
    MAV.setGuidedModeWP(item)                                    # tells UAV "go to" the set lat/long @ alt
    print 'Going to WP 1'
    time.sleep(10)                                                            # wait 10 seconds
    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(10)
    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(10)
    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(10)
    print 'Mission Complete'
    #MAV.setMode(RETURN_TO_LAUNCH)
    Script.ChangeMode("RTL")                                      # Return to Launch point
    print 'Returning to Launch'
    time.sleep(10)
    Script.ChangeMode("LOITER")                                # switch to "LOITER" mode
    print 'LOITERING'

    Note: this is a TIME-based script... it will guide the UAV to the next waypoint after waiting a specified amount of time. One would have to replace the "time.sleep(10)" lines with "Script.WaitFor('ARMING MOTORS',30000)" [and replace 'ARMING MOTORS' with whatever notification Mission Planner usually provides upon arriving to a waypoint] to replicate the mission plan creation (i.e., go to next waypoint after arriving at previous waypoint).

This reply was deleted.

Activity

DIY Robocars via Twitter
yesterday
DIY Robocars via Twitter
RT @_JonMyer: 🚨Attention DeepRacer's including #UndergroundDeepRacer🚨 Check our our LIVE stream that including @IAM_dbro Take a few moments…
Aug 5
DIY Drones via Twitter
RT @MarvelmindMaxim: Extreme precision for 60 swarming robots. #marvelmind #autonomousrobotics #robotics #swarmrobotics #rtls #ips #indoor…
Aug 3
DIY Drones via Twitter
RT @MarvelmindMaxim: Precise (±2cm) tracking for racing boats and autonomous boats. Works outdoor and indoor. #autonomous #AutonomousVehic…
Aug 3
DIY Drones via Twitter
RT @MarvelmindMaxim: Helping PixHawk folks to fly autonomous quadcopters using PX4 and ArduPilot. https://marvelmind.com/drones/ Equally suitab…
Aug 3
DIY Robocars via Twitter
RT @chr1sa: The @DIYRobocars @donkey_car virtual AI car race is starting in 15 minutes! Watch it live on Twitch https://www.twitch.tv/mossmann3333 htt…
Aug 1
DIY Robocars via Twitter
RT @chr1sa: Don't miss our monthly @DIYRobocars @donkey_car virtual AI car race tomorrow at 10:00am PT live on Twitch. Head-to-head racing…
Jul 31
DIY Robocars via Twitter
RT @sparkfun: Our completed tutorial on building an @NVIDIA Jetson Nano-powered @Sphero RVR gets your bot up and running via teleoperation…
Jul 30
DIY Robocars via Twitter
RT @SmallpixelCar: Freeway test https://t.co/4V5tV9lhIP
Jul 29
DIY Robocars via Twitter
Very small autonomous cars racing, thanks to an overhead camera: https://control.ee.ethz.ch/research/team-projects/autonomous-rc-car-racing.html
Jul 29
DIY Robocars via Twitter
Jul 29
DIY Robocars via Twitter
Jul 29
DIY Robocars via Twitter
RT @chr1sa: Don't miss our virtual AI car race this Saturday! Real developers + virtual cars =🏎️🏎️🏎️ Head-to-head battles with thrills, sp…
Jul 28
DIY Robocars via Twitter
Jul 27
DIY Robocars via Twitter
RT @usashirou1: Jetson nano by Isaac Kaya #jetson https://t.co/Mu1N0CyQkN
Jul 23
DIY Robocars via Twitter
RT @GPUsolution: JetRacer mady by Iflytek company #JetsonNANO #Nvidia https://t.co/MimTymIwge
Jul 23
More…