Version 29 (modified by 7 years ago) (diff) | ,
---|
Vision Framework
Objective
Create a reprogrammable module in which a Raspberry Pi 3, protective case, power cable, light ring, and camera are self contained and execute a base program on startup. The base code of the module continuously reads the camera feed (subscribes to camera) and publishes corresponding data via the Pi's serial output (located on the Pi's GPIO connector). This data can then be fairly simply read by the RoboRIO. We hope that this will make implementing a vision subsystem a more simple proposition, allowing more teams to do so.
Materials
- Clear Case
- Raspberry Pi 3 (with NOOBS installed on Micro SD card)
- Ribbon Cable Camera (need 3)
- Micro USB Cable
- Light Ring
- 3-pin female to female jumper wire
Raspberry Pi Setup
Raspbian Lite
Install Win32 Disk Imager
Install Raspian Lite onto MicroSD card via Win32 Disk Imager
Load Raspberry Pi 3 (rpi) with the newly imaged MicroSD
username: pi password: raspberry
connect to wifi by adding the following to the /etc/network/interfaces file:
auto wlan0 iface wlan0 inet dhcp wpa-ssid "your-ssid" wpa-psk "your-password"
reboot the pi:
sudo shutdown -r now
update with the following commands:
sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade sudo apt-get clean
set localization configuration options:
sudo raspi-config
reboot:
sudo shutdown -r now
X server
Install Xorg and Xinit:
sudo apt-get install --no-install-recommends xserver-xorg sudo apt-get install --no-install-recommends xinit
Install the MATE GUI:
sudo apt-get install mate-desktop-environment-core
Install LightDM login manager:
sudo apt-get install lightdm
reboot:
sudo shutdown -r now
login to MATE
At the top left:
navigate to preferences -> hardware -> keyboard shortcuts
to set Run a Terminal to Ctrl + Alt + T
or the like
open a terminal
navigate to Edit -> Profile Preferences -> Colors
to deselect Use colors from system theme
select Built-in schemas: White on black
Development Tools
Java 8
Now that the terminal color scheme is not killing you, we are going to start off by installing java:
sudo apt-get install oracle-java8-jdk
test the java installation (output should include "1.8.0_65" and should not include "openjdk"):
java -version
Let's also set the JAVA_HOME variable to be exported on startup:
echo "export JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt" >> ~/.bashrc source ~/.bashrc
Finally, let's install ANT:
sudo apt-get install ant
Pi4J (Java-GPIO Interface)
Now we can install pi4j, a Java interface for the pi GPIO:
curl -s get.pi4j.com | sudo bash
rpi_ws281x (NeoPixel? Control Library)
Then we can use the rpi_ws281x library for controlling the Adafruit NeoPixel lightring
But first, let's install some tools and dependencies:
sudo apt-get install build-essential python-dev git scons swig
Now we can install the rpi_ws281x library:
git clone https://github.com/jgarff/rpi_ws281x.git cd rpi_ws281x scons
Let's also install the python library:
cd python sudo python setup.py install
OpenCV
EDIT: we have tried with a heatsink as well. It doesn't work. You need to water cool your pi. Please skip to the WATER COOLING section.
First of all, you need a heatsink for your processor before building OpenCV. If you see this overheating symbol, you will die. Straight up.
If you don't have a heatsink on hand, tape some pennies to the CPU like we did:
================WATER COOLING================
If this still doesn't work, it may be necessary to water cool your pi:
Make sure to change the ice cube at least once every half hour. Also, only single bag the ice cube.
Now we are going to install OpenCV and its dependencies.
We only install OpenCV for C++ and Java, not for Python (we ain't scrubs):
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev cd git clone https://github.com/opencv/opencv.git cd opencv mkdir build cd build cmake -DCMAKE_RELEASE_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=OFF -DWITH_FFMPEG=OFF.. make -j $[$(nproc)+1] sudo make install
This builds a single shared object file (libopencv_java320.so), a jar file (opencv-320.jar) and a ton of static libraries (*.a)
It copies the shared object file and the jar file to the install directory: /usr/local/share/OpenCV/java/...
NOTE: we could not get the java wrapper to work with ffmpeg enabled (we ran into a Segmentation fault with opencv libs 3.2.0, 3.3.0, and 3.3.1). We gave up and disabled it.
If you do not want to git clone the master opencv repository, download a zipped version:
opencv-3.2.0.zip
Java Projects with OpenCV
Enable VideoCapture?
First, to allow OpenCV VideoCapture? to access the ribbon cable camera, execute the following:
echo "sudo modprobe bcm2835-v4l2" >> ~/.bashrc source ~/.bashrc
Compiling
javac -d <build_path> -classpath <external_jars> <source_path>/*.java
where:
build_path = directory to store class files
external_jars = string specifying individual jar dependencies (such as OpenCV and Pi4J) with delimiters as follows:
:/path_to_jars/jar1.jar:/path_to_jars/jar2.jar
souce_path = directory containing all of your java files to be compiled
We recommend creating a libs
folder in which you store all of your external jars such as the opencv-320.jar
and all the Pi4J jars rather than having your libraries scattered all over your machine.
Running
sudo java -Djava.library.path=<opencv_install_path> -Dpi4j.debug -Dpi4j.linking=dynamic -classpath <external_jars> <Main_class>
where:
external_jars = same string that you used in the Compilation step
Main_class = name of the class file with main method
- For example, where
Vision.class
is the class file,Main_class = Vision
- For example, where