Skip to content

Hardware

quebeh edited this page Mar 24, 2023 · 8 revisions

Hardware

The hardware folder has several useful classes with the necessary functions.

Contents:

  • hardware.getPCA
  • hardware.ESC
  • hardware.Servo
  • hardware.CameraHandler
  • hardware.Car

hardware.getPCA

hardware.getPCA(frequency=60) -> PCA9685

Returns a adafruit_pca9685.PCA9685 object with the given frequency

  • frequency: Frequency of the PCA9685
import hardware

pca = hardware.getPCA()

hardware.ESC

hardware.ESC(channel: PWMChannel) -> ESC

Calibrates a connected ESC and provides a speed controller

  • channel: The channel of the ESC

Sample use:

esc = hardware.ESC(pca.channels[15]) # replace with used channel

esc.speed = 1 # Forward
esc.speed = -1 # Backward
esc.speed = 0 # Stop

hardware.Servo

hardware.Servo(channel: PWMChannel) -> Servo

Calculates duty cycle for servo

  • channel: The channel of the servo

Sample use:

servo = hardware.Servo(pca.channels[0]) # replace with used channel

servo.turn(90) # Turn 90 degrees
servo.turn(180) # Turn 180 degrees

hardware.CameraHandler

hardware.CameraHandler(camera, calibratePatternSize: Tuple[int] = (5,5), lowThreshold=65, highThreshold=255, capProp=None) -> CameraHandler

A simplifier for the camera post-processing and prediction. Uses checkerboard pattern recognition from opencv to get ROI (Region of interest) coordinates which will later be used to warp the image. The warped image is then thresholded to get a vivid black and white image of the road lines, then the prediction is performed.

  • camera: The camera index or path
  • calibratePatternSize: Checkerboard
  • lowThreshold: Lower threshold value
  • highThreshold: Higher threshold value
  • capProp: Additional camera setting. (e.g. cv2.CAP_DSHOW)

hardware.Car

hardware.Car(pca: PCA9685, escChannel: int, steerChannel: int, camera) -> Car

A class to combine and simplify ESC, servo and camera together

  • pca: PCA9685 object in which the ESC and servo is connected to
  • escChannel: Channel of the ESC
  • steerChannel: Channel of the Servo
  • camera: Camera index or path

Clone this wiki locally