Exemplo n.º 1
0
'''
Filename: picar_move.py
Description: First attempt at getting the PiCar to run a custom program.
Author: Andi Frank
E-mail: [email protected]
Purpose: CSE 276A: Intro to Robotics; Fall 2019

Inspiration drawn from:
    https://github.com/korzen/PiCar_ROS/

'''

import time
import SunFounder_PiCar.picar as pc

pc.setup()
fw = pc.front_wheels.Front_Wheels(db="config")
bw = pc.back_wheels.Back_Wheels(db="config")

fw.turning_max = 30
fwd_speed = 50
bkw_speed = 50

bw.speed = fwd_speed

fw.ready()
bw.ready()

DELAY = .2

try:
 def __init__(self):
     self.fwheels = front_wheels.Front_Wheels(debug=False)
     self.bwheels = back_wheels.Back_Wheels(debug=False)
     picar.setup()
Exemplo n.º 3
0
import numpy as np
import cv2
from SunFounder_PiCar.picar import front_wheels
from SunFounder_PiCar.picar import back_wheels
import SunFounder_PiCar.picar as picar

picar.setup()

fw = front_wheels.Front_Wheels(db='config')
bw = back_wheels.Back_Wheels(db='config')
fw.turning_max = 45

ball_detected_speed = 50


def steering(position, distance, framesize):
    rel_position = (framesize / 2) - position
    angle = np.degrees(np.arctan(np.abs(rel_position) / distance))
    if rel_position < 0:
        drive_angle = 90 + angle
    else:
        drive_angle = 90 - angle

    fw.turn(drive_angle)
    bw.forward()
    bw.speed(ball_detected_speed)


def steer_to_bbox(bbox, frame):
    hpos = (np.size(frame, 1) / 2) - (bbox[0] + (bbox[2] - bbox[0]))
    vpos = (np.size(frame, 2) / 2) - (bbox[1] + (bbox[1] - bbox[3]))