# PiRacer-Py
This package will provide you with a simple abstraction layer for the PiRacer development platform.
You will be able to control the powertrain and the steering as easy as possible.
I also provides an easy way to grab images from the camera (based on v4l2 and opencv)
PiRacer Standard and Pro architecture overview:
![](doc/architecture/export/piracer_overview.drawio.svg)
## Install
Tested on the following Hardware:
* Raspberry Pi 4 Model B 4GB
Tested on the following distributions:
* Raspberry Pi OS Lite "Bullseye" (64-Bit)
* Camera is not working at the moment
* Ubuntu Server 22.04.1 LTS (64-Bit)
* Ubuntu Server 20.04.5 LTS (64-Bit)
### Add additional sources (Ubuntu only)
If you run **Ubuntu**, add the following sources first:
sudo -s
echo "deb http://archive.raspberrypi.org/debian/ buster main" >> /etc/apt/sources.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7FA3303E
apt update
exit
If you're facing messages like the following when trying to install packages
via apt:
pi@ubuntu:/home/pi# sudo apt install PACKAGES...
Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1807 (unattended-upgr)
Disable the unattended upgrade feature by running the following command to disable:
sudo dpkg-reconfigure unattended-upgrades
### Install dependencies:
sudo apt update
sudo apt install \
gcc \
v4l-utils \
i2c-tools \
raspi-config \
python3-dev \
python3-setuptools \
python3-venv \
libopencv-dev
### Setup periphery
#### Mount boot partition (Ubuntu only)
On Ubuntu it is necessary to explicitly mount the boot partition before
enabling the i2c controller and camera:
mount /dev/mmcblk0p1 /boot/
#### Enable i2c and camera
Use the **raspi-config** tool to enable the following peripherals:
* i2c: Interface Options > I2C
* Camera: Interface Options > Camera
Afterwards, reboot:
sudo reboot
### Install piracer-py package
cd ~
mkdir piracer_test/
cd piracer_test/
python3 -m venv venv
source venv/bin/ativate
pip install piracer-py
## Examples
The following examples will show the basic functionality of the piracer-py package.
Make sure the virtual environment from step **Install piracer-py package** is activated.
### Basic example
This basic example will test the power train and the steering.
Paste the following code into **basic_example.py**
import time
from piracer.vehicles import PiRacerPro
if __name__ == '__main__':
piracer = PiRacerPro()
# piracer = PiRacerStandard()
# Forward
piracer.set_throttle_percent(0.2)
time.sleep(2.0)
# Brake
piracer.set_throttle_percent(-1.0)
time.sleep(0.5)
piracer.set_throttle_percent(0.0)
time.sleep(0.1)
# Backward
piracer.set_throttle_percent(-0.3)
time.sleep(2.0)
# Stop
piracer.set_throttle_percent(0.0)
# Steering left
piracer.set_steering_percent(1.0)
time.sleep(1.0)
# Steering right
piracer.set_steering_percent(-1.0)
time.sleep(1.0)
# Steering neutral
piracer.set_steering_percent(0.0)
Run it with:
python basic_example.py
### Remote control example
The following example will let you control the PiRacer with the ShanWan Gamepad
that is shipped with the PiRacer package. Make sure the dongle is connected to your Raspberry Pi.
Paste the following code into **rc_example.py**:
from piracer.vehicles import PiRacerPro
from piracer.gamepads import ShanWanGamepad
if __name__ == '__main__':
shanwan_gamepad = ShanWanGamepad()
piracer = PiRacerPro()
# piracer = PiRacerStandard()
while True:
gamepad_input = shanwan_gamepad.read_data()
throttle = gamepad_input.analog_stick_right.y * 0.5
steering = -gamepad_input.analog_stick_left.x
print(f'throttle={throttle}, steering={steering}')
piracer.set_throttle_percent(throttle)
piracer.set_steering_percent(steering)
Run it with:
python rc_example.py
### Grab images example
With the following example you can grab and save images from the Raspberry Pi camera.
Paste the following code into **camera_grab_example.py**:
import cv2
from piracer.cameras import Camera, MonochromeCamera
if __name__ == '__main__':
camera = MonochromeCamera()
image = camera.read_image()
cv2.imwrite('image.png', image)
Run it with:
python camera_grab_example.py
Raw data
{
"_id": null,
"home_page": "https://github.com/junho2000/custom_piracer_py",
"name": "seame-piracer",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "piracer embedded abstraction",
"author": "Junho Kim",
"author_email": "jhk00@kookmin.ac.kr",
"download_url": "https://files.pythonhosted.org/packages/c3/16/596edb4ab5cb32b053ca03f57e0e44552702e85d7c866f52e33fecadd7cd/seame_piracer-0.1.2.tar.gz",
"platform": null,
"description": "# PiRacer-Py\n\nThis package will provide you with a simple abstraction layer for the PiRacer development platform.\nYou will be able to control the powertrain and the steering as easy as possible.\n\nI also provides an easy way to grab images from the camera (based on v4l2 and opencv)\n\nPiRacer Standard and Pro architecture overview:\n\n![](doc/architecture/export/piracer_overview.drawio.svg)\n\n\n## Install\n\nTested on the following Hardware:\n\n* Raspberry Pi 4 Model B 4GB\n\nTested on the following distributions: \n\n* Raspberry Pi OS Lite \"Bullseye\" (64-Bit)\n * Camera is not working at the moment\n* Ubuntu Server 22.04.1 LTS (64-Bit)\n* Ubuntu Server 20.04.5 LTS (64-Bit)\n\n\n### Add additional sources (Ubuntu only)\n\nIf you run **Ubuntu**, add the following sources first:\n\n sudo -s\n echo \"deb http://archive.raspberrypi.org/debian/ buster main\" >> /etc/apt/sources.list\n apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 7FA3303E\n apt update\n exit\n\nIf you're facing messages like the following when trying to install packages\nvia apt:\n\n pi@ubuntu:/home/pi# sudo apt install PACKAGES...\n Waiting for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 1807 (unattended-upgr)\n\nDisable the unattended upgrade feature by running the following command to disable:\n\n sudo dpkg-reconfigure unattended-upgrades\n\n### Install dependencies:\n\n sudo apt update\n sudo apt install \\\n gcc \\\n v4l-utils \\\n i2c-tools \\\n raspi-config \\\n python3-dev \\\n python3-setuptools \\\n python3-venv \\\n libopencv-dev\n\n### Setup periphery \n\n#### Mount boot partition (Ubuntu only)\n\nOn Ubuntu it is necessary to explicitly mount the boot partition before \nenabling the i2c controller and camera:\n\n mount /dev/mmcblk0p1 /boot/\n\n#### Enable i2c and camera\n\nUse the **raspi-config** tool to enable the following peripherals:\n\n* i2c: Interface Options > I2C\n* Camera: Interface Options > Camera\n\nAfterwards, reboot:\n \n sudo reboot\n\n### Install piracer-py package\n\n cd ~\n mkdir piracer_test/\n cd piracer_test/\n python3 -m venv venv\n source venv/bin/ativate\n\n pip install piracer-py\n\n## Examples\n\nThe following examples will show the basic functionality of the piracer-py package.\nMake sure the virtual environment from step **Install piracer-py package** is activated.\n\n### Basic example\n\nThis basic example will test the power train and the steering.\n\nPaste the following code into **basic_example.py**\n\n import time\n from piracer.vehicles import PiRacerPro\n\n if __name__ == '__main__':\n \n piracer = PiRacerPro()\n # piracer = PiRacerStandard()\n \n # Forward\n piracer.set_throttle_percent(0.2)\n time.sleep(2.0)\n \n # Brake\n piracer.set_throttle_percent(-1.0)\n time.sleep(0.5)\n piracer.set_throttle_percent(0.0)\n time.sleep(0.1)\n \n # Backward\n piracer.set_throttle_percent(-0.3)\n time.sleep(2.0)\n \n # Stop\n piracer.set_throttle_percent(0.0)\n \n # Steering left\n piracer.set_steering_percent(1.0)\n time.sleep(1.0)\n \n # Steering right\n piracer.set_steering_percent(-1.0)\n time.sleep(1.0)\n \n # Steering neutral\n piracer.set_steering_percent(0.0)\n\n\nRun it with:\n\n python basic_example.py\n\n### Remote control example\n\nThe following example will let you control the PiRacer with the ShanWan Gamepad \nthat is shipped with the PiRacer package. Make sure the dongle is connected to your Raspberry Pi.\n\nPaste the following code into **rc_example.py**:\n\n from piracer.vehicles import PiRacerPro\n from piracer.gamepads import ShanWanGamepad\n\n if __name__ == '__main__':\n \n shanwan_gamepad = ShanWanGamepad()\n piracer = PiRacerPro()\n # piracer = PiRacerStandard()\n \n while True:\n gamepad_input = shanwan_gamepad.read_data()\n \n throttle = gamepad_input.analog_stick_right.y * 0.5\n steering = -gamepad_input.analog_stick_left.x\n \n print(f'throttle={throttle}, steering={steering}')\n \n piracer.set_throttle_percent(throttle)\n piracer.set_steering_percent(steering)\n\nRun it with:\n\n python rc_example.py\n\n### Grab images example\n\nWith the following example you can grab and save images from the Raspberry Pi camera.\n\nPaste the following code into **camera_grab_example.py**:\n\n import cv2\n from piracer.cameras import Camera, MonochromeCamera\n \n if __name__ == '__main__':\n camera = MonochromeCamera()\n \n image = camera.read_image()\n cv2.imwrite('image.png', image)\n\nRun it with:\n\n python camera_grab_example.py\n",
"bugtrack_url": null,
"license": "GPL 3.0",
"summary": "PiRacer Abstract Layer for SEA:ME DES proejct",
"version": "0.1.2",
"project_urls": {
"Homepage": "https://github.com/junho2000/custom_piracer_py"
},
"split_keywords": [
"piracer",
"embedded",
"abstraction"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2096e54c2ef4e165c4692803f74022c2d0e69f9156423ebd031dd8dfa36815e8",
"md5": "f2c5f9c69f56ed8f5e53682f1dbf2c1e",
"sha256": "6508d164627823927ac6adcfb55155fb51a0f232e89fc071521622a55b7461d1"
},
"downloads": -1,
"filename": "seame_piracer-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f2c5f9c69f56ed8f5e53682f1dbf2c1e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 20111,
"upload_time": "2023-11-19T14:49:29",
"upload_time_iso_8601": "2023-11-19T14:49:29.914420Z",
"url": "https://files.pythonhosted.org/packages/20/96/e54c2ef4e165c4692803f74022c2d0e69f9156423ebd031dd8dfa36815e8/seame_piracer-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c316596edb4ab5cb32b053ca03f57e0e44552702e85d7c866f52e33fecadd7cd",
"md5": "35d6d63d719cc83e2532a882ffedca62",
"sha256": "3ef2bb491ec21f6ec71a683e15afec9b056deabe3e97bb456efa97cf467c46d2"
},
"downloads": -1,
"filename": "seame_piracer-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "35d6d63d719cc83e2532a882ffedca62",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 20803,
"upload_time": "2023-11-19T14:49:31",
"upload_time_iso_8601": "2023-11-19T14:49:31.753073Z",
"url": "https://files.pythonhosted.org/packages/c3/16/596edb4ab5cb32b053ca03f57e0e44552702e85d7c866f52e33fecadd7cd/seame_piracer-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-19 14:49:31",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "junho2000",
"github_project": "custom_piracer_py",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "twine",
"specs": []
},
{
"name": "RPi.GPIO",
"specs": []
},
{
"name": "adafruit-circuitpython-pca9685",
"specs": []
},
{
"name": "adafruit-circuitpython-ina219",
"specs": []
},
{
"name": "adafruit-circuitpython-ssd1306",
"specs": []
},
{
"name": "opencv-python",
"specs": []
},
{
"name": "pygame",
"specs": []
}
],
"lcname": "seame-piracer"
}