question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Indoor copter flight

See original GitHub issue

I am working with dronekit python and using RPi 1 and Pixhawk with copter v3.3.3, in a gps denied environment.

Last few weeks I am trying to make the drone takeoff through python script but unable to do so as i dont know in a gps denied environment, what mode should i use to make the drone takeoff.

----------------next part i want to do-------------- And also I want to control the drone through an android mobile app having joystics on screen to send the exact values as of my transmitter and for that I am trying with RC Override but Im not able to takeoff or increase the throttle with rc override as it says cannot ARM:Throttle too high. ----------------next part i want to do--------------

But first of all, I want to takeoff the drone in GPS Denied environment, hover for few seconds and Land but I am not sure what mode to use instead of guided, with which simple_takeoff() will work.

NOTE: In STABILIZE the motors are disarming after some time instead of increase in their speed:

I am using the following code:

#/usr/bin/env python
# -*- coding: utf-8 -*-
from dronekit import connect,VehicleMode,LocationGlobalRelative
from pymavlink import mavutil
import time
# Receiving from command line
# import argparse
# parser = argparse.ArgumentParser()
# parser.add_argument('--connect',help="PORT_NO")
# args = parser.parse_args()

# Connecting to the vehicle
#connection_string = args.connect
connection_string = "/dev/ttyAMA0,57600"
print("Connecting to...% s" % connection_string)
vehicle = connect(connection_string, wait_ready=True)

#Function to arm and takeoff to a specified altitude
print(vehicle.mode)

# vehicle.mode = VehicleMode("LAND")
# time.sleep(5)
def arm_and_takeoff(aTargetAlt):
	print("Basic Prearm checks..dont touch!!")

 	# while not vehicle.is_armable:
		# print("Waiting for vehicle to initialize")
		# time.sleep(2)

	print("Arming Motors..")
	# Copter should arm in Guided-mode
	vehicle.mode = VehicleMode("GUIDED")
	time.sleep(3)
	vehicle.armed = True
	
	while not vehicle.armed:
		print("Waiting for arming..:% s"% vehicle.mode)
		vehicle.armed = True
		time.sleep(2)
		
	print("Taking Off..")
	vehicle.simple_takeoff(aTargetAlt)
	time.sleep(5)

	while True:
		print("Altitude: ",vehicle.location.global_relative_frame.alt)
		#Break and return from function just below target altitude.
		if vehicle.location.global_relative_frame.alt>=aTargetAlt*0.95: 
			print("Reached Target Altitude..")
			modeLand()
			# print("Landing....")
			# vehicle.mode = VehicleMode("LAND");
			# print("Vehicle mode:%s"% vehicle.mode)
			break


def modeLand():
	print("Landing now")
	vehicle.mode = VehicleMode("LAND")
	time.sleep(5)
	print("-------------Vehicle is in:-------%s"% vehicle.mode)

arm_and_takeoff(2)
print(vehicle.mode)
print("Vehicle object closed")
vehicle.close()

And I have Optical flow Camera and a Lidar which i can use. Please help I’m stuck with this.

Regards Biswajit

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ncoop23commented, Nov 7, 2017

Try this: Need a recent version of ArduPilot.

import sched, time, math
from dronekit import connect, VehicleMode, LocationGlobal, LocationGlobalRelative
from pymavlink import mavutil # Needed for command message definitions

	flightalt = 20 #This is how high you want it to fly to
	vehicle = connect('0.0.0.0:14550')
	time.sleep(10)
	vehicle.channels.overrides = {}
	
	def arm_and_takeoffNoGPS(Target):

	#Arm the vehicle
        vehicle.mode    = VehicleMode("Guided_NoGPS")
	while not vehicle.is_armable: #Wait for the vehicle to be armable
		time.sleep(.5)

	vehicle.armed = True
	while not vehicle.armed:
		time.sleep(1)#Waiting for armed
	#Take Off
	thrust = 0.7
	while True:
		current_altitude = vehicle.location.global_relative_frame.alt
		if current_altitude >= Target*0.95:
			break
		elif current_altitude >= Target*0.6:
			thrust = 0.6
		set_attitude(thrust = thrust)
		time.sleep(0.2)

	def set_attitude(roll_angle = 0.0, pitch_angle = 0.0, yaw_rate = 0.0, thrust = 0.5, duration = 0):

	#Duration is seconds to do this for

	msg = vehicle.message_factory.set_attitude_target_encode(
		0,
		0,                                         #target system
		0,                                         #target component
		0b00000000,                                #type mask: bit 1 is LSB
		to_quaternion(roll_angle, pitch_angle),    #q
		0,                                         #body roll rate in radian
		0,                                         #body pitch rate in radian
		math.radians(yaw_rate),                    #body yaw rate in radian
		thrust)                                    #thrust

	vehicle.send_mavlink(msg)

	if duration != 0:
        	# Divide the duration into the frational and integer parts
        	modf = math.modf(duration)
        	
        	# Sleep for the fractional part
        	time.sleep(modf[0])
        	
        	# Send command to vehicle on 1 Hz cycle
        	for x in range(0,int(modf[1])):
        	    time.sleep(1)
        	    vehicle.send_mavlink(msg)

	def to_quaternion(roll = 0.0, pitch = 0.0, yaw = 0.0):
		"""
		Convert degrees to quaternions
		"""
		t0 = math.cos(math.radians(yaw * 0.5))
		t1 = math.sin(math.radians(yaw * 0.5))
		t2 = math.cos(math.radians(roll * 0.5))
		t3 = math.sin(math.radians(roll * 0.5))
		t4 = math.cos(math.radians(pitch * 0.5))
		t5 = math.sin(math.radians(pitch * 0.5))
    
		w = t0 * t2 * t4 + t1 * t3 * t5
		x = t0 * t3 * t4 - t1 * t2 * t5
		y = t0 * t2 * t5 + t1 * t3 * t4
		z = t1 * t2 * t4 - t0 * t3 * t5
    
		return [w, x, y, z]


	arm_and_takeoffNoGPS(flightalt)

1reaction
Biswajit1995commented, May 24, 2017

Thanks @studroid ,

I will look into it. And sorry for late response.

Regards Biswajit

Read more comments on GitHub >

github_iconTop Results From Across the Web

RC helicopters for indoors - Amazon.com
SWTOIPIG Remote Control Helicopter, Heavy RC Helicopters Toy Altitude Hold, 2.4GHz Aircraft Indoor Flying Toy with High & Low Speed Mode, One Key...
Read more >
10 Best Indoor Radio Control Helicopters 2022 - TheToyZone
1Carrera RC - Flying Cape Super Mario (Best Budget Option) · 2Remote Control Helicopter, S107H-E Aircraft with Altitude Hold (Best Quality Option).
Read more >
Best Remote-Control Helicopters in 2022 - Futurism
Flying indoors requires more control to avoid not just damaging the helicopter but also breaking items in the house. No one wants to...
Read more >
Micr Flyers Wireless Indoor Helicopter Indoor LED Flight ...
Seller assumes all responsibility for this listing. eBay item number:234761075233. Last updated on ...
Read more >
7 Best Remote Control Helicopters for Kids (2022 Reviews)
Best Large RC Helicopter. WLtoys Helicopter Toy. Fly time of 8 minutes; Stunt-ready; 2.4 GHz remote control ; Best for Indoors and Outdoors....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found