Using scipt to change mode

Hi i am currently using a script that mavproxy will read from and execute commands, i will post the script below. I would like to the script such that i can change to guided mode halfway through auto mode(at a particular waypoint eg WP 4. Will appreciate any help !

import socket
import sy
import time , os
import py_compile

py_compile.compile('fyp.py')

def send(ts,rs):
    try:
        for c in range(len(commands)):
            time.sleep(3)
            message = commands[c]
            ts.sendall(message)
            print '\n' + message.upper() + ' ~SUCCESS~'
            data,addr=rs.recvfrom(1024)
            print data

    except socket.error:
        print '\n' + message.upper() + ' ~FAILED~'
        sys.exit()


def create_tx():
    try:
        ts=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        print ('Socket TX Created')
    except socket.error:
        print ('Failed to create TX socket')
        sys.exit()
    ts.connect((HOST,PORT_TX))
    print 'TX socket connected ' + HOST
    return ts

def create_rx():
    try:
        rs=socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        print ('Socket RX Created')
    except socket.error:
        print('Failed to create RX socket')
        sys.exit()
    rs.bind((HOST,PORT_RX))
    print 'RX socket connected ' + HOST
    return rs
###################################################################################################
commands = ['mode stabilize','arm safetyoff','arm throttle', 'rc 3 1600', 'mode auto', 'rc 3 0', 'disarm', 'arm safetyon' ] #this is the command list

time.sleep(10)
HOST = '127.0.0.1'
PORT_TX = 4123
PORT_RX = 4000

hi = create_tx()
bye =create_rx()
send(hi,bye)

 

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

Join diydrones

Email me when people reply –

Activity