def drive(): #Initialize car mule = Vehicle() mule.add(WebCam(threaded=True)) mule.add(DisplayFeed('MuleView')) mule.start() mule.drive() mule.stop()
def drive(config): V = Vehicle() clock = Timestamp() V.add(clock, outputs=['timestamp']) cam = PiCamera(resolution=config.CAMERA_RESOLUTION) V.add(cam, outputs=['image'], threaded=True) ctr = LocalWebController() V.add(ctr, inputs=['image'], outputs=['angle', 'throttle'], threaded=True) engine = CarEngine() V.add(engine, inputs=['angle', 'throttle']) tub = TubWriter(path='~/mycar', inputs=['image'], types=['image_array']) V.add(tub, inputs=['image']) # run the vehicle V.start(rate_hz=config.DRIVE_LOOP_HZ, max_loop_count=config.MAX_LOOPS)
def drive(): ''' Construct a working robotic vehicle from many parts. Each part runs as a job in the Vehicle loop, calling either it's run or run_threaded method depending on the constructor flag `threaded`. All parts are updated one after another at the framerate given in cfg.DRIVE_LOOP_HZ assuming each part finishes processing in a timely manner. Parts may have named outputs and inputs. The framework handles passing named outputs to parts requesting the same named input. ''' # Initialize car V = Vehicle() f710 = LogitechJoystickController(auto_record_on_throttle=False, steering_scale=1, throttle_scale=cfg.JOYSTICK_MAX_THROTTLE, throttle_dir=cfg.JOYSTICK_THROTTLE_DIR) V.add(f710, outputs=['user/angle', 'user/throttle', 'user/mode', 'recording'], threaded=True) # Drive train setup arduino_controller = ArduinoFirmata(servo_pin=cfg.STEERING_ARDUINO_PIN, esc_pin=cfg.THROTTLE_ARDUINO_PIN) steering = PWMSteering(controller=arduino_controller, left_pulse=cfg.STEERING_LEFT_PWM, right_pulse=cfg.STEERING_RIGHT_PWM) throttle = PWMThrottle(controller=arduino_controller, max_pulse=cfg.THROTTLE_FORWARD_PWM, zero_pulse=cfg.THROTTLE_STOPPED_PWM, min_pulse=cfg.THROTTLE_REVERSE_PWM) V.add(steering, inputs=['user/angle']) V.add(throttle, inputs=['user/throttle']) # run the vehicle V.start(rate_hz=cfg.DRIVE_LOOP_HZ, max_loop_count=cfg.MAX_LOOPS)
#Define a vehicle to take and record pictures 10 times per second. from vehicle import Vehicle import os, sys from parts.camera import PiCamera #from parts.datastore import Tub V = Vehicle() #add a camera part cam = PiCamera() V.add(cam, outputs=['image'], threaded=True) #add tub part to record images tub = Tub(path='~/d2/gettings_started', inputs=['image'], types=['image_array']) V.add(tub, inputs=['image']) #start the drive loop at 10 Hz V.start(rate_hz=10)
def drive(cfg, model_path=None, use_joystick=True): """ Drive the car. You will either drive to record data for training or drive to test the autonomous mode. Either use Web controls or Joystick to control the vehicle. If driving autonomous, give the model to load. :param cfg: Configuration for user defined values. :param model_path: Path to load the model. :param use_joystick Use parameter in startup to use joystick. """ #Initialized car V = Vehicle() # Setup camera cam = PiCamera() V.add(cam, outputs=['cam/image_array'], threaded=True) # Select if only use bluetooth PS3 controller ctr = JoystickController( max_throttle=cfg.JOYSTICK_MAX_THROTTLE, steering_scale=cfg.JOYSTICK_STEERING_SCALE, auto_record_on_throttle=cfg.AUTO_RECORD_ON_THROTTLE) V.add(ctr, inputs=['cam/image_array'], outputs=['user/angle', 'user/throttle', 'user/mode', 'recording'], threaded=True) # See if we should even run the pilot module. # This is only needed because the part run_contion only accepts boolean def pilot_condition(mode): if mode == 'user': return False else: return True pilot_condition_part = Lambda(pilot_condition) V.add(pilot_condition_part, inputs=['user/mode'], outputs=['run_pilot']) # Load the model configuration kl = KerasRicar() if model_path: print(model_path) kl.load(model_path) V.add(kl, inputs=['cam/image_array'], outputs=['pilot/angle', 'pilot/throttle'], run_condition='run_pilot') # Choose what inputs should change the car. def drive_mode(mode, user_angle, user_throttle, pilot_angle, pilot_throttle): if mode == 'user': return user_angle, user_throttle elif mode == 'local_angle': return pilot_angle, user_throttle else: return pilot_angle, pilot_throttle drive_mode_part = Lambda(drive_mode) V.add(drive_mode_part, inputs=[ 'user/mode', 'user/angle', 'user/throttle', 'pilot/angle', 'pilot/throttle' ], outputs=['angle', 'throttle']) # Configure the throttle and angle control hardware # Calibrate min/max for steering angle # Calibrate min/max/zero for throttle steering_controller = PCA9685(1) steering = PWMSteering(controller=steering_controller, left_pulse=460, right_pulse=260, invert_steering_angle=cfg.INVERT_STEERING_ANGLE) throttle_controller = PCA9685(0) throttle = PWMThrottle(controller=throttle_controller, max_pulse=500, zero_pulse=370, min_pulse=220) V.add(steering, inputs=['angle']) V.add(throttle, inputs=['throttle']) # Add tub to save data inputs = [ 'cam/image_array', 'user/angle', 'user/throttle', 'pilot/angle', 'pilot/throttle', 'user/mode' ] types = ['image_array', 'float', 'float', 'float', 'float', 'str'] th = TubHandler(path=cfg.DATA_PATH) tub_writer = th.new_tub_writer(inputs=inputs, types=types) V.add(tub_writer, inputs=inputs, run_condition='recording') # Run the vehicle for 20 seconds V.start(rate_hz=cfg.FPS, max_loop_count=100000) print("You can now go to <your pi ip address>:8887 to drive your car.")