PiCam Summary

Overview

The PiCam system is a flight camera system designed to record live footage of the rocket. The PiCam system consists of two Raspberry Pi Zeros equipped with HD cameras mounted inside the vent section body tube, with the camera lenses pointing sideways in opposite directions.

PCB Designs: https://github.com/waterloo-rocketry/canhw/tree/master/picam

Firmware: https://github.com/waterloo-rocketry/cansw_picam

PiCam (Raspbian) software: https://github.com/waterloo-rocketry/daq/tree/master/inflight_recording

Photo:

 

Mechanical Description

Kraken of the Sky has two holes drilled in the vent section body tube, into each of which are placed an HD camera module. Each camera module is connected to a PiCam assembly, which consists of a plastic housing, a PiCam Hat and a Raspberry Pi Zero. There are two identical PiCam assemblies in the vent section. The 3D-printed plastic housing is mounted to the fibreglass body tube using epoxy glue. A 20 cm ribbon cable connects the camera module to the Raspberry Pi Zero. The Raspberry Pi Zero is mounted directly under the PiCam Hat PCB; the two boards are connected by M2.5 standoffs and the 40-pin Raspberry Pi header. The PiCam Hat PCB has exactly the same form factor as the Raspberry Pi Zero, and mates with the Raspberry Pi Zero through a female 40-pin header. The plastic housing provides mechanical support for the entire assembly and provides heat-insert M2.5 threaded holes into which the stand-offs and the PCBs are installed. A Harwin Datamate connector connects each PiCam to the RocketCAN bus.

Electrical Description

The camera is a 180-degree fisheye adjustable lens with a 12.3 megapixel Sony IMX477 image sensor. The camera connects to the Raspberry Pi Zero (Pi) using a CSI ribbon cable. The Raspberry Pi Zero W (the W stands for Wi-Fi) is a tiny embedded computer that runs Raspbian (a lightweight Linux distribution).

The Raspberry Pi Zero has an ARMv6 SoC which is a self-contained embedded computer chip. The Pi’s peripherals include a CSI camera connector, two micro USB ports (only the second port supports serial communication), a 40-pin GPIO header, a micro HDMI port, and an onboard Wi-Fi adapter (including a tiny resonant cavity Wi-Fi antenna printed on the PCB). The Pi also has a microSD card slot; a good quality microSD card with at least 128 GB of capacity is recommended. The microSD card serves both as a bootable volume on which the entire operating system is installed, as well as a local file system to which video data is saved. The Pi accepts a 5 V DC power supply but operates on 3v3 logic.

The PiCam Hat features a PIC18F microcontroller which communicates with the RocketCAN bus and the Pi. The PiCam Hat also carries a P-channel MOSFET which can turn on/off power to the Pi. The PiCam Hat runs on 5v logic from the RocketCAN 5 V supply. Level shifters are used to translate into the 3v3 logic used by the Pi into the 5v logic used by the Hat. The PiCam Hat has a UART connection with the Pi through two of the 40 GPIO pins in the header. The PiCam Hat has a CAN transceiver for communication with the RocketCAN bus. Finally, the PiCam Hat has a current sensing circuit which measures the current drawn by the Pi.

The PiCam draws about 400 mA when recording and roughly 10 mA when idle. The main function of the PiCam Hat is to turn on/off the Pi when instructed to do so by the RocketCAN bus in order to conserve battery power. The human DAQ operator can turn each of the PiCams on/off using omnibus commands. Furthermore, the PiCam Hat generates CAN warning messages if the current drawn by the Pi is too high. The PiCam Hat regularly reports the status of the PiCam on the RocketCAN bus, indicating whether the Pi is currently recording.

A “pseudo-UART” interface is used for basic communication between the PiCam Hat and the Pi. The pseudo-UART is simply a pair of wires allowing for basic on/off binary signalling between the two modules. Physically, the pseudo-UART is built the same way as a conventional UART, with a Rx->Tx and Tx->Rx wire pair. However, the psuedo-UART is not a serial interface, it is simply a binary flag raised by the PIC indicating for the Pi to perform a safe shutdown, and another binary flag lowered by the Pi indicating that video is currently being recorded.

The Pi has a tiny green LED which flashes when the CPU is active. The PiCam Hat has three LEDs, which blink out a heartbeat (one of which is controlled by the Pi) to indicate that the PiCam is alive.

Firmware

The PiCam Hat implements a soft shutdown function for safely turning off the Pi. When the PiCam Hat receives a RocketCAN message to turn off the camera, the PiCam Hat will raise the pseudo-UART Hat->Pi flag. The Pi will detect this flag and automatically stop recording and do a safe shutdown. As the Pi shuts down, the pseudo-UART Pi->Hat wire will be electrically pulled up to logical HIGH and the PiCam Hat will interpret this as an indication that the Pi has completed its safe shutdown. The PiCam Hat will then cut off power to the Pi by switching off the PFET. The purpose of the safe shutdown is to ensure that the Pi has an opportunity to stop recording safely and properly save the video file so that the file does not become corrupted.

By default, the PFET is switched off and the supply of power to the Pi is cut off. When the PiCam Hat receives a command to start recording, it turns on the PFET, delivering power to the Pi and allowing it to boot up. When the Pi has finished booting (about 2 minutes), it will automatically begin recording video and lower the Pi->Hat flag. The PIC microcontroller will detect this flag and this status will be reflected in all following MSG_ACTUATOR_STATUS messages.

If the connection between the camera and the Pi is interrupted at any point, the Pi will be unable to continue recording video and the Pi->Hat flag will be raised. This status will be reflected in any following MSG_ACTUATOR_STATUS messages. The PIC microcontroller distinguishes between the curr_state and req_state. The curr_state represents the actual status of the Pi recording, as indicated by the Pi->Hat pseudo-UART flag. The req_state represents the desired state of the Pi recording, as indicated by the most recent RocketCAN command. Both the req_state and curr_state are reported in MSG_ACTUATOR_STATUS messages.

The PIC microcontroller firmware monitors the RocketCAN bus. A BUS_DOWN_WARNING message will cause the PiCam Hat to shut down the Pi. Furthermore, a MSG_ACTUATOR_CMD message with an ACTUATOR_CLOSED state will cause the Pi to turn on; an ACTUATOR_OPEN state will cause the Pi to turn off.

The two PiCams are distinguished by their board IDs. Specifically, ROCKET_PI, ROCKET_PI_2, ROCKET_PI_SPARE and ROCKET_PI_2_SPARE are used to address CAN messages to each of the PiCams. The two PiCams on the rocket run identical firmware, except for the board ID.

The Pi uses the default Raspberry Pi operating system, called Raspbian. Raspbian is a variant of Debian and is both lightweight and suitable for embedded computers. The default install of Raspbian comes with all necessary drivers built in. A set of shell scripts are used to perform automatic video recording. The Raspbian system comes with a built-in utility for video recording called raspivid. The raspivid utility captures a video stream from the camera and stores it as an h264 video file on the local file system. The video is captured in streaming mode, which means that the video data buffer is regularly flushed onto the video file. This regular flushing ensures that in case of a sudden loss of power, the previously captured video data will not be permanently lost. The video file is saved on the local file system on the microSD card. The video file has the current timestamp baked into the file name.

During installation of the picam software, a picam.service is installed. This service is automatically invoked during start-up. The picam service invokes a shell script which starts the raspivid program, so that video recording will begin automatically when power is applied to the Pi, without requiring any user interaction.

When the Pi is connected to a Wi-Fi network, the video can also be streamed using UDP. The UDP streaming configuration, including the IP address destination for streaming, is done while installing the picam software. When the Pi starts up, it will automatically connect to a Wi-Fi network if available, and will begin streaming video to the network using UDP. Any computer connected to the same Wi-Fi network will be able to video stream using a video streaming program such as MPV. The PiCam does not require a Wi-Fi connection in order to operate; it will continue to record video footage and store the footage in a local file even when no network is available.

Current Status

The PiCam system was tested and validated both at SF5 and SF6. The PiCam system was also installed in KotS in anticipation of flight. However, the PiCam system has never been tested in flight. The PiCam system has been desert tested both by being in an actual desert, and by being in a “desert simulator” (i.e. toaster oven) for 30 minutes at 60 C. During these tests, the PiCam was shown to be very tolerant of extreme hot and cold temperatures. A camera lens placed directly behind the the nozzle during SF5 also survived, though the extreme heat caused the camera image to become temporarily blurry and grainy.

During testing, several flaws in the electrical design were discovered. Firstly, the RocketCAN connector is incorrect, in that the pin mappings of the six wires in the Harwin connector are different from most other RocketCAN boards. Furthermore, a 100 uF “flying” (i.e. non-footprint) capacitor must be placed between the PFET gate and ground. This capacitor is necessary so that the PFET turns on gradually to prevent a surge of inrush current from flowing into the Pi. Without the flying capacitor, the surge of inrush current will cause the 5 V line to temporarily droop, which results in the PIC microcontroller resetting and the PiCam being unable to start up. In addition, the MCLR pin indicator is missing from the silkscreen, which leads to some ambiguity with respect to plugging in the PICKit programming header. The footprint for the polyfuse is also too small, which makes it difficult to install. All these issues may be fixed in the next re-spin of the PiCam Hat board.

The current procedure for installing the picam software on the Pi is rather complicated and tedious; an automatic program for installing the software has been proposed, but currently does not exist. In addition, the method for configuring the UDP streaming addresses is very complicated and obscure; this must be simplified and clarified.

During the preparation for the droptest, several PiCam Hats were accidentally assembled with male instead of female header pins. In order to get these incorrectly assembled Hats to mate with their respective Pis, the male header pins of the Pis and their Hats were soldered tip-to-tip (yikes!). This unholy arrangement has since been removed. However, there is still some slight roughness to the pins of the affected Pis and Hats as a result of the soldering and desoldering process. Furthermore, during the conformal coating process while preparing for the 2022 competition, some conformal resin leaked into the header sockets of some of the Hats, but the socket was not fully obstructed. Altogether, most of the PiCam hardware has suffered a lot of abuse and is in rough shape, but appears to still be fully functional.

Another issue with the PiCam system is its dependence on the Raspberry Pi Zero. When the PiCam system was first designed, back in 2020, Raspberry Pi Zeros were cheap and abundant. However, as a result of the great Chip Shortage, Raspberry Pi Zeros are extremely scarce and are virtually impossible to acquire, except through the resale market at extremely inflated prices. This scarcity makes it nearly impossible to create new PiCams, and also makes the current inventory of Pis extremely precious.

The most serious issue affecting the performance of the PiCam is the ribbon cable. The ribbon cable is weak and flimsy, and is connected to the camera module and the Pi through a weak and fragile plastic retainer clip. This clip is easily broken through normal use and is quite fragile. During the 2022 competition, there were several instances when the PiCams did not work due to the ribbon cable connection being flaky. It is theorized that the vibrations caused by moving and transporting the rocket, as well has plugging/unplugging the ribbon several times caused the contacts to become eroded to the point of failure. The PiCam has never been vibration nor shock tested, and many team members (including myself) are sceptical that the flimsy ribbon cable would survive the vibrations and mechanical shocks experienced during flight. During the 2022 competition, some tape was used to reinforce the ribbon cable connection, but this reinforcement was rather sketchy and not very strong.

Overall, while the PiCam did serve its purpose well during its years of service in 2020 and 2021, the PiCam is not a good solution as a flight camera, on account of the ribbon cable. A new, more robust camera system should be developed as a replacement. Furthermore, any future flight camera system should be fully vibration and shock tested on the ground before integrating it into a rocket design.