Skip to content

Instantly share code, notes, and snippets.

View djnugent's full-sized avatar

Daniel Nugent djnugent

View GitHub Profile
@djnugent
djnugent / apistop.py
Created June 18, 2015 18:06
api.stop usage
import time
# First get an instance of the API endpoint
api = local_connect()
# Get the connected vehicle (currently only one vehicle can be returned).
v = api.get_vehicles()[0]
#wait here until mavproxy tells us to exit
while not api.exit:
time.sleep(0.2)
@djnugent
djnugent / cmdack.py
Created June 18, 2015 21:44
Using command_ack in dronekit
#
# This example shows how to use DroneKit-Python to change the vehicles altitude
#
import time
from pymavlink import mavutil
def process_result(result):
if result is None:
#!/usr/bin/python
from Adafruit_PWM_Servo_Driver import PWM
import time
import numpy as np
import cv2
import math
import sys
/**
TODO
-Handle user input:
-during approach(RTL) and during descent
-abort landing to loiter or althold
-Allow for a pause before starting descent
-slow down on final descent
-dont allow for a mode switch out of NO_GPS land if there is no gps
@djnugent
djnugent / ChangeAlt.py
Last active June 17, 2016 10:25
Dronekit: Change alt in GUIDED mode
#
# This example shows how to use DroneKit-Python to change the vehicles altitude
#Usage: api start ChangeAlt.py
from pymavlink import mavutil
# First get an instance of the API endpoint
api = local_connect()
# Get the connected vehicle (currently only one vehicle can be returned).
v = api.get_vehicles()[0]
@djnugent
djnugent / Makefile
Created September 21, 2016 23:02
Universal C/C++ Makefile
#https://ubuntuforums.org/showthread.php?t=1204739
app = shell
srcExt = c
srcDir = src
objDir = build
binDir = .
inc = include
@djnugent
djnugent / scriptr.py
Created February 8, 2017 06:22
Outline for a bash scripting module in python
#todo
# Implement
# how to handle sudo
# how to handle readline/buffer with errors
class process():
#cmd - bash cmd + args
@djnugent
djnugent / StateMachine.py
Created June 30, 2017 18:48
HSM in python
import time
import types
class StateMachine():
def __init__(self):
self.states = {}
self.start_state = None
self.current_state = None
self.started = False
@djnugent
djnugent / set_att.py
Created July 5, 2017 16:34
Mavros Set Attitude Rate
#!/usr/bin/env python
import rospy
import IPython
from geometry_msgs.msg import PoseStamped, TwistStamped, Twist, Vector3, Pose
from mavros_msgs.msg import PositionTarget, AttitudeTarget, State
from mavros_msgs.srv import SetMode, SetModeRequest
from std_msgs.msg import Float64
import math
import time
class pos_control:
def __init__(self, kP, kI, kD, max_int = 100, max_spd=10):
limits = [-math.sqrt(2) * max_spd,math.sqrt(2) * max_spd]
self.x_pid = PID(kP, kI, kD, max_int = max_int, limits = limits)
self.y_pid = PID(kP, kI, kD, max_int = max_int, limits = limits)