I've got a question about Python Scripts in the Mission Planner:
I want to send waypoints to my Arducopter with a Python Script. I already found this page: http://code.google.com/p/arducopter/wiki/Python.
Unfortunately there is no information about how I can send whole waypoints to the quadrocopter.
I would be glad if someone would have an answer!
Is it possible to send AT commands to one of the UART's to get a connected GSM/4G modem to connect to internet ?
Michael Thomas said:
Dear Stefan, do you have the codes for landing?
if you have it , please share it to my mail id email@example.com
Stefan Lane Hardy said:
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.
Hey Venkat, can you share the codes that you developed?
I made my vehicle go into "Guided" mode from my Python script. However, I'm trying to create a safety control in my Python script so if I flip the Radio Control from Auto to Manual, the vehicle will stop running the Python script. As of now, without the safety control, my vehicle just continues to run around continuously until I abort the script.
I tried to input an "if" statement for cs.mode (ex. if cs.mode == "Manual", script.ChangeMode("Manual")). However, it never seems to work. Do you know if the cs.mode only applies to the mode I have written in Python, and has nothing to do with the mode the Radio is switched to? Any ideas on a "switch to Manual" safety control?
Here's my code:
from math import sqrt
import re, string
import MissionPlanner #import *
clr.AddReference("MissionPlanner.Utilities") #includes the Utilities class
from MissionPlanner.Utilities import Locationwp
HOST = 'localhost' # Symbolic name meaning all available interfaces
#SPORT = 5000 # Arbitrary non-privileged port
RPORT = 4000 # Arbitrary non-privileged port
REMOTE = ''
# Datagram (udp) socket
rsock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
print 'Sockets created'
# Bind socket to local host and port
except socket.error, msg:
#print 'Bind failed. Error Code:'
sys.stderr.write("[ERROR] %s\n" % msg)
print 'Receive Socket bind complete on ' + str(RPORT)
print 'Starting Follow'
Script.ChangeMode("Guided") # changes mode to "Guided"
print 'Guided Mode'
#keep talking with the Mission Planner server
msg = rsock.recv(1024)
pattern = re.compile("[ ]")
parameters = pattern.split(msg)
latData = parameters
lngData = parameters
headingData = parameters
altData = parameters
float_lat = float(latData)
float_lng = float(lngData)
float_heading = float(headingData)
float_alt = float(altData)
"""Safety Manual Mode Switch"""
if cs.mode == 'MANUAL':
XOffset= float(0) #User Input for x axis offset
YOffset= float(-2) #User Input for y axis offset
brng = math.radians(float_heading)
# brng = float_heading*math.pi/180 #User input heading angle of follower in relation to leader. 0 degrees is forward.
d = math.sqrt((XOffset**2)+(YOffset**2)) #Distance in m
MperLat = 69.172*1609.34 #meters per degree of latitude. Length of degree (miles) at equator * meters in a mile
MperLong = math.cos(float_lat)*69.172*1609.34 #meters per degree of longitude
Lat_Offset_meters = YOffset/MperLat #lat distance offset in meters
Long_Offset_meters = XOffset/MperLong #long distance offset in meters
Follower_lat = float_lat + (Long_Offset_meters*math.sin(brng)) + (Lat_Offset_meters*math.cos(brng)) #rotates lat follower offset in relation to heading of leader
Follower_long = float_lng - (Long_Offset_meters*math.cos(brng)) + (Lat_Offset_meters*math.sin(brng)) #rotates long follower offset in relation to heading of leader
Follower_alt = float_alt + 10
#Follower_alt = 10
float_lat = float(Follower_lat)
float_lng = float(Follower_long)
float_alt = float(Follower_alt) #4-5 second lag induced on altitude waypoint line, unless alt is set to 0
item = MissionPlanner.Utilities.Locationwp() # creating waypoint
MissionPlanner.Utilities.Locationwp.alt.SetValue(item,float_alt) #Can only use lat,lng, or alt
MAV.setGuidedModeWP(item) #set waypoint
print 'Waypoint Sent'
print time.strftime('%X %x %Z')
print 'Script End'
Do you have to set an altitude for a waypoint to be set and the vehicle follow it?
I ask because I wrote a script for the rovers and used the same lat, long, and alt waypoint setting lines you used here. In addition, I'm operating with mission planner on two different computers since I'm operating with 2 rovers. One of the rovers is a leader, and the other a follower. The follower grabs coordinates and parameters from the leader, and creates its own continuous waypoints to follow it.
However, the problem lies in when I create the waypoint for the follower. It works fine, but there is like a 4-5 second delay from when the leader Mission Planner script sends the parameters, and the follower Mission Planner script receives them. I'm trying to get rid of this delay and I've found that the problem lies with the altitude line of code for setting the waypoint on the follower. The lat/long are fine, but when I comment out the altitude, there is no delay at all. The only problem is, the follower vehicle doesn't follow the leader without the altitude. In fact, it doesn't move at all. Therefore it looks like the altitude setting is necessary for writing waypoints in all vehicles, even though it doesn't make sense for rovers. But, do you know of a way to reduce the latency or delay of this?
anyone here succeeded in sending waypoints using python in the mission planner?
is there a manual for python scripting for mission planner? Would the scripts in Mission planner run in Andropilot? I am looking to learn how to script an auto mode routine, but have only found brief references to python scripting, if there is a "User guide" for python scripting in Mission Planner, would you link me please? I would like to try my programming skills out on some practical flight routines for Arducopter. any help or hints to where to begin would be greatly appreciated. I also want to say THANK YOU MICHAEL for giving me my new obsession :P i love what you've written/created thanks in advance