def __init__(self): ''' Read config file to init camera's parameter ''' config = configparser.ConfigParser() config.read("config.ini") self.statu="" # Horiazonal direction control parameters HIntfNum = config.getint("camera", "HIntfNum") HInitPosition = config.getint("camera", "HInitPosition") HMinPosition = config.getint("camera", "HMinPosition") HMaxPosition = config.getint("camera", "HMaxPosition") HSpeed = config.getint("camera", "HSpeed") # Vertical direction control parameters VIntfNum = config.getint("camera", "VIntfNum") VInitPosition = config.getint("camera", "VInitPosition") VMinPosition = config.getint("camera", "VMinPosition") VMaxPosition = config.getint("camera", "VMaxPosition") VSpeed = config.getint("camera", "VSpeed") self.HCameraControl = Steering( HIntfNum, HInitPosition, HMinPosition, HMaxPosition, HSpeed) self.VCameraControl = Steering( VIntfNum, VInitPosition, VMinPosition, VMaxPosition, VSpeed)
def __init__(self, arg): self.args = arg isDebug = False if (len(self.args) > 1): print("\n".join(self.args[1:])) if (self.args[1] == "debug"): self.__debug = True atexit.register(self.cleanup) self.__connect_to_cruncher() try: self.__kit = ServoKit(channels=16) self.__space_invaders = SpaceInvaders(self.__kit) except: print("Servokit not initialised, Servo Calibration won't work") try: self.__steering = Steering(self.__kit, steeringStatusFile=os.path.abspath( "./config/steering_status.json")) self.__suspension = Suspension(self.__kit) except: type, value, traceback = sys.exc_info() print("Steering status failed to load") print('Error Details %s: %s %s' % (type, value, traceback))
def __init__(self): self.ub.Init() self.tb.Init() self.t1 = datetime.now() self.tickSpeed = 0.05 self.us = Ultrasonics(self.ub) self.motors = Motors(self.tb, self.ub, self.tickSpeed) self.steering = Steering(self.tb, self.ub, self.tickSpeed) self.teleLogger = Telemetry("telemetry", "csv").get() self.ptc = PanTiltController(self.ub, 270, 135) self.joystick_controller = JoystickController(self.tb, self.ub) battMin, battMax = self.tb.GetBatteryMonitoringLimits() battCurrent = self.tb.GetBatteryReading() print('Battery monitoring settings:') print(' Minimum (red) %02.2f V' % (battMin)) print(' Half-way (yellow) %02.2f V' % ((battMin + battMax) / 2)) print(' Maximum (green) %02.2f V' % (battMax)) print() print(' Current voltage %02.2f V' % (battCurrent)) print(' Mode %s' % (self.mode)) print()
def __init__(self, servoKit): self.__kit = servoKit self.__keyboardInput = KeyboardInput("Steering Calibration") config_file = servoStatusFile = os.path.abspath( os.path.join(os.path.dirname(__file__), "..")) + "/config/servo_status.json" self.__steering = Steering(self.__kit, config_file) self.__suspension = Suspension(self.__kit, config_file)
def back(self): if self.has_turned: with Steering() as steer: steer.turn_center() #Log('move start') GPIO.output(self.enable1, GPIO.HIGH) # if input1 and input2 are swapped a regular motor will go in reverse. GPIO.output(self.input1, GPIO.HIGH) # but lego will not as it has different pin for reverse. so we should disable this signal and enable that , creepy GPIO.output(self.input2, GPIO.LOW)
def front(self): #Log('move start') # if input1 and input2 are swapped we go in reverse. if self.has_turned: with Steering() as steer: steer.turn_center() GPIO.output(self.input1, GPIO.LOW) GPIO.output(self.input2, GPIO.HIGH) GPIO.output(self.enable1, GPIO.HIGH)
def __init__(self): config = configparser.ConfigParser() config.read("./config.ini") HIntfNum = config.getint("camera", "HIntfNum") HInitPosition = config.getint("camera", "HInitPosition") HMinPosition = config.getint("camera", "HMinPosition") HMaxPosition = config.getint("camera", "HMaxPosition") HSpeed = config.getint("camera", "HSpeed") # Vertical direction control parameters VIntfNum = config.getint("camera", "VIntfNum") VInitPosition = config.getint("camera", "VInitPosition") VMinPosition = config.getint("camera", "VMinPosition") VMaxPosition = config.getint("camera", "VMaxPosition") VSpeed = config.getint("camera", "VSpeed") self.HCameraControl = Steering(HIntfNum, HInitPosition, HMinPosition, HMaxPosition, HSpeed) self.VCameraControl = Steering(VIntfNum, VInitPosition, VMinPosition, VMaxPosition, VSpeed)
def move(self, signal): if signal == 258: self.logger.debug('going forward') if self.brakes == True: self.logger.debug('disabling brakes') GPIO.output(self.enable1, GPIO.HIGH) self.brakes = False self.front() if signal == 260: self.logger.debug('turning left') with Steering() as steer: steer.turn_left() self.has_turned = True if signal == 261: self.logger.debug('turning right') with Steering() as steer: steer.turn_right() self.has_turned = True if signal == 259: self.logger.debug('going back') self.back() if signal == 32: self.logger.debug('applying brakes') self.brakes = True GPIO.output(self.enable1, GPIO.LOW) if signal == 27: self.logger.debug('clearing') self.clear() return signal
def __init__(self, arg): self.arg = arg atexit.register(self.cleanup) try: self.__kit = ServoKit(channels=16) except: print("Servokit not initialised, Servo Calibration won't work") try: self.__steering = Steering(self.__kit, servoStatusFile=os.path.abspath("./config/servo_status.json")) except: type, value, traceback = sys.exc_info() print("Steering status failed to load") print('Error Details %s: %s %s' % (traceback, type, value))
def __init__(self): self.logger = logging.getLogger(self.__class__.__name__) GPIO.setmode(GPIO.BCM) self.steer = Steering() self.brakes = False self.has_turned = False # motor driver self.input1 = 20 self.input2 = 16 self.enable1 = 21 # always disable after finishing and\or in catch # set GPIO direction (IN / OUT) # we send instructions to motor driver IC GPIO.setup(self.input1, GPIO.OUT) GPIO.setup(self.input2, GPIO.OUT) # this will determine if signal should be sent to output pins GPIO.setup(self.enable1, GPIO.OUT)
def __init__(self): self.pwm = PWM(16) self.pwm.start() self.light_level = 0 # self.pwm.set_pwm_freq(60) self.steering_wheel_left = ServoMotor(self.pwm, 0) self.steering_wheel_right = ServoMotor(self.pwm, 1) self.left_motor = DCMotor(self.pwm, 2, 3) self.right_motor = DCMotor(self.pwm, 4, 5) self.camera = ServoMotor(self.pwm, 12) self.steering = Steering(mount_height=46.1, mount_width=40.0, wheel_arm=26.1, servo_horn=20.0, bridge=40.0, width=123, length=193.650) self._mode_button = Button(24) self._mode_button.when_pressed = self._on_mode_button self._mode_led_1 = LED(22) self._mode_led_2 = LED(10) self.mode = 1 self._update_mode()
def __init__(self): config = configparser.ConfigParser() config.read("config.ini") trigger = config.getint("ultrasonic", "Trigger") echo = config.getint("ultrasonic", "Echo") servoNum = config.getint("steering", "servoNum") InitPosition = config.getint("steering", "InitPosition") minPosition = config.getint("steering", "MinPosition") maxPosition = config.getint("steering", "maxPosition") speed = config.getint("steering", "speed") self.IN_1 = config.getint("car", "IN1") self.IN_2 = config.getint("car", "IN2") self.IN_3 = config.getint("car", "IN3") self.IN_4 = config.getint("car", "IN4") self.Sonic = Ultrasonic(trigger, echo) self.Servo = Steering(servoNum, InitPosition, minPosition, maxPosition, speed) self.motor = Motor(self.IN_1, self.IN_2, self.IN_3, self.IN_4)
def getSteeringPIDDerivativeGain(self): return 0.0008 def getSteeringPIDIntegralTermLimit(self): return -1.0 if __name__ == "__main__": log_message_queue_listener.start() logging.info('Loading') ev3.Sound.beep().wait() ev3.Sound.beep().wait() settings = Settings() bumpers = Bumpers(settings.getFrontBumperAddress()) if (settings.hasFrontBumper()) else None steering = Steering( settings.getSteeringMotorAddress(), settings.getSteeringMotorSpeedFactor(), settings.getSteeringSpeed(), settings.getSteeringMaxRange(), settings.getSteeringMotorPositionFactor(), settings.getDoCenterSteeringWhenInitializing() ) folkracer = Folkracer(steering, Engine(settings), Distances(settings), bumpers, Buttons(), settings, None, None, LightsAndSounds()) folkracer.start() folkracer.join() logging.info('Shutting down.') log_message_queue_listener.stop() ev3.Sound.beep().wait() ev3.Sound.beep().wait()
from machine import Pin import blesync_server import blesync_uart.server from motors import Motor import pinout from steering import Steering motor_r = Motor(pinout.MOTOR_1A, pinout.MOTOR_2A, pinout.MOTOR_12EN) motor_l = Motor(pinout.MOTOR_3A, pinout.MOTOR_4A, pinout.MOTOR_34EN) steering = Steering(motor_l, motor_r) built_in_led = Pin(2, Pin.OUT) @blesync_uart.server.UARTService.on_message def on_message(service, conn_handle, message): if message == b'!B516': steering.center(1000) elif message == b'!B507': steering.center(0) elif message == b'!B615': steering.center(-1000) elif message == b'!B606': steering.center(0) elif message == b'!B813': steering.right(1000) elif message == b'!B804': steering.right(0) elif message == b'!B714': steering.left(1000)
from motor import Motor from time import sleep from predict import Predict #import config pygame.init() pygame.joystick.init() prediction = Predict("VGG16_RealImg_Adagrad_150x2.EP74-0.62-0.04.h5", 150, 150) DrivingMotor = Motor(388) SteeringWheel = Steering(298) SteeringWheel.Run() axis = 0 stop = 0 autoMode = 0 joystick_pressed = 0 steer_enhancer = 2 while stop == 0: pygame.event.get() if pygame.joystick.get_count() == 1: # 1 Joystick = pygame.joystick.Joystick(0)
#!/usr/bin/python3 import logging import time from steering import Steering logging.basicConfig(format='%(asctime)s %(message)s', filename='steering_systemtest.log', level=logging.DEBUG) if __name__ == "__main__": logging.info('Steering system test: starting') steering = Steering(steering_motor_address='outC', steering_motor_speed_factor=10, steering_speed=5, steering_max_range=35, steering_motor_position_factor=-1) logging.info('=== Steering system test: Initialize ===') steering.initialize() logging.info('Steering system test: steering position = ' + str(steering.get_current_steering_position())) time.sleep(1) logging.info('=== Steering system test: turn to 100% left ===') steering.set_steering_position(-100) logging.info('Steering system test: steering position = ' + str(steering.get_current_steering_position())) logging.info('Steering system test: steering motor state = ' + str(steering.steering_motor.state)) time.sleep(1)
from gevent import monkey monkey.patch_all() import cv2 from flask import (Flask, Response, render_template, send_file, stream_with_context) from flask_sockets import Sockets from camera import Camera from steering import Steering from gevent import spawn, sleep app = Flask(__name__, static_folder='static') sockets = Sockets(app) steering = Steering() camera = Camera() #creating greenthread for getting frames from camera spawn(camera.get_frames) def generate(cam): while True: if cam.frame is None: sleep(0) continue (flag, encodedImage) = cv2.imencode(".jpg", cam.frame) cam.frame = None # ensure the frame was successfully encoded if not flag:
def setUp(self): self.steering = Steering(TEST_STEERING_MOTOR_ADDRESS, TEST_STEERING_MOTOR_SPEED_FACTOR, TEST_STEERING_SPEED, TEST_STEERING_MAX_RANGE, TEST_STEERING_MOTOR_POSITION_FACTOR, True) self.steering.steering_motor = MagicMock()