def setup():
    global api, bw, fw, buzzer, led_green, led_red, mqtt_distance, mqtt_speed, ua

    # 1. PiCar setup.
    picar.setup()
    ua = Ultrasonic_Avoidance.Ultrasonic_Avoidance(20)
    fw = front_wheels.Front_Wheels(db='config')
    bw = back_wheels.Back_Wheels(db='config')
    fw.turning_max = 45

    # 2. GPIO pins for buzzer and LED.
    GPIO.setmode(GPIO.BCM)  # GPIO.BCM mode.
    GPIO.setup(PIN_BUZZER, GPIO.OUT)  # Buzzer pin.
    GPIO.setup(PIN_LED, GPIO.OUT)  # LED pins.
    GPIO.output(PIN_LED, GPIO.LOW)  # Set LED pins to low to turn off LEDs.
    buzzer = GPIO.PWM(PIN_BUZZER, 440)  # Set buzzer frequency to 440Hz.
    led_red = GPIO.PWM(PIN_LED[0], 2000)  # Set LED frequencies to 2KHz.
    led_green = GPIO.PWM(PIN_LED[1], 2000)
    buzzer.start(0)
    led_red.start(0)
    led_green.start(0)

    # 3. Ubidots.
    api = ApiClient(token='A1E-priJupwmfAGtVeOjcslK9wAW16HJzO')
    mqtt_distance = api.get_variable('59e93a20c03f9748c6bc3d54')
    mqtt_speed = api.get_variable('5a092816c03f9706c0205e88')
Beispiel #2
0
    def __init__(self):
        picar.setup()
        self.camera = cv2.VideoCapture(-1)
        self.fourcc = cv2.VideoWriter_fourcc(*'XVID')
        # self.capture_out = cv2.VideoWriter("")
        # self.angles_fname = ""

        self.camera.set(3, self.__SCREEN_WIDTH)
        self.camera.set(4, self.__SCREEN_HEIGHT)
        self.pan_servo = picar.Servo.Servo(1)
        self.pan_servo.offset = -40  # calibrate servo to center (left, right)
        self.pan_servo.write(90)

        self.tilt_servo = picar.Servo.Servo(2)
        self.tilt_servo.offset = -120  # calibrate servo to center (up, down)
        self.tilt_servo.write(90)

        logging.debug('Set up back wheels')
        self.back_wheels = picar.back_wheels.Back_Wheels()
        self.back_wheels.speed = 0  # Speed Range is 0 (stop) - 100 (fastest)

        logging.debug('Set up front wheels')
        self.front_wheels = picar.front_wheels.Front_Wheels()
        self.front_wheels.turning_offset = 20  # calibrate servo to center
        self.front_wheels.turn(
            90)  # Steering Range is 45 (left) - 90 (center) - 135 (right)
def main():
    picar.setup()
    controller = PiCarController()

    # Collect events until released
    with Listener(on_press=on_press, on_release=on_release) as listener:
        listener.join()
Beispiel #4
0
    def __init__(self, TimeToSteer = 6, LogInfo = False,forwardSpeed = 40,turnSpeed = 35, confidenceNeeded = 0.90,InitCar = True,distanceToTurn =  50,
    distanceToDetectMin = 15, distanceToDetectMax = 70):

# Αρχικοποίηση κινητήρων
        if(InitCar):
            picar.setup()

        self.bw = back_wheels.Back_Wheels()

        self.fw = front_wheels.Front_Wheels()
    
        self.PreviousState = RobotState.Initial
        self.State = RobotState.Initial
        self.NNState = NeuralNetWorkRead.Unknown
        self.distance = 0
        self.confidence = 0
        self.confidenceNeeded = confidenceNeeded
        self.lastTime = time.time()
        self.curTime = time.time()
        self.timeDif = 0
        self.distanceToTurn = distanceToTurn
        self.TimeToSteer = TimeToSteer
        self.FolderName = time.strftime("%Y%m%d-%H%M%S")
        self.LogInfo = LogInfo
        self.count = 0
        self.forwardSpeed = forwardSpeed
        self.turnSpeed = turnSpeed
        self.distanceToDetectMin = distanceToDetectMin
        self.distanceToDetectMax = distanceToDetectMax
        self.lastLog = 0
        if(LogInfo):
            self.logger = logging.getLogger('./' + self.FolderName +'/logs.txt')
            fh = logging.FileHandler(self.FolderName + '.html',mode = "w")
            self.logger.setLevel(logging.INFO)
            self.logger.addHandler(fh)
Beispiel #5
0
    def __init__(self,
                 max_steer=40,
                 max_speed=90,
                 unit_converter=None,
                 configfile="config",
                 virtual=False,
                 virtual_verbose=False,
                 initialize=True):
        # Use virtual libraries if requested (so we don't get GPIO errors for not running on a Pi)
        if not virtual:
            import picar
            from picar.front_wheels import Front_Wheels
            from picar.back_wheels import Back_Wheels
            picar.setup()
            self.fw = Front_Wheels(db=configfile)
            self.bw = Back_Wheels(db=configfile)
        else:
            from virtual_wheels import Virtual_Front_Wheels as Front_Wheels
            from virtual_wheels import Virtual_Back_Wheels as Back_Wheels
            self.fw = Front_Wheels(db=configfile, verbose=virtual_verbose)
            self.bw = Back_Wheels(db=configfile, verbose=virtual_verbose)

        if unit_converter is None:
            unit_converter = HardwareUnitConverter(
                speed_slope=1,
                angle_slope=1)  # Assume 1:1 unit relationship by default
        self.unit_converter = unit_converter  # HardwareUnitConverter class

        self.fw.max_turn = max_steer  # Max turn radius
        self.max_speed = max_speed
        self.max_steer = max_steer

        if initialize:
            self.initialize()
    def __init__(self):
        picar.setup()
        self.fw = front_wheels.Front_Wheels(db='config')
        self.bw = back_wheels.Back_Wheels(db='config')

        self.bw.speed = 70
        self.fw.turning_max = 45

        self.forward_speed = 90
        self.backward_speed = 70

        self.back_distance = 10
        self.turn_distance = 20
        self.straight = 90

        self.movement_dispatch = dict()
        self.movement_dispatch[self.FORWARD] = self.accelerate
        self.movement_dispatch[self.BACKWARD] = self.decelerate
        self.movement_dispatch[self.LEFT] = self.turn_left
        self.movement_dispatch[self.RIGHT] = self.turn_right

        self.movement_reset = dict()
        self.movement_reset[self.FORWARD] = self.stop
        self.movement_reset[self.BACKWARD] = self.stop
        self.movement_reset[self.LEFT] = self.turn_straight
        self.movement_reset[self.RIGHT] = self.turn_straight

        self.key_map = dict()

        self.bw.stop()
Beispiel #7
0
    def __init__(
            self,
            max_turn=45,
            configfile="config",
            L=0.145,
            # kpr=1, kpa=0, kpb=0, kdr=0, kda=0, kdb=0, kir=0, kia=0, kib=0,
            # controllers=lambda x: x, min_dt=0.005,
            max_picar_speed=80,
            max_picar_turn=40,
            virtual=False,
            verbose=False,
            virtual_speedverbose=False):

        self.verbose = verbose

        # Use virtual libraries if requested (so we don't get GPIO errors for not running on a Pi)
        if not virtual:
            import picar
            from picar.front_wheels import Front_Wheels
            from picar.back_wheels import Back_Wheels
            picar.setup()
            self._fw = Front_Wheels(db=configfile)
            self._bw = Back_Wheels(db=configfile)
        else:
            from virtual_wheels import Virtual_Front_Wheels as Front_Wheels
            from virtual_wheels import Virtual_Back_Wheels as Back_Wheels
            self._fw = Front_Wheels(db=configfile,
                                    verbose=virtual_speedverbose)
            self._bw = Back_Wheels(db=configfile, verbose=virtual_speedverbose)

        # Wheel base [m]
        self._L = L
        # Max turn radius
        self._fw.max_turn = max_picar_turn
        # Initialize wheels
        self._speed = 0  # from 0-100
        self._steering = 0  # initalize at no turn angle
        self._direction = 1  # wheels set forward
        self._fw.ready()
        self._bw.ready()
        self._bw.forward()

        # Controllers for calculating control signals
        # self.controller = MyPicarController(v_controllers, gamma_controllers)
        # self._rhomyPID   = myPID(Kp=kpr, Ki=kir, Kd=kdr)
        # self._alphamyPID = myPID(Kp=kpa, Ki=kia, Kd=kda)
        # self._betamyPID  = myPID(Kp=kpb, Ki=kib, Kd=kdb)

        # Set maximum values of control signals -- IN PICAR UNITS (e.g. degrees, not radians)
        self.MAX_PICAR_SPEED = max_picar_speed
        self.MAX_PICAR_TURN = max_picar_turn

        # Minimum loop delay
        # self.min_dt = min_dt

        # Initialize WorldState and BicycleModel
        self._my_cartesian_pose = CartesianPose(0, 0, 0)
        self._goal_cartesian_pose = CartesianPose(0, 0, 0)
        self._my_bicycle_model = BicycleModel(rho=0, alpha=0, beta=0)
Beispiel #8
0
 def __init__(self):
     picar.setup()
     self.is_stopped = False
     self.bw = back_wheels.Back_Wheels()
     self.fw = front_wheels.Front_Wheels()
     self.motor_speed = 0
     self.turning_direction = ""
     self.angle = self.DEFAULT_ANGLE
Beispiel #9
0
 def __init__(self):
     picar.setup()
     db_file = "autonomous_car/picar_v/config"
     self.fw = front_wheels.Front_Wheels(debug=False, db=db_file)
     self.bw = back_wheels.Back_Wheels(debug=False, db=db_file)
     self.bw.ready()
     self.fw.ready()
     self.bw_status = 0
Beispiel #10
0
 def __init__(self):
     self.fw = front_wheels.Front_Wheels(debug=True)
     self.max_right = 135
     self.max_left = 45
     self.straight = 90
     self.current_angle = 90
     self.direction = 1
     self.delta = 5  # number of degrees per turn
     picar.setup()
    def __init__(self):
        picar.setup()
        self.camera = cv2.VideoCapture(-1)
        self.camera.set(3, self.__SCREEN_WIDTH)
        self.camera.set(4, self.__SCREEN_HEIGHT)
        self.pan_servo = picar.Servo.Servo(1)
        self.pan_servo.offset = -40  # calibrate servo to center (left, right)
        self.pan_servo.write(90)

        self.tilt_servo = picar.Servo.Servo(2)
        self.tilt_servo.offset = -120  # calibrate servo to center (up, down)
        self.tilt_servo.write(90)
    def __init__(
        self,
        camero=None,
    ):
        """ Init camera and wheels"""
        logging.info('Creating a DeepPiCar...')
        #jimmy setup motor: chnnel 0 for front whell ,1 for( horizontal) ultra,2 for (vitical) camera
        #GPIO.setwarnings(False)
        #GPIO.setmode(GPIO.BOARD)

        #turn.ahead()
        picar.setup()
        #linsensorsetup()

        logging.debug('Set up camera')
        if camero == None:
            self.camera = cv2.VideoCapture(-1)
        else:
            self.camera = camero
        #self.camera.set(3, self.__SCREEN_WIDTH)
        #self.camera.set(4, self.__SCREEN_HEIGHT)

        #self.pan_servo = picar.Servo.Servo(1)
        #self.pan_servo.offset = -30  # calibrate servo to center
        #self.pan_servo.write(90)

        #self.tilt_servo = picar.Servo.Servo(2)
        #self.tilt_servo.offset = 20  # calibrate servo to center
        #self.tilt_servo.write(90)

        logging.debug('Set up back wheels')
        #self.back_wheels = picar.back_wheels.Back_Wheels()
        #self.back_wheels.speed = 30  # Speed Range is 0 (stop) - 100 (fastest)
        #self.back_wheels.forward()
        #self.back_wheels.backward()

        logging.debug('Set up front wheels')
        #self.front_wheels = picar.front_wheels.Front_Wheels()
        #self.front_wheels.turning_offset = -25  # calibrate servo to center
        #self.front_wheels.turn(90)  # Steering Range is 45 (left) - 90 (center) - 135 (right)

        self.lane_follower = HandCodedLaneFollower(self)
        self.traffic_sign_processor = ObjectsOnRoadProcessor(self)
        # lane_follower = DeepLearningLaneFollower()

        self.fourcc = cv2.VideoWriter_fourcc(*'XVID')
        datestr = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
        #self.video_orig = self.create_video_recorder('/home/pi/data/tmp/car_video%s.avi' % datestr)
        self.video_lane = self.create_video_recorder(
            '/home/pi/data/tmp/car_video_lane%s.avi' % datestr)
        #self.video_objs = self.create_video_recorder('/home/pi/data/tmp/car_video_objs%s.avi' % datestr)

        logging.info('Created a DeepPiCar')
Beispiel #13
0
    async def start(self):
        loop = asyncio.get_running_loop()

        transport, protocol = await loop.create_datagram_endpoint(
            lambda: DatagramEndpointInterface(self.message_handler),
            local_addr=(self.address, self.port))

        picar.setup()
        self.camera_controls.ready()
        self.back_wheels.ready()
        self.front_wheels.ready()
        self.transport = transport
        print('CommandsServer - Running on', self.address, self.port)
Beispiel #14
0
 def __init__(self):
     picar.setup() 
     self.bw=picar.back_wheels.Back_Wheels()
     self.fw=picar.front_wheels.Front_Wheels()
     self.fw.turning_max=40 
     self.fw.offset=0 
     self.bw.speed=0
     self.fw.turn(90)
     self.calib_mode=False
     self.observe("calib_start", self.calib_start)
     self.observe("calib_stop", self.calib_stop)
     self.observe("calib_left", self.cali_left)
     self.observe("calib_right", self.cali_right)
Beispiel #15
0
    def __init__(self):
        self.music = playmusic.MUSIC()

        self.steer_count = 0
        """ Init camera and wheels"""
        logging.info('Creating a DeepPiCar...')

        picar.setup()

        logging.debug('Set up back wheels')
        self.fw = front_wheels.Front_Wheels(db='config')
        self.bw = back_wheels.Back_Wheels(db='config')
        self.bw.speed = DEFAULT_SPEED
    def __init__(self, test_mode=False):
        self._test_mode = False if test_mode is False else True
        self._controller = InputController()

        db_file = "config"
        picar.setup()

        self.fw = front_wheels.Front_Wheels(debug=False, db=db_file)
        self.bw = back_wheels.Back_Wheels(debug=False, db=db_file)

        self.bw.ready()
        self.fw.ready()

        self.fw.calibration()
Beispiel #17
0
    def __init__(self, max_turn=45, configfile="config", L=0.145,
                    kpr=1, kpa=0, kpb=0, kdr=0, kir=0,
                    max_picar_speed=80, max_picar_turn=40,
                    virtual=False, min_dt=0.005, verbose=False, virtual_verbose=False):

        self.verbose = verbose

        # Use virtual libraries if requested (so we don't get GPIO errors for not running on a Pi)
        if not virtual:
            import picar
            from picar.front_wheels import Front_Wheels
            from picar.back_wheels import Back_Wheels
            picar.setup()
            self._fw = Front_Wheels(db=configfile)
            self._bw = Back_Wheels(db=configfile)
        else:
            from virtual_wheels import Virtual_Front_Wheels as Front_Wheels
            from virtual_wheels import Virtual_Back_Wheels as Back_Wheels
            self._fw = Front_Wheels(db=configfile, verbose=virtual_verbose)
            self._bw = Back_Wheels(db=configfile, verbose=virtual_verbose)

        # Wheel base [m]
        self._L = L        
        # Max turn radius
        self._fw.max_turn = max_turn # [deg]  In picar's world; in reality 45 maps to around 40, etc
        # Initialize wheels
        self._v= 0      # from 0-100
        self._gamma = 0     # initalize at forward
        self._direction = 1
        self._fw.ready()
        self._bw.ready()
        self._bw.forward()

        # PID controllers for parameters
        self._rhoPID   = PID(Kp=kpr, Ki=kir, Kd=kdr)
        self._alphaPID = PID(Kp=kpa)
        self._betaPID  = PID(Kp=kpb)

        # Set maximum values of control signals -- IN PICAR UNITS (e.g. degrees, not radians)
        self.MAX_PICAR_SPEED = max_picar_speed
        self.MAX_PICAR_TURN = max_picar_turn

        # Minimum loop delay
        self.min_dt = min_dt

        # Initialize WorldState and BicycleModel
        self._my_worldstate   = WorldState(0,0,0)
        self._goal_worldstate = WorldState(0,0,0)
        self._BM = BicycleModel(0,0,0)
Beispiel #18
0
def test():
	import picar
	picar.setup()
	
	camera = Camera_Control(debug = True)
	try:
		while True:
	
			test_pan_angle = input("Enter a pan value: ")
			test_tilt_angle = input("Enter a tilt value: ")
		
			camera.pan_to(test_pan_angle)
			camera.tilt_to(test_tilt_angle)
	except KeyboardInterrupt:
		camera.pan_straight()
		camera.tilt_flat()
    def __init__(self):
        picar.setup()

        self.camera = cv2.VideoCapture(-1)
        self.camera.set(3, self.img_width)
        self.camera.set(4, self.img_height)

        self.back_wheels = picar.back_wheels.Back_Wheels()
        self.back_wheels.forward()
        self.back_wheels.speed = 0

        self.front_wheels = picar.front_wheels.Front_Wheels()
        self.front_wheels.turn(90)

        self.detect_traffic_objects = DetectObjectsOnRoad(self)

        self.calculate_steering_angle = CalculateSteering(self)
Beispiel #20
0
    def __init__(self, debug=False):
        try:
            from picar import front_wheels
            from picar import back_wheels
            import picar
        except ImportError:
            # the Picar moduls are not available,
            # most likely due to the code running outside the Raspberry Pi
            raise PicarModulesUnavailableException

        picar.setup()
        # ua = Ultrasonic_Avoidance.Ultrasonic_Avoidance(20)
        self.fw = front_wheels.Front_Wheels(db='config')
        # self.fw.turning_max = 45
        self.fw.debug = debug

        self.bw = back_wheels.Back_Wheels(db='config')
        self.bw.debug = debug
    def __init__(self):
        """ Init camera and wheels"""
        logging.info('Creating a DeepPiCar...')

        picar.setup()

        logging.debug('Set up camera')
        self.camera = cv2.VideoCapture(-1)
        self.camera.set(3, self.__SCREEN_WIDTH)
        self.camera.set(4, self.__SCREEN_HEIGHT)
        #Unneeded Removed these servos
        #self.pan_servo = picar.Servo.Servo(1)
        #self.pan_servo.offset = -30  # calibrate servo to center
        #self.pan_servo.write(90)

        #self.tilt_servo = picar.Servo.Servo(2)
        #self.tilt_servo.offset = 20  # calibrate servo to center
        #self.tilt_servo.write(90)

        logging.debug('Set up back wheels')
        self.back_wheels = picar.back_wheels.Back_Wheels()
        self.back_wheels.speed = 0  # Speed Range is 0 (stop) - 100 (fastest)

        logging.debug('Set up front wheels')
        self.front_wheels = picar.front_wheels.Front_Wheels()
        self.front_wheels.turning_offset = 15  # calibrate servo to center
        self.front_wheels.turn(
            90)  # Steering Range is 45 (left) - 90 (center) - 135 (right)

        #add later mode select with conditional ifs
        self.lane_follower = ManualDriveLaneFollower(self)
        #self.traffic_sign_processor = ObjectsOnRoadProcessor(self)
        #lane_follower = DeepLearningLaneFollower()

        self.fourcc = cv2.VideoWriter_fourcc(*'XVID')
        datestr = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
        self.video_orig = self.create_video_recorder(
            '../data/car_video%s.avi' % datestr)
        self.video_lane = self.create_video_recorder(
            '../data/car_video_lane%s.avi' % datestr)
        self.video_objs = self.create_video_recorder(
            '../data//car_video_objs%s.avi' % datestr)

        logging.info('Created a DeepPiCar')
Beispiel #22
0
    def __init__(self):
        """
        Starts and calibrates PiCar's servos
        """
        logging.info('Configuring Herbie')

        picar.setup()

        logging.debug('Configuring Camera')
        self.camera = cv2.VideoCapture(-1)
        self.camera.set(3, self.__SCREEN_WIDTH)
        self.camera.set(4, self.__SCREEN_HEIGHT)

        self.pan_servo = picar.Servo.Servo(1, bus_number=1)
        self.pan_servo.offset = -30  # calibrate servo to center
        self.pan_servo.write(90)

        self.tilt_servo = picar.Servo.Servo(1, bus_number=1)
        self.tilt_servo.offset = 20  # calibrate servo to center
        self.tilt_servo.write(90)

        logging.debug('Calibrating Rear Wheels')
        self.rear_wheels = picar.back_wheels.Back_Wheels()
        self.rear_wheels.speed = 0  # Speed Range is 0 (stop) - 100 (fastest)

        logging.debug('Calibrating Front Wheels')
        self.front_wheels = picar.front_wheels.Front_Wheels()
        self.front_wheels.turning_offset = -25  # calibrate servo to center
        self.front_wheels.turn(
            90)  # Steering Range is 45 (left) - 90 (center) - 135 (right)

        self.lane_follower = LaneKeepAssistSystem(self)
        #self.lane_follower = DeepLearningLKAS(self)

        self.fourcc = cv2.VideoWriter_fourcc(*'XVID')
        datestr = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
        self.video_orig = self.create_video_recorder(
            '../data/tmp/car_video%s.avi' % datestr)
        self.video_lane = self.create_video_recorder(
            '../data/tmp/car_video_lane%s.avi' % datestr)
        self.video_objs = self.create_video_recorder(
            '../data/tmp/car_video_objs%s.avi' % datestr)

        logging.info('Herbie Configuration Complete')
Beispiel #23
0
def setup():
    global fw, bw, cam, SPEED, bw_status, is_setup
    if is_setup == True:
        return
    from .picar_v_video_stream import Vilib
    picar.setup()
    db_file = "/home/pi/SunFounder_PiCar-V/remote_control/remote_control/driver/config"
    fw = front_wheels.Front_Wheels(debug=False, db=db_file)
    bw = back_wheels.Back_Wheels(debug=False, db=db_file)
    cam = camera.Camera(debug=False, db=db_file)
    cam.ready()
    bw.ready()
    fw.ready()

    Vilib.camera_start()

    SPEED = 60
    bw_status = 0
    is_setup = True
Beispiel #24
0
    def __init__(self):
        """ Init camera and wheels"""
        logging.info('Creating a DeepPiCar...')

        picar.setup()

        logging.debug('Set up camera')
        self.camera = cv2.VideoCapture(-1)
        self.camera.set(3, self.__SCREEN_WIDTH)
        self.camera.set(4, self.__SCREEN_HEIGHT)

        self.pan_servo = picar.Servo.Servo(1)
        self.pan_servo.offset = -30  # calibrate servo to center
        self.pan_servo.write(90)

        self.tilt_servo = picar.Servo.Servo(2)
        self.tilt_servo.offset = 20  # calibrate servo to center
        self.tilt_servo.write(90)

        logging.debug('Set up back wheels')
        self.back_wheels = picar.back_wheels.Back_Wheels()
        self.back_wheels.speed = 0  # Speed Range is 0 (stop) - 100 (fastest)

        logging.debug('Set up front wheels')
        self.front_wheels = picar.front_wheels.Front_Wheels()
        self.front_wheels.turning_offset = -25  # calibrate servo to center
        self.front_wheels.turn(
            90)  # Steering Range is 45 (left) - 90 (center) - 135 (right)

        self.lane_follower = HandCodedLaneFollower(self)

        # lane_follower = DeepLearningLaneFollower()

        self.fourcc = cv2.VideoWriter_fourcc(*'XVID')
        datestr = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
        self.video_orig = self.create_video_recorder(
            '../data/tmp/car_video%s.avi' % datestr)
        self.video_lane = self.create_video_recorder(
            '../data/tmp/car_video_lane%s.avi' % datestr)
        self.video_objs = self.create_video_recorder(
            '../data/tmp/car_video_objs%s.avi' % datestr)

        logging.info('Created a DeepPiCar')
    def __init__(self):
        picar.setup()

        self.REFERENCES = [20.5, 25.0, 28.0, 21.5, 20.5]
        # self.calibrate = True
        self.calibrate = False
        self.forward_speed = 40
        self.turning_angle = 45

        self.delay = 0.0005

        self.fw = front_wheels.Front_Wheels(db='config')
        self.bw = back_wheels.Back_Wheels(db='config')
        self.lf = Line_Follower.Line_Follower()

        self.lf.references = self.REFERENCES
        self.fw.ready()
        self.bw.ready()
        self.fw.turning_max = 60
Beispiel #26
0
def main():
    print('STARTING CAR')

    picar.setup()
    db_file = "/home/pi/SunFounder_PiCar-V/remote_control/remote_control/driver/config"
    fw = front_wheels.Front_Wheels(debug=True, db=db_file)
    bw = back_wheels.Back_Wheels(debug=True, db=db_file)
    cam = camera.Camera(debug=True, db=db_file)
    cam.ready()
    bw.ready()
    fw.ready()
    cv2Cam = cv2.VideoCapture(0)

    # bw.speed = 20
    turn_cam_down(cam)
    current_state = 'straight'

    while True:
        print('TAKING PIC')
        np_img = take_picture(cv2Cam)

        print('CLASSIFYING PIC')
        prediction = classify(np_img)
        print('CLASSIFICATION: ' + prediction)

        if prediction == 'straight':
            if current_state == 'veer_left':
                turn_straight_from_left(fw)  # Overcorrect due to faulty car
            else:
                turn_straight(fw)
        elif prediction == 'right':
            turn_right(fw)
        elif prediction == 'veer_right':
            veer_right(fw)
        elif prediction == 'veer_left':
            veer_left(fw)
        current_state = prediction

        print('SLEEPING')
        sleep_car(0.05)
        print('')
        print('')
Beispiel #27
0
    def __init__(self, initial_speed=_INITIAL_SPEED):
        logging.info("Setting up CarControl...")
        print("Setting up CarControl ....")
        self.initial_speed = initial_speed

        picar.setup()

        self.back_wheels = picar.back_wheels.Back_Wheels()
        self.front_wheels = picar.front_wheels.Front_Wheels()

        logging.info("Setting up Back Wheels...")
        print("Setting up Back Wheels ....")
        self.back_wheels.speed = 0

        time.sleep(2)
        logging.info("Setting up Front Wheels...")
        print("Setting up Front Wheels ....")
        self.front_wheels.turning_offset = -25
        self.front_wheels.turn(90)
        time.sleep(2)
Beispiel #28
0
def index():
    picar.setup()  # needs to be in index() otherwise weird output

    top = """<!DOCTYPE HTML>
    <html>
    	<head>
    		<title>Pi Car</title>
    		<meta charset="utf-8">
    		<meta name="description" content="Raspberry Pi control RC car.">
    		<meta name="author" content="Michael Russell">
            <meta name="viewport" content="initial-scale=1.0">
    		<link rel="shortcut icon" type="image/png" href="static/raspi.png">
            </head><body> """
    bottom = "</body></html>"
    return top + \
           render_template('joy.html', key = apikeys.google_map_api,
                              # need a little more to get rid of the scrollbars
                               webcam_w=str(webcam_w+20)+"px", webcam_h=str(webcam_h+20)+"px") + \
           render_template('snap.html', innerHTML=snap.innerHTML()) + \
           bottom
Beispiel #29
0
    def __init__(self):
        # 0 = random direction, 1 = force left, 2 = force right, 3 = orderdly
        self.force_turning = 0
        picar.setup()

        self.ua = Ultrasonic_Avoidance.Ultrasonic_Avoidance(20)
        self.fw = front_wheels.Front_Wheels(db='config')
        self.bw = back_wheels.Back_Wheels(db='config')
        self.fw.turning_max = 45

        self.forward_speed = 70
        self.backward_speed = 70

        self.back_distance = 10
        self.turn_distance = 20

        self.timeout = 10
        self.last_angle = 90
        self.last_dir = 0

        self.command = xavier_command.STOP
    def __init__(self):
        picar.setup()                                            #Setup propio de la libreria del Kit
        #Se obtiene la cámara abierta por default y se le hace un rezise de width y height
        self.camera = cv2.VideoCapture(-1)
        self.camera.set(3, self.__SCREEN_WIDTH)
        self.camera.set(4, self.__SCREEN_HEIGHT)

        #Se pueden omitir/no conectar, en caso de dejar fija la cámara en el soporte, caso de nuestro carrito
        #self.pan_servo = picar.Servo.Servo(1)
        #self.pan_servo.offset = -30  
        #self.pan_servo.write(90)

        #self.tilt_servo = picar.Servo.Servo(2)
        #self.tilt_servo.offset = 20
        #self.tilt_servo.write(90)

        self.back_wheels = picar.back_wheels.Back_Wheels()
        self.back_wheels.speed = 0                              # Rango de velocidad PWM  0 (stop) - 100 (fastest)

        self.front_wheels = picar.front_wheels.Front_Wheels()
        self.front_wheels.turning_offset = -25                  # Offset por default del archivo de configuración del kit
        self.front_wheels.turn(70)                              # Ángulo recto a 70° para nstrs, equivalencias 45(izq) 90(centro) 135 (drc)
        self.lane_follower = HandCodedLaneFollower(self)