So I have developed a python script to arm a quadrotor, fly a guided mission, return to launch and disarm. However, I am interested in getting back control of the rotor while the script is in progress incase something goes wrong. Can I put a failsafe case for this in python script or do I have to look into mavlink framework to achieve this.

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

Join diydrones

Email me when people reply –

Replies

  • Developer

    you are in control of the python script, so you can do whatever you need to do.

    • Hey Michael, thanks for your reply. Can you tell me what command is used to restore control back to RC?

      • Developer

        are you using the rc override in the script?

        if so just set all the pwm's to 0, and send a packet, that will remove the rc override

        • It worked. Thank you !!

          • Michael, I tried to do that, and I was able to regain control. But my I fail to go into guided mode after that. The copter just drops to the ground after I execute the sequence to remove rc override.

            Here is my code

            import sys
            import clr
            import time
            from math import *
            import MissionPlanner #import *

            clr.AddReference("MissionPlanner.Utilities") # includes the Utilities class

            def set_RC():
            print "Setting RCs to Neutral"
            for i in range(1,9):
            Script.SendRC(i,1500,False)
            Script.SendRC(3,Script.GetParam('RC3_MIN'),True)
            Script.ChangeMode("Stabilize")

            return True

            def arm_motors():
            Script.ChangeMode("Stabilize")
            Script.SendRC(3,Script.GetParam('RC3_MIN'),True)
            Script.SendRC(4,Script.GetParam('RC4_MAX'),True)
            print "Arming Motors !!"
            Script.WaitFor('ARMING MOTORS',10000)
            print "Armed"
            Script.SendRC(4,(Script.GetParam('RC4_MIN')+Script.GetParam('RC4_MAX'))/2,True)
            Script.Sleep(5)
            Script.SendRC(3,2000,True)
            time.sleep(1)
            Script.ChangeMode("AltHold")
            #Script.SendRC(3,(Script.GetParam('RC3_MIN')+Script.GetParam('RC3_MAX'))/2,True)
            Script.SendRC(3,(Script.GetParam('TRIM_THROTTLE')),True)

            return True

            def disarm_motors():
            Script.ChangeMode("Stabilize")
            Script.SendRC(3,Script.GetParam('RC3_MIN'),True)
            Script.SendRC(4,Script.GetParam('RC4_MIN'),True)
            print "Disarming motors ...."
            Script.WaitFor('DISARMING MOTORS',10000)
            print "Disarmed"
            Script.SendRC(4,(Script.GetParam('RC4_MIN')+Script.GetParam('RC4_MAX'))/2,True)

            return True

            def Return_To_Launch(user_alt):
            if user_alt==0:
            Script.ChangeParam("RTL_ALT",2000)
            print "Default RTL altitude set"
            else:
            Script.ChangeParam("RTL_ALT",cs.alt*100)
            print "User RTL altitude set"
            Script.ChangeMode("RTL")
            print "Returning to Launch"

            return True

            #MAIN

            set_RC();
            arm_motors();
            time.sleep(20);

            for i in range(1,9):
            Script.SendRC(i,0,True) #fails after this


            Script.ChangeMode("Guided")

            item = MissionPlanner.Utilities.Locationwp()

            lat = 37.871460
            lng = -122.317564
            alt = 5

            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(30)

            print 'Ready for next WP'

            lat = lat
            lng = lng
            alt = alt+2
            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(30)

            print "Reached WP 2"

            Return_To_Launch(1);
            time.sleep(30);
            disarm_motors();
            set_RC();

This reply was deleted.

Activity

Neville Rodrigues liked Neville Rodrigues's profile
Jun 30
Santiago Perez liked Santiago Perez's profile
Jun 21
More…