(See also my more recent non-LEGO rpi robot.)
Code to control my Raspberry Pi + BrickPi controlled LEGO robot. This version also has a static webcam.
Parts list:
- LEGO EV3 motors and tank chassis components
- BrickPi
- 12.6V battery (came with the BrickPi)
- An old Logitech webcam
- Some rubber bands
The BrickPi is a "hat" for the Raspberry Pi that sits on the GPIO pins. It has sockets for the ethernet-like plugs that connect to the LEGO EV3 motors and sensors. It allows LEGO motors and sensors to be controlled by a Raspberry Pi.
All of the following needs to be done on a Raspberry Pi, except for the browser interaction. I recommend SSHing in.
(Note that you may have to use sudo python3 to get BrickPi control on the Raspberry Pi.)
Clone my fork of the webcam feed server and install the dependencies:
git clone https://github.com/jaredclaypoole/LiveStream-WebRTC-Flask-OpenCV.git
cd LiveStream-WebRTC-Flask-OpenCV
python3 -m pip install -r requirements-versionless.txt
Test the installation by running the server:
cd src
python3 server.py
Navigate to http://<rpi-ip-address>:5000/video_feed to view the video feed.
Clone this repo and cd into its root directory.
python3 -m pip install -r requirements.txt
The GUI reads a small config.yaml file to determine the url of the video feed.
From the root dir of this repo:
cp config.example.yaml config.yaml
Then modify config.yaml to contain the following line, filling in your RPi IP address:
video_feed_url: http://<rpi-ip-address>:5000/video_feedFirst, start the webcam feed server as described in the Setup section.
Next, cd into this repo's root directory and run:
flet run --web --port <your-chosen-port> --hidden main_gui.py
Finally, navigate to http://<rpi-ip-address>:<your-chosen-port> to access the web gui.
The buttons on the interface should be relatively self-explanatory.
Currently the robot will keep moving until told to stop or change direction.
As an alternative to the buttons in the GUI, you can use the WSAD keys to move the robot, space to stop, and J and K to decrease/increase speed.
