def run(self): #create the drone controller droneController = DroneController(robotName) path = [1,2,3,4,5,6,7,1,8,9,10,11,12,13] droneController.setPath(path) #randomize how much this guy cares about angular error angleMult = (random.random() * 2) + 1.0 while not rospy.is_shutdown() and self.isRunning: twist = Twist() angle = droneController.getAngleError() angle *= angleMult if math.fabs(angle) > 0.8: if angle > 0: twist.angular.z=1 elif angle < 0: twist.angular.z=-1 else: twist.linear.x=1 self.pub.publish(twist) delay = (random.random() * 1.8) + 0.2 rospy.sleep(delay)
def run(self): #create the drone controller droneController = DroneController(robotName) path = [1,2,3,4,5,6,7,1,8,9,10,11,12,13] droneController.setPath(path) while not rospy.is_shutdown(): twist = Twist() angle = droneController.getAngleError() #if math.fabs(angle) > 0.1: twist.angular.z=angle #else: twist.linear.x=1 self.pub.publish(twist) rospy.sleep(1)
class Control(): def __init__(self): self.cmd = BasicCommands() # self.display = KeyboardController(self.cmd) self.drone_controller = DroneController(self.cmd) def run(self): # self.display.show() self.drone_controller.listener() # executes the QT application # self.status = self.app.exec_() # and only progresses to here once the application has been shutdown rospy.signal_shutdown('Shutting Down') self.cmd.SendLand() print("AHHHH");
import logging from person_detector import FakeFixedPersonDetector from drone_controller import DroneController from configuration import DroneConfiguration from ai import DroneAI logging.basicConfig( format='[%(asctime)s] %(levelname)-7s (%(name)s) %(message)s', level=logging.DEBUG) log = logging.getLogger(__name__) config = DroneConfiguration(udp_port=14550) drone_controller = DroneController(config) ai = DroneAI(config, drone_controller, FakeFixedPersonDetector()) ai.run()
from flask import Flask, render_template, request from authentication import Authentication from drone_controller import DroneController authentication = Authentication() drone_controller = DroneController() app = Flask(__name__) @app.route("/", methods=["GET"]) def home(): return render_template("home.html") @app.route("/routing", methods=["GET"]) def routing(): if request.values.get("login"): return render_template("login.html") elif request.values.get("new_user_account"): return render_template("new_user_account.html") @app.route("/routing2", methods=["GET"]) def routing2(): if request.values.get("add_drone"): return render_template("add_drone.html") elif request.values.get("view_drone"): display = drone_controller.display_drones() return render_template("view_drones.html", display=display) elif request.values.get("move_drone"): return render_template("move_drone.html")
def __init__(self): self.cmd = BasicCommands() # self.display = KeyboardController(self.cmd) self.drone_controller = DroneController(self.cmd)
#! /usr/bin/env python # test code import rospy import rospkg import time import random from gazebo_connection import GazeboConnection from drone_controller import DroneController from optitrack import OptiTrack if __name__ == '__main__': rospy.init_node('test_to_fly', anonymous=True) controller = DroneController() #controller.reset() # gazebo = GazeboConnection() # gazebo.set_location() controller.send_takeoff() time.sleep(3) # rospy.loginfo("Land Drone") controller.send_land() # controller.send_emergency()
def main(): # Setting up the logging file # Logging file will be called log-<runtime time and date> logging.basicConfig(filename='script_log-' + str(datetime.now()), level=logging.DEBUG) # Checking that script inputs are valid checked_args = check_inputs() database_file = checked_args[0] output_folder = checked_args[1] # Setting up the database database_cursor = setup_database(database_file) # Getting the drone controller drone_controller = DroneController() previous_x = "" previous_y = "" num_samples = 1 # Getting the algorithm name algorithm = input("Algorithm Name: ") logging.debug("Script: Algorithm Name Provided: " + algorithm) logging.debug("Script: Entering Testing Loop") while True: # Reminding the user what the previous configuration was print("The previous configuration was: X: " + previous_x + " Y: " + previous_y + " Num Samples: " + str(num_samples)) # Getting the X Distance to fly x_distance = input( "How many metres in the X direction would you like to fly: ") if x_distance == "BREAK": break # Getting the Y Distance to fly y_distance = input( "How many metres in the Y direction would you like to fly: ") if y_distance == "BREAK": break # If the same configuration was used, increase the numSamples if x_distance == previous_x and y_distance == previous_y: num_samples += 1 else: num_samples = 1 # Setting up the folders for sensor output results_folder = setup_output_folder(output_folder, algorithm, x_distance, y_distance, num_samples) # Commanding the drone to fly the given distances drone_controller.default_fly_to(int(x_distance), int(y_distance), results_folder) # Getting the actual distances of the flight x_actual = input("Actual X: ") if x_actual == "BREAK": break y_actual = input("Actual Y: ") if y_actual == "BREAK": break # Creating a database entry create_database_entry(database_cursor, algorithm, x_distance, y_distance, x_actual, y_actual, results_folder) # Formatting Gap print() # Updating tracking variables previous_x = x_distance previous_y = y_distance # Closing the connection at the end database_cursor.connection.close()
def main(): print("\nHubsan X4 H107L - Python head-end for Arduino Hubsan Controller.") print("----------------------------------------------------------------") print("> Loading config settings...\n") config = configparser.ConfigParser() config.read('hubsan.config') print("> Detecting COM ports...\n") ports = list() i = 0 for port in list_ports.comports(): print(" %s: [%s] %s" % (str(i), port[0], port[1])) ports.append(port) i += 1 if len(ports) == 0: print( "Error: No Arduino Serial ports detected! Try reconnecting the USB cable." ) sys.exit(1) portnum = input("\n Enter the number of the desired COM port: ") comport = ports[int(portnum)] print("\n- [%s] Selected." % comport[0]) print("\n> Opening Serial port...") ser = serial.Serial(comport[0], 115200, timeout=1) print(" - Successful.") print("\n> TERMINAL STATUS:") print("------------------") while True: line = ser.readline().strip() if line != "": print(" %s" % line) if (line == "** Status: READY. **"): break print("\n> INITIALIZING CONTROL INTERFACE.") print("---------------------------------") dc = DroneController(ser, ) # Set up control values # def_t = throttle = 0 # def_y = yaw = 128 + int(config['flight']['yaw_trim']) # def_p = pitch = 128 + int(config['flight']['pitch_trim']) # def_r = roll = 128 + int(config['flight']['roll_trim']) print(" Post-Trim Flight Defaults = Yaw: %s Pitch: %s Roll: %s" % (str(yaw), str(pitch), str(roll))) yt = int(config['flight']['yaw_trim']) pt = int(config['flight']['pitch_trim']) rt = int(config['flight']['roll_trim']) dc = DroneController(ser, yt, pt, rt) smooth = 0 # Set up PyGame event handlers and event loop pygame.init() window = pygame.display.set_mode((640, 480)) pygame.display.set_caption("Hubsan X4 H107L Python Controller v0.1") clock = pygame.time.Clock() print("\nTHR:YAW:PIT:ROL\n---------------") while True: clock.tick(200) # Lock framerate of the input for consistency. dc.update_control_values(pygame.event.get()) dc.send_control_signals()