From 622ed0911eb88b0b2a9ba72bad7c6af30b3c6c0c Mon Sep 17 00:00:00 2001 From: Piv Date: Sun, 30 Aug 2020 15:16:15 +0930 Subject: [PATCH] Add some readme files, start fixing docker build. Docker (and CI in general) build currently isn't generating protobuf files. Docker image also needs to check that pigpio works. --- README.md | 41 +++++++++++++++++++++ protobuf/README.md | 11 ++++++ pycar/Dockerfile | 7 ++++ pycar/README.md | 51 +++++++++++++++++++++++++++ pycar/build.gradle | 6 ++++ pycar/src/car/control/gpio/vehicle.py | 2 +- 6 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 README.md create mode 100644 protobuf/README.md create mode 100644 pycar/README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..cb9eab5 --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +# PiCar + +This software allows for the control of an RC Car using a linux system. Currently it's been tested to work on a Traxxas Slash and raspberry pi 3b+. + +See the individuals modules for more detailed READMEs, including build instructions. + +### Current Functinoality + +- 2D Servo (Steering + Throttle) control. +- 2D SLAM streaming +- 2D LiDAR streaming +- LiDAR object tracking + - Currently the grouping works great, tracking needs some work. +- Control via smartphone applications + - Android is fully supported, iOS currently only supports servo control. + +## Modules + +### PyCar + +This is the main (and original) project to control the raspberry pi. It supports all functions listed in Current Functionality. + +Tracking through the LiDAR is somewhat supported, however has been found to be quite poor at the moment, due to the current assignment algorithm. + +Currently this module is only designed to work standalone, as it is seen to be quite trivial to create the core functionality in a custom application. + +### SwiftyCar + +The plan for this module is to eventually replace the python one, as Swift is known to be faster, whilst being nicer to program than C. Currently it's only meant to support 2D servo control, as a separate library is being created for LiDAR functionality. + +### CarControlleriOS + +This is the iOS application to control the car. Due to the use of gRPC, it can work with + +### app + +This contains the code for the Android application. You should use gradle for this, and Java must be installed to use it. + +### protobuf + +This contains the gRPC and protobuf definitions for controlling the car, so arbitrary clients (that must support gRPC) can be used with the car. The recommended way to generate the code at the moment is to use Gradle, which will do Python, Swift and Java codegen. \ No newline at end of file diff --git a/protobuf/README.md b/protobuf/README.md new file mode 100644 index 0000000..17f43ae --- /dev/null +++ b/protobuf/README.md @@ -0,0 +1,11 @@ +# Protobuf + +This module contains the protobuf definitions used by PiCar. + +## Build + +Run the gradle task + +`./gradlew generateProto` + +It's not recommended to run this alone, unless you plan on manually copying the generated files. The build.gradle files in the other projects will automatically copy the correct generated code across, which is recommended to use instead. \ No newline at end of file diff --git a/pycar/Dockerfile b/pycar/Dockerfile index 151fc03..3142c8d 100644 --- a/pycar/Dockerfile +++ b/pycar/Dockerfile @@ -16,6 +16,13 @@ RUN apt-get install -y \ libpq-dev \ && rm -rf /var/lib/apt/lists/* +# PIGPIO - used to control servos. +RUN wget https://github.com/joan2937/pigpio/archive/master.zip \ + && unzip master.zip \ + && cd pigpio-master \ + && make \ + && make install \ + && cd .. && rm -rf pigpio-master master.zip ARG PYPI_USERNAME ARG PYPI_PASSWORD diff --git a/pycar/README.md b/pycar/README.md new file mode 100644 index 0000000..2f60aef --- /dev/null +++ b/pycar/README.md @@ -0,0 +1,51 @@ +# PyCar + +This module is the original project for RC Car control, and as such contains the most functionality. + +Note that only python 3+ has been tested for support (up to and including python 3.8). + +## Build + +Before building with python or Docker, you should generate protobuf code. If you have Java installed, the easiest way to do this is with the :pycar:copyPythonCode gradle task + +`./gradlew :pycar:copyPythonCode` + +Build using setup tools. +The easiest way to build is using the gradle task. This will also generate protobuf code if it hasn't already been generated. + +`./gradlew :pycar:build` + +Otherwise you can run: + +`python setup.py bdist_wheel` + +### Docker + +A docker image has been created to ease deployment on the raspberry pi. + +The docker image is always built on a tag in GitLab CI. + +Otherwise, the image can be built by running + +`docker build --build-arg PYPI_USERNAME=$PYPI_USERNAME --build-arg PYPI_PASSWORD=$PYPI_PASSWORD .` + +or running the gradle task (which will also generate protobuf code) + +`./gradlew :pycar:buildDocker` + +## Runtime environment variables + +There are two key environment variables that should probably be configured at runtime: +CAR_VEHICLE +- This variable can have two values, and is used to control whether +- Possible Values: + - CAR_MOCK (Default, log changes to stdout) + - CAR_2D + - Use gpiozero and pigpio to control steering/throttle servos) + +CAR_LIDAR +- This variable controls whether an RPLidar will be used, or a file to load LiDAR scans from. +- Possible Values: + - LIDAR_MOCK (Default) + - {Serial Port} + - You must have an RPLidar connected via this port to access. For most linux systems such as raspberry pi, this will probably be /dev/ttyUSB0 \ No newline at end of file diff --git a/pycar/build.gradle b/pycar/build.gradle index 519d040..4c9cd6f 100644 --- a/pycar/build.gradle +++ b/pycar/build.gradle @@ -20,6 +20,12 @@ task build(type: Exec, dependsOn: copyPythonCode) { args 'setup.py', 'bdist_wheel' } +task buildDocker(type: Exec, dependsOn: copyPythonCode) { + executable 'docker' + workingDir projectDir + args 'build', '--build-arg', "PYPI_USERNAME=$System.env.PYPI_USERNAME", '--build-arg', "PYPI_PASSWORD=$System.env.PYPI_PASSWORD", '-t', 'vato.ddns.net:8082/pycar:latest', '.' +} + task clean { doLast { delete 'dist' diff --git a/pycar/src/car/control/gpio/vehicle.py b/pycar/src/car/control/gpio/vehicle.py index f2f0deb..00d3de4 100644 --- a/pycar/src/car/control/gpio/vehicle.py +++ b/pycar/src/car/control/gpio/vehicle.py @@ -31,7 +31,7 @@ def _is_pin_valid(pin): class Vehicle: def __init__(self, motor_pin=19, servo_pin=18): - subprocess.call(['sudo', 'pigpiod']) + subprocess.call(['pigpiod']) Device.pin_factory = PiGPIOFactory() print('Using pin factory:') print(Device.pin_factory)