def set_servos(throttle, steering): throttle = THROTTLE_SERVO_MIN + ((throttle / 100) * (THROTTLE_SERVO_MAX - THROTTLE_SERVO_MIN)) steering = STEERING_SERVO_MIN + ((steering / 180) * (STEERING_SERVO_MAX - STEERING_SERVO_MIN)) servo3.set(throttle) servo1.set(steering)
def disable_servos(): servos_enabled = False print("Disarming throttle") servo1.set(0) servo3.set(0) time.sleep(1) rcpy.servo.disable() if servo1clk: servo1clk.stop() if servo3clk: servo3clk.stop()
def set_servos(throttle, steering): global servos_enabled, servos_paused if not servos_enabled: enable_servos() if not servos_paused: throttle = THROTTLE_SERVO_MIN + ((throttle/100) * (THROTTLE_SERVO_MAX - THROTTLE_SERVO_MIN)) steering = STEERING_SERVO_MIN + ((steering/180) * (STEERING_SERVO_MAX - STEERING_SERVO_MIN)) servo3.set(throttle) servo1.set(steering) else: servo3.set(0) servo1.set(0)
def enable_servos(): global servo1, servo3, servo1clk, servo3clk servos_enabled = True rcpy.servo.enable() # Enable steering servo if not servo1: from rcpy.servo import servo1 servo1.set(0) if not servo1clk: servo1clk = rcpy.clock.Clock(servo1, 0.02) servo1clk.start() # Enable throttle if not servo3: from rcpy.servo import servo3 servo3.set(0) if not servo3clk: servo3clk = rcpy.clock.Clock(servo3, 0.02) servo3clk.start() time.sleep(1) print("Arming throttle") servo3.set(-0.1) time.sleep(3) servo3.set(0)
def enable_steering_and_throttle(self): rcpy.servo.enable() # Enable steering servo servo1.set(0) servo1clk = rcpy.clock.Clock(servo1, 0.02) servo1clk.start() # Enable throttle servo3.set(0) servo3clk = rcpy.clock.Clock(servo3, 0.02) servo3clk.start() time.sleep(1) print("Arming throttle") servo3.set(-0.1) time.sleep(3) servo3.set(0)
#!/usr/bin/env python3 import os, sys if not os.geteuid() == 0: sys.exit("\nPlease run as root.\n") if sys.version_info < (3, 0): sys.exit("\nPlease run under python3.\n") import rcpy, time from rcpy.servo import servo3 rcpy.servo.enable() servo3.set(0) servo3clk = rcpy.clock.Clock(servo3, 0.02) servo3clk.start() time.sleep(1) print("Arming") servo3.set(-0.1) time.sleep(3) print("Idle") servo3.set(0) time.sleep(3) #print("Medium") #servo3.set(0.1) #time.sleep(1) print("Slow") servo3.set(0.05) time.sleep(3) #print("Fast") #servo3.set(0.2) #time.sleep(2)
sys.exit("\nPlease run under python3.\n") print("Importing Python modules, please be patient.") import cv2, rcpy, datetime, time, numpy, pygame, threading, math # Enable steering servo from rcpy.servo import servo1 rcpy.servo.enable() servo1.set(0) servo1clk = rcpy.clock.Clock(servo1, 0.02) servo1clk.start() # Enable throttle from rcpy.servo import servo3 rcpy.servo.enable() servo3.set(0) servo3clk = rcpy.clock.Clock(servo3, 0.02) servo3clk.start() time.sleep(1) print("Arming throttle") servo3.set(-0.1) time.sleep(3) servo3.set(0) # This file was originally part of the OpenMV project. # Copyright (c) 2013-2017 Ibrahim Abdelkader <*****@*****.**> & Kwabena W. Agyeman <*****@*****.**> # This work is licensed under the MIT license, see the file LICENSE for details. ########### # Settings ###########