Ejemplo n.º 1
0
from donkeycar.parts.camera import PiCamera

from custom_parts.HCSR04 import HCSR04
from custom_parts.ADS1115 import ADS1115
from custom_parts.BNO055_uart import BNO055
from custom_parts.AS5048A_Process import speed
from custom_parts.OLED import OLED
from custom_parts.CSVDATA import CSVDATA
from custom_parts.pulse_generator import Pulse

import donkeycar as dk

cfg = dk.load_config()
meta = []

V = Vehicle()

# hcsr04 = HCSR04()
# V.add(hcsr04, outputs=['hcsr04'], threaded=True)

ads1115 = ADS1115(coeff_m=cfg.VM_COEFFICIENT, coeff_p=cfg.VP_COEFFICIENT)
V.add(ads1115, outputs=['ads1115/vm', 'ads1115/vp'], threaded=True)

bno055 = BNO055()
V.add(bno055,
      outputs=[
          "bno055/heading", "bno055/roll", "bno055/pitch", "bno055/sys",
          "bno055/gyro", "bno055/accel", "bno055/mag", "bno055/ori_x",
          "bno055/ori_y", "bno055/ori_z", "bno055/ori_w", "bno055/temp_c",
          "bno055/mag_x", "bno055/mag_y", "bno055/mag_z", "bno055/gyr_x",
          "bno055/gyr_y", "bno055/gyr_z", "bno055/acc_x", "bno055/acc_y",
Ejemplo n.º 2
0
from donkeycar.vehicle import Vehicle
import donkeycar as dk
from donkeycar.parts.actuator import PCA9685, PWMSteering, PWMThrottle

from custom_parts.ADS1115 import ADS1115
from custom_parts.AS5048A_Process import speed
from custom_parts.SocketData import SocketData
from custom_parts.Clock import Clock
# from custom_parts.PID import PID
from custom_parts.list_generator import LPulse
from custom_parts.PID_new import PID

cfg = dk.load_config()
V = Vehicle()

sensor = ['as5048a', 'throttle', 'vm', 'vp']
parameter = ['rspeed', 'mp', 'mi', 'md', 'sp', 'si', 'sd']
setting = ['rspeed', 'mp', 'mi', 'md', 'sp', 'si', 'sd']

# time of current control step
clock = Clock()
V.add(clock, outputs=['milliseconds'])

# speed sensor
as5048a = speed()
V.add(as5048a, outputs=['as5048a'])

ads1115 = ADS1115(coeff_m=cfg.VM_COEFFICIENT, coeff_p=cfg.VP_COEFFICIENT)
V.add(ads1115, outputs=['vm', 'vp'], threaded=True)

signal_lst = [
Ejemplo n.º 3
0
from donkeycar.vehicle import Vehicle
from donkeycar.parts.tofsensor import TOFSensorPart

V = Vehicle()

tof_sensor = TOFSensorPart(2)

V.add(tof_sensor, outputs=["tof/2"]

V.start()
Ejemplo n.º 4
0
#   and the pixel radius of a circle that encloses the ball
#Part 3: Controller - Determines the PWM values to send to the ESC. For Throtttle
#   uses PI control
#Part 4,5: PWMsender - Parts that send values to the ESC.

from donkeycar.vehicle import Vehicle
from picamera.array import PiRGBArray
from picamera import PiCamera
from donkeycar.parts.actuator import PCA9685
import time
import CvCam1
import FetchFunctionsModularized as FF
import cfg2

#Setup Vehicle, PWM senders, and Camera
V = Vehicle()
steering_controller = PCA9685(cfg2.Steering_Channel)
throttle_controller = PCA9685(cfg2.Throttle_Channel)

camera = PiCamera()
camera.resolution = cfg2.Cam_Resolution
camera.framerate = cfg2.Cam_FrameRate
rawCapture = PiRGBArray(camera, size=cfg2.Cam_Resolution)

test

print('Warming Cam...')
time.sleep(.5)
print('Camera Warmed')

#Add parts to the Donkeycar Vehicle
Ejemplo n.º 5
0
from donkeycar.vehicle import Vehicle
from cvcam import CvCam, CvImageDisplay

v = Vehicle()

# Cam part
cam = CvCam()

# Need to specify outputs
v.add(cam, outputs=["camera/image"], threaded=True)

# display part
disp = CvImageDisplay()

v.add(disp, inputs=["camera/image"])

v.start()
Ejemplo n.º 6
0
from donkeycar.vehicle import Vehicle
import donkeycar as dk
from donkeycar.parts.actuator import PCA9685, PWMSteering, PWMThrottle
from custom_parts.AS5048A_Process import speed
from custom_parts.SocketData import SocketData
from custom_parts.Clock import Clock
# from custom_parts.PID import PID
from custom_parts.pulse_generator import Pulse
from custom_parts.PID_new import PID

cfg = dk.load_config()
V = Vehicle()

sensor = ['as5048a', 'throttle', 'rspeed']
parameter = ['rspeed', 'mp', 'mi', 'md', 'sp', 'si', 'sd']
setting = ['rspeed', 'mp', 'mi', 'md', 'sp', 'si', 'sd']
V.mem.put(parameter, [
    40, cfg.MOTOR_P, cfg.MOTOR_I, cfg.MOTOR_D, cfg.SERVO_P, cfg.SERVO_I,
    cfg.SERVO_D
])
# V.mem.put(['throttle'], 0.2)

# time of current control step
clock = Clock()
V.add(clock, outputs=['milliseconds'])

# speed sensor
as5048a = speed()
V.add(as5048a, outputs=['as5048a'])

# reference speed (set point)
Ejemplo n.º 7
0
def drive(cfg, goalLocation):
    """
    drive(cfg, goalLocation)

    Add GPS, Planner, and actuator parts and call DK Vehicle.py to run car.
    @param: cfg - configuration file from dk calibration
            goalLocation - list of GPS coordinates in degrees
    @return: None
    """
    # initialize vehicle
    V = Vehicle()

    # GPS is a DK part that will poll GPS data from serial port
    # and output current location in radians.
    gps = GPS(cfg.BAUD_RATE, cfg.PORT, cfg.TIMEOUT)

    # Planner is a DK part that calculates control signals to actuators based on current location
    # from GPS
    planner = Planner(goalLocation=goalLocation, steer_gain=cfg.STEERING_P_GAIN,
                        throttle_gain=cfg.THROTTLE_P_GAIN)

    # Actuators: steering and throttle
    steering_controller = PCA9685(cfg.STEERING_CHANNEL)
    steering = PWMSteering(controller=steering_controller,
                                    left_pulse=cfg.STEERING_LEFT_PWM,
                                    right_pulse=cfg.STEERING_RIGHT_PWM)

    throttle_controller = PCA9685(cfg.THROTTLE_CHANNEL)
    throttle = PWMThrottle(controller=throttle_controller,
                                    max_pulse=cfg.THROTTLE_FORWARD_PWM,
                                    zero_pulse=cfg.THROTTLE_STOPPED_PWM,
                                    min_pulse=cfg.THROTTLE_REVERSE_PWM)

    # add threaded part for gps controller
    V.add(gps, outputs=["currLocation", "prevLocation"], threaded=True)

    # add planner, actuator parts
    V.add(planner, inputs=["currLocation", "prevLocation"], outputs=["steer_cmd", "throttle_cmd"])
    V.add(steering, inputs=['steer_cmd'])
    V.add(throttle, inputs=['throttle_cmd'])

    V.start()
Ejemplo n.º 8
0
def drive(cfg):
    V = Vehicle()

    #path which is second point in parking lot 
    #path = [[32.865852, -117.21047316666667]]
    
    #path which is make circle start from first point in parking lot 
    """
    path = [
            [32.865863,-117.210494],
            [32.865870,-117.210487],
            [32.865881,-117.210474],
            [32.865888,-117.210463],
            [32.865890,-117.210460],
            [32.865895,-117.210444],
            [32.865895,-117.210432],
            [32.865880,-117.210425],
            [32.865862,-117.210423],
            [32.865849,-117.210428],
            [32.865837,-117.210440],
            [32.865826,-117.210455],
            [32.865823,-117.210457],
            [32.865818,-117.210477],
            [32.865825,-117.210497],
            [32.865828,-117.210502],
            [32.865839,-117.210508],
            [32.865855,-117.210504],
            [32.865863,-117.210495]
            ]
    """
    """
    path = [
            [32.865886333333336, -117.21044666666667],
            [32.865871166666665, -117.21044216666667],
            [32.865856666666666, -117.21045283333333],
            [ 32.86585383333333 , -117.21047116666666]
            ]

    """
    initial_location = [ 32.865891 , -117.2104515 ]
    final_location = [ 32.86583533333334 , -117.21051933333334 ]

    obstacles_location_1 = [ 32.865858333333335 , -117.21049116666667 ]
    obstacles_location_2 = [ 32.86587683333333 , -117.21046883333334 ]
    path = GPSPathFinder(initial_location, final_location, obstacles_location_1, obstacles_location_2)

    #init two new part of donkeycar
    control = Controller(path) 
    #init actuator parts which are steering and throttle

    steering_controller = PCA9685(cfg.STEERING_CHANNEL, cfg.PCA9685_I2C_ADDR, busnum=cfg.PCA9685_I2C_BUSNUM)
    steering = PWMSteering(controller=steering_controller,
                                        left_pulse=0, 
                                        right_pulse=1000)
    
    throttle_controller = PCA9685(cfg.THROTTLE_CHANNEL, cfg.PCA9685_I2C_ADDR, busnum=cfg.PCA9685_I2C_BUSNUM)
    throttle = PWMThrottle(controller=throttle_controller,
                                        max_pulse=cfg.THROTTLE_FORWARD_PWM,
                                        zero_pulse=cfg.THROTTLE_STOPPED_PWM, 
                                        min_pulse=cfg.THROTTLE_REVERSE_PWM)
    
    mode = input("Input m: manual, a: auto:")
    if mode is not 'm' and  mode is not 'a':
        print("wrong input:")
        return 
    if mode == 'm':
        gpsManualMode = GpsManualMode()
        V.add(gpsManualMode,outputs = ["latitude","longditude"])
    if mode == 'a':
        gpsPart = GpsRTK('/dev/ttyACM0',9600,1)
        V.add(gpsPart,outputs = ["latitude","longditude"],threaded = True)
    
    # add webcam to get camera image
    from donkeycar.parts.camera import Webcam
    cam = Webcam(image_w=cfg.IMAGE_W, image_h=cfg.IMAGE_H, image_d=cfg.IMAGE_DEPTH)
    inputs=['cam/image_array',
            'user/angle', 'user/throttle', 
            'user/mode']

    types=['image_array',
           'float', 'float',  
           'str']
    th = TubHandler(path=cfg.DATA_PATH)
    tub = th.new_tub_writer(inputs=inputs, types=types)

    #add parts in vehicle
    
    V.add(control, inputs = ["latitude","longditude"],outputs=["user/angle","user/throttle"])
    V.add(steering, inputs=["user/angle"])
    V.add(throttle, inputs=["user/throttle"])
    V.add(cam, outputs=['cam/image_array'], threaded=True)
    V.add(tub, inputs=inputs, run_condition='recording')
    #V.add(ReportPart(),inputs=["latitude","longditude","user/angle","user/throttle"])
    
    print("Start...")
    V.start()
def drive(cfg):
    """
    drive(cfg, goalLocation)

    Add GPS, Planner, and actuator parts and call DK Vehicle.py to run car.
    @param: cfg - configuration file from dk calibration
            goalLocation - list of GPS coordinates in degrees
    @return: None
    """
    # initialize vehicle
    V = Vehicle()

    # GPS is a DK part that will poll GPS data from serial port
    # and output current location in radians.
    #gps = GPS(cfg.BAUD_RATE, cfg.PORT, cfg.TIMEOUT)

    # IMU addition
    imu = IMU()

    # Planner is a DK part that calculates control signals to actuators based on current location
    # from GPS
    planner = Planner(steer_gain=cfg.STEERING_P_GAIN,
                      throttle_gain=cfg.THROTTLE_P_GAIN)

    # Actuators: steering and throttle
    steering_controller = PCA9685(cfg.STEERING_CHANNEL, busnum=1)
    steering = PWMSteering(controller=steering_controller,
                           left_pulse=cfg.STEERING_LEFT_PWM,
                           right_pulse=cfg.STEERING_RIGHT_PWM)

    throttle_controller = PCA9685(cfg.THROTTLE_CHANNEL, busnum=1)
    throttle = PWMThrottle(controller=throttle_controller,
                           max_pulse=cfg.THROTTLE_FORWARD_PWM,
                           zero_pulse=cfg.THROTTLE_STOPPED_PWM,
                           min_pulse=cfg.THROTTLE_REVERSE_PWM)

    # add threaded part for gps controller
    #V.add(gps, outputs=["currLocation", "prevLocation"], threaded=True)

    #TODO replace with CvCam code
    ultrasonic = Ultrasonic()
    V.add(ultrasonic, outputs=['stop_cmd'], threaded=True)

    #Team2 addition
    #add OpenCV camera part. Outputs a stop command if shape is detected
    #cvcam = CVCam()
    #V.add(cvcam, outputs=['stop_cmd'], threaded=True)

    V.add(imu, outputs=['heading'], threaded=True)

    #desired heading part
    d_head = Trajectory()
    V.add(d_head, outputs=['desired_heading'], threaded=True)

    # add planner, actuator parts
    V.add(planner,
          inputs=['heading', 'desired_heading', 'stop_cmd'],
          outputs=["steer_cmd", "throttle_cmd"])
    V.add(steering, inputs=['steer_cmd'])
    V.add(throttle, inputs=['throttle_cmd'])

    V.start()
Ejemplo n.º 10
0
from donkeycar.vehicle import Vehicle
from donkeycar.parts.actuator import PCA9685, PWMSteering, PWMThrottle

from custom_parts.ADS1115 import ADS1115
from custom_parts.BNO055 import BNO055
from custom_parts.AS5048A_Process import speed
from custom_parts.OLED import OLED
from custom_parts.CSVDATA import CSVDATA
from custom_parts.pulse_generator import Pulse

import donkeycar as dk

cfg = dk.load_config()
meta = []
V = Vehicle()

pulse = Pulse(interval=4, cycle=0.5, length=20, min=0.0, max=0.3)
V.add(pulse, outputs=['user/throttle', 'recording'])


throttle_controller = PCA9685(cfg.THROTTLE_CHANNEL, cfg.PCA9685_I2C_ADDR, busnum=cfg.PCA9685_I2C_BUSNUM)
throttle = PWMThrottle(controller=throttle_controller,
                       max_pulse=cfg.THROTTLE_FORWARD_PWM,
                       zero_pulse=cfg.THROTTLE_STOPPED_PWM,
                       min_pulse=cfg.THROTTLE_REVERSE_PWM)
V.add(throttle, inputs=['user/throttle'])


ads1115 = ADS1115(coeff_m=cfg.VM_COEFFICIENT, coeff_p=cfg.VP_COEFFICIENT)
V.add(ads1115, outputs=['ads1115/vm', 'ads1115/vp'], threaded=True)
Ejemplo n.º 11
0
from donkeycar.vehicle import Vehicle
from donkeycar.parts.controller import JoystickController, PS3JoystickController
from donkeycar.parts.throttle_filter import ThrottleFilter
from donkeycar.parts.transform import Lambda
from picamera.array import PiRGBArray
from picamera import PiCamera
from donkeycar.parts.actuator import PCA9685
import time
import Cam
import mod as FF
import cfg2

#Setup Vehicle, PWM senders, and Camera
V = Vehicle()
steering_controller = PCA9685(cfg2.Steering_Channel)
throttle_controller = PCA9685(cfg2.Throttle_Channel)

camera = PiCamera()
camera.resolution = cfg2.Cam_Resolution
camera.framerate = cfg2.Cam_FrameRate
rawCapture = PiRGBArray(camera, size=cfg2.Cam_Resolution)

#Setup Controller

cont_class = PS3JoystickController
ctr = cont_class(throttle_scale=cfg2.JOYSTICK_MAX_THROTTLE,
                 steering_scale=cfg2.JOYSTICK_STEERING_SCALE,
                 auto_record_on_throttle=cfg2.AUTO_RECORD_ON_THROTTLE)
print('Warming Cam...')
time.sleep(.5)
print('Camera Warmed')
Ejemplo n.º 12
0
def drive(cfg, goalLocation):
    """
    drive(cfg, goalLocation)

    Add GPS, Planner, and actuator parts and call DK Vehicle.py to run car.
    @param: cfg - configuration file from dk calibration
            goalLocation - list of GPS coordinates in degrees
    @return: None
    """
    # initialize vehicle
    V = Vehicle()

    # GPS is a DK part that will poll GPS data from serial port
    # and output current location in radians.
    #gps = GPS(cfg.BAUD_RATE, cfg.PORT, cfg.TIMEOUT)
    #dmp = DMP()#TODO)

    # Planner is a DK part that calculates control signals to actuators based on current location
    # from GPS
    planner = Planner(goalLocation=goalLocation)

    # Actuators: steering and throttle
    steering_controller = PCA9685(cfg.STEERING_CHANNEL)
    steering = PWMSteering(controller=steering_controller,
                                    left_pulse=cfg.STEERING_LEFT_PWM,
                                    right_pulse=cfg.STEERING_RIGHT_PWM)

    throttle_controller = PCA9685(cfg.THROTTLE_CHANNEL)
    throttle = PWMThrottle(controller=throttle_controller,
                                    max_pulse=cfg.THROTTLE_FORWARD_PWM,
                                    zero_pulse=cfg.THROTTLE_STOPPED_PWM,
                                    min_pulse=cfg.THROTTLE_REVERSE_PWM)

    # add threaded part for gps controller
    # We no longer need the GPS to output previous location
    #V.add(gps, outputs=["currLocation"], threaded=True)
    
    #the DMP in the IMU should return the bearing relative to North
    # TODO - implement this part...
    #V.add(dmp, outputs=["bearing_angle"], threaded=True)

    #the ultrasonics will tell you whether you need to stop
    #True means stop, False means go
    # This part should be good to go - Saurabh
    ultrasonic = HCSR04()
    V.add(ultrasonic, outputs=['stop_cmd'], threaded=True)

    # add planner, actuator parts
    # Previous location is no longer needed
    # Instead, use actual bearing from DMP
    # It also takes in stop_cmd, a boolean indicating whether to stop
    # in which case it reverts to "STOPPED_PWM"
    #V.add(planner, inputs=["currLocation", "bearing_angle", "stop_cmd"], 
    #        outputs=["steer_cmd", "throttle_cmd"])
    V.add(planner, inputs=["stop_cmd"], 
            outputs=["steer_cmd", "throttle_cmd"])

    #steer_cmd is a pwm value
    V.add(steering, inputs=['steer_cmd'])
    # throttle takes in a throttle_cmd pwm value,
    V.add(throttle, inputs=['throttle_cmd'])

    V.start()
Ejemplo n.º 13
0
from donkeycar.vehicle import Vehicle
import numpy as np
from donkeycar.parts.datastore import TubHandler
from tensorflow.keras.preprocessing.image import img_to_array
from imutils import paths
import cv2
import os
import time

V = Vehicle()


class foto(object):
    def __init__(self):

        print('start foto...')
        self.angle = 0.0
        self.throttle = 0.0
        self.image_array = None
        self.mode = 'user'
        self.data = []
        self.labels = []
        self.idx = 0
        self.recording = False
        self.vehicle = None
        self.running = True
        self.imagePaths = sorted(list(paths.list_images('./mycar/phot')))
        # print(self.imagePaths)
        # loop over the input images
        for imagePath in self.imagePaths:
            # load the image, pre-process it, and store it in the data list
Ejemplo n.º 14
0
def drive(cfg, goalLocation):
    """
    drive(cfg, goalLocation)

    Add GPS, Planner, and actuator parts and call DK Vehicle.py to run car.
    @param: cfg - configuration file from dk calibration
            goalLocation - list of GPS coordinates in degrees
    @return: None
    """
    # initialize vehicle
    V = Vehicle()

    ctr = LocalWebController()

    speedPID = PIDController(p=0.03, i=0, d=0, f=0.13)

    # GPS is a DK part that will poll GPS data from serial port
    # and output current location in radians.
    gps = RTKGPS()
    personFinder = PersonFinder(steer_gain=0.5, distance_calibration=466)
    gpsHeading = GPSHeading(3)
    gpsSpeed = Speedometer(speedPID)

    # Planner is a DK part that calculates control signals to actuators based on current location
    # from GPS
    planner = KiwiPlanner(goalLocation=goalLocation,
                          steer_gain=cfg.STEERING_P_GAIN,
                          throttle_gain=cfg.THROTTLE_P_GAIN,
                          speedPID=speedPID)

    # Actuators: steering and throttle
    steering_controller = PCA9685(1, 0x40, busnum=1)
    steering = PWMSteering(controller=steering_controller,
                           left_pulse=310,
                           right_pulse=465)

    throttle_controller = PCA9685(2, 0x40, busnum=1)
    throttle = PWMThrottle(controller=throttle_controller,
                           max_pulse=460,
                           zero_pulse=370,
                           min_pulse=330)

    mixer = Mixer()

    from donkeycar.parts.camera import Webcam
    cam = Webcam(image_w=400, image_h=300, image_d=3)

    V.add(cam, inputs=[], outputs=['cam/img'], threaded=True)

    V.add(personFinder,
          inputs=["cam/img"],
          outputs=["steer_cmd_person", "person_throttle", "proc/img"],
          threaded=True)

    # add threaded part for gps controller
    # We no longer need the GPS to output previous location
    V.add(gps, outputs=["currLocation", "prevLocation"], threaded=True)
    V.add(gpsHeading, inputs=["currLocation"], outputs=["heading"])
    V.add(gpsSpeed, inputs=["currLocation"], outputs=["speed"])

    # add planner, actuator parts
    # Previous location is no longer needed
    # Instead, use actual bearing from DMP
    # It also takes in stop_cmd, a boolean indicating whether to stop
    # in which case it reverts to "STOPPED_PWM"
    V.add(planner,
          inputs=["currLocation", "heading"],
          outputs=["steer_cmd_planner", "planner_throttle"])

    V.add(mixer,
          inputs=[
              "steer_cmd_person", "steer_cmd_planner", "person_throttle",
              "planner_throttle"
          ],
          outputs=["steer_cmd", "throttle_cmd"])

    #steer_cmd is a pwm value
    V.add(steering, inputs=['steer_cmd'])
    # throttle takes in a throttle_cmd pwm value,
    V.add(throttle, inputs=['throttle_cmd'])

    V.add(ctr,
          inputs=['proc/img'],
          outputs=['user/angle', 'user/throttle', 'user/mode', 'recording'],
          threaded=True)

    print(
        "You can now go to <your jetson's hostname.local>:8887 to view your car's camera."
    )

    V.start()
Ejemplo n.º 15
0
import donkeycar as dk
from donkeycar.vehicle import Vehicle
from lanedetection import LanesDetector

cfg = dk.load_config(config_path='./config.py')

print(cfg.LD_PARAMETERS["videofile_in"])

V = Vehicle()
laneDetector = LanesDetector(cfg.CAMERA_ID)

V.add(laneDetector)

V.start()
Ejemplo n.º 16
0
#import parts
from donkeycar.vehicle import Vehicle
from donkeycar.parts.actuator import PCA9685  #PWM motor controller
from picamera.array import PiRGBArray
from picamera import PiCamera

#import essential functions from cvCam
import time
import cfg
import cvCam
import convoyController

#Make new Vehicle
V = Vehicle()

#Make PiCamera Available
camera = PiCamera()
camera.resolution = cfg.CAMERA_RESOLUTION
camera.framerate = cfg.CAMERA_FRAMERATE
rawCapture = PiRGBArray(camera, size=cfg.CAMERA_RESOLUTION)
print('Made a new PiCamera')

time.sleep(.5)
print('Camera Ready')

#Keep Getting the Images through PiCamera and returning frames
cam = cvCam.CvCamCamera(camera, rawCapture)
V.add(cam, outputs=["camera/image"], threaded=False)
print('Added Camera')

#Make Display Available and Add to the Car