> For the complete documentation index, see [llms.txt](https://davids-tutorials.gitbook.io/robotics/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://davids-tutorials.gitbook.io/robotics/setup-pi-record-video.md).

# Setup Pi/Record Video

### 1 - Record video

```python
import picamera
from time import sleep
from subprocess import call

with picamera.PiCamera() as camera:
    camera.start_recording("pythonVideo.h264")
    sleep(5)
    camera.stop_recording()

# The camera is now closed.
command = "MP4Box -add pythonVideo.h264 convertedVideo.mp4"
call([command], shell=True)
print("Video converted.")

#src: https://www.youtube.com/watch?v=TeMX9MjrJLY&t=555s
```

or

```python
from picamera2 import Picamera2, Preview
picam2 Picamera2()
picam2.start_and_record_video("test.mp4", duration = 60, show_preview = True)

# src: https://www.youtube.com/watch?v=TeMX9MjrJLY&t=555s
```

***

### 2 - ArduPilot

### Installation Instructions \[[1](#sources)]

Open the terminal with `Ctrl` + `Alt` + `T`

```
sudo apt-get update
sudo apt-get install git
sudo apt-get install gitk git-gui
```

```
git clone --recurse-submodules https://github.com/ArduPilot/ardupilot.git
```

> Note: this takes a minute

```
cd ardupilot
```

```
Tools/environment_install/install-prereqs-ubuntu.sh -y
```

> &#x20;Note: this takes a minute

```
. ~/.profile
```

### 3 - Dronekit

Open the terminal with `Ctrl` + `Alt` + `T`

```
cd ~
git clone https://github.com/dronekit/dronekit-python
cd dronekit-python

sudo python setup.py install
```

### Dronekit Simple\_goto example

```
cd examples/simple_goto
```

```
gedit modified_goto.py
```

## Location Changes

```
Mojave=35.059217, -118.150861,0.0,0
Mojave_1=35.063570, -118.156204,0.0,0
Mojave_2=35.059257, -118.157724,0.0,0
```

```
## open new terminal
cd ardupilot/Tools/autotest

nano locations.txt

## add the followig: 
Mojave=35.059217, -118.150861,0.0,0
```

### 4 - Set up Pi - Installation

Python Library [Versions located here](https://gitlab.com/drone_la/cv/-/blob/main/yolov5-versions-3-27-2024.txt?ref_type=heads)

<table><thead><tr><th width="737">Ctrl + Alt + T</th></tr></thead><tbody><tr><td><p>NOTE: (2:54)</p><p>-click top left</p><p>-preferences</p><p>-raspberry pi configuration</p><p>-tabs: interfaces</p><p>-enable camera</p><p>-reboot</p></td></tr><tr><td>uaYq12tCsfz3-hWdK8ivKExIY</td></tr></tbody></table>

| sudo apt-get update                                                                        |
| ------------------------------------------------------------------------------------------ |
| git clone <https://github.com/ultralytics/yolov5>                                          |
| cd yolov5                                                                                  |
| pip install -r requirements.txt                                                            |
| pip install -r requirements.txt --user                                                     |
| pip install torchvision                                                                    |
| mv installs to /.local/python3/dist-packages /usr/local/lib/python3.9/dist-packages/yolov5 |
|                                                                                            |
| cd .local/lib/python3.10/site-packages/                                                    |
| ls # check if packages installed                                                           |
| sudo mv ./\* /usr/local/lib/python3.10/dist-packages                                       |
|                                                                                            |
|                                                                                            |
|                                                                                            |
|                                                                                            |

### 5 - Run Yolov5

| Ctrl + Alt + T                                                                                                                                                                                                                                                  |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Download your best.pt file after training, you can use Github or Google Drive                                                                                                                                                                                   |
|                                                                                                                                                                                                                                                                 |
| cd yolov5                                                                                                                                                                                                                                                       |
| cp \~/Downloads/best.pt .                                                                                                                                                                                                                                       |
|                                                                                                                                                                                                                                                                 |
| <p>gedit detect.py<br></p><ul><li>(Note: make sure you use correct naming convention)</li><li><p>got to line 53 and type: </p><ul><li>weights = 'best.pt',</li></ul></li><li><p>go and comment line 54: </p><ul><li>weights = 'yolov5s.pt',</li></ul></li></ul> |
|                                                                                                                                                                                                                                                                 |
| sudo python3 detect.py                                                                                                                                                                                                                                          |
| <p>sudo python3 detect.py --weights 3-27-13-best.pt --source 0<br>or<br>sudo python3 detect.py --weights best.pt --source 0</p>                                                                                                                                 |

### 6 - config

```
ssh pi@195.168.43.153
sudo apt-get update && upgrade
sudo pip install pymavlink mavproxy

sudo raspi-config > serial activate > restart

nano /boot/config.txt
```

<figure><img src="/files/UvhRxW14LfIvKPBdm4vi" alt=""><figcaption></figcaption></figure>

```
ls /dev/tty*
# Look for AMA0

sudo -s
mavproxy.py --master=/dev/ttyAMA0 --baudrate 921600 --aircraft MyCopter

# src - https://www.youtube.com/watch?v=BSDST7ePOtM
```
