This Python library is designed to help you build and control a self-driving RC car using a Raspberry Pi. Whether you're a beginner or an experienced, this library provides a modular framework that allows you to mix and match various components, such as sensors, cameras, controller types, and drive trains, to create your own customized self-driving RC car.
- Modular architecture: Easily swap out or add new components to your RC car setup.
- Self-driving capability: Implement autonomous driving algorithms using the library's sensor and camera modules.
- Manual control: Use a controller to take the wheel when you want to drive the car manually.
- Extensible: Create custom components or algorithms to expand the functionality of your RC car.
- User-friendly: Designed with simplicity in mind to make it accessible to hobbyists and learners.
- Clone this repository to your Raspberry Pi:
git clone https://github.com/Caleb646/Herbie.git cd Herbie
- Basic Install:
pip install .
- Install with PiCamera:
pip install[PiCamera] .
- Install with TFLite:
pip install[TFLite] .
- Install with Both:
pip install[PiCamera,TFLite] .
- Additional Dependendies
- Picar-4wd is needed if any of non-base Hardware classes are used such as DriveTrain or UltraSonic.
-
Import the library into your Python project:
from Herbie.CarNav.Api import Car, AutonomousController, TFDetector from Herbie.Hardware.Api import DriveTrain, UltraSonic, Camera from Herbie.Network.Api import Client
-
Initialize the car and chosen controller:
car = Car( AutonomousController( map_size = 11, # how big the grid the car exists in will be. cell_size = 25, # how big each cell in the grid is in centimeters. target = Position(9, 9), # the x, y position in the car's map that it needs to drive to. drive_train = DriveTrain(), # the drivetrain controls how the car rotates and moves forwards and backwards. obstacle_sensor = UltraSonic(), # the ultrasonic is how the car detects obstacles it needs to avoid. detector = TFDetector(Camera(), model_path="path to detection model")) # the class responsible for detecting various objects using the car's camera. ), # Client is an optional argument. It is a standard socket client that connects to a server and sends # data about the car's position, current obstacles, and the current path the car has chosen to take. Client() )
-
Tell the car to drive and shutdown gracefully if an error is encountered:
try: car.drive() except Exception as e: car.shutdown() raise e
Herbie is made up of four modules CarNav, CMath, Hardware, and Network. In each module there is a Base.py file. Each Base.py is only dependent on the CPython3 standard library. So they can be imported and used to create a user specified class that can be used with the higher level classes. For example:
- Creating a custom sensor class.
from Herbie.Hardware.Base import BaseSensor class MySensor(BaseSensor): # Below are the only methods required for the Sensor to be able to interact with the higher level # classes such as AutonomousController. def get_distance(self) -> float: """Implementation""" def move_sensor_to(self, angle: float) -> bool: """Implementation""" # Now all that is needed to use this class is to pass it to the Controller class when setting up the car. car = Car( ... AutonomousController( .... MySensor() ) ) # This will create a car that uses your sensor for obstacle detection.
Check out the Examples/
directory for sample code using this library. These examples can help you understand how to build and program your RC car.
This project is licensed under the MIT License.
Happy driving with your Raspberry Pi Self-Driving RC Car!