Raspberry PI Vision Processor (SpartaCam)

by Louis Lauriello in Circuits > Raspberry Pi

5393 Views, 25 Favorites, 0 Comments

Raspberry PI Vision Processor (SpartaCam)

IMG_20200206_132039.jpg
IMG_0634.JPG

A Raspberry PI vision processor system for your FIRST Robotics Competition robot.

About FIRST

From Wikipedia, the free encyclopedia https://en.wikipedia.org/wiki/FIRST_Robotics_Compe...

The FIRST Robotics Competition (FRC) is an international high school robotics competition. Each year, teams of high school students, coaches, and mentors work during a six-week period to build game-playing robots that weigh up to 120 pounds (54 kg). Robots complete tasks such as scoring balls into goals, flying discs into goals, inner tubes onto racks, hanging on bars, and balancing robots on balance beams. The game, along with the required set of tasks, changes annually. While teams are given a standard set of parts, they are also allowed a budget and are encouraged to buy or make specialized parts.

This years game(2020) INFINITE RECHARGE. The Infinite Recharge game involves two alliances of three teams each, with each team controlling a robot and performing specific tasks on a field to score points. The game centers around a futuristic city theme involving two alliances consisting of three teams each competing to perform various tasks, including shooting foam balls known as Power Cells into high and low goals to activate a Shield Generator, manipulating a Control Panel to activate this shield, and returning to the Shield Generator to park or climb at the end of the match. The objective is to energize and activate the shield before the match ends and asteroids strike FIRST City, a futuristic city modeled after Star Wars.

What does Raspberry PI vision processor system do?

The camera will be able to scan the playing field and target locations where game pieces are supplied or need to be placed for scoring. The assembly has 2 connections, power and Ethernet.

The vision targets on the playing field are outlined with retro-reflective tape and light will reflect back to the camera lens. The Pi running open source code from Chameleon Vision ( https://chameleon-vision.readthedocs.io/en/latest/... ) will process the view, highlight it, add image overlays and output pitch, yaw,contour, and position as array values ordered by x and y in meters and angle in degrees along with other data via a network table. That information will used in software to control our robot in autonomous mode as well as aiming and firing our turreted shooter. Other software platforms can be run on the Pi. FRC vision can be installed if your team has already invested the software time in that platform.

Our budget was tight this year and purchasing a Limelight $399.00 (https://www.wcproducts.com/wcp-015) camera was not in the cards. Sourcing all supplies from Amazon and using Team 3512 Spartatroniks 3D printer I was able to package a custom vision system for $150.00 . Some items came in bulk, building up a second co-processor would only require another Raspberry Pi, PI Camera and fan. With CAD help from one of the teams Mentors (thank you Matt) the PI enclosure was created using Fusion 360.

Why not just use a Pi with cheap enclosure, plug in a USB camera, add a ring light, install Chameleon vision and your done, right? Well, I wanted more power and less cables and the coolness factor of a custom system.

A Pi 4 uses 3 amps if running full bore, that's if its using most of its ports, and wifi and running a display. We are not doing that on our robots, but the USB ports on the roboRIO https://www.ni.com/en-us/support/model.roborio.ht... are rated at 900 ma, the voltage regulator modual (VRM) 5 volt supplies up to 2 amps peak, 1.5 amps limit, but its a shared connector so if another device is on the 5 volt bus there's a possibility of a brownout. The VRM also supplies 12 volts at 2 amps, but we use both connections to power our radio using a POE cable and a barrel connection for redundancy. Some FRC inspectors will not allow anything other than whats printed on the VRM to be plugged in there. So 12 volts from the PDP on a 5 amp Breaker is where the Pi needs to be powered.

12 volts is supplied via a 5 amp breaker on the power distribution panel (PDP) , is converted to 5.15 volts using a LM2596 DC to DC Buck Converter. The Buck converter supplies 5 volts at 3 amps and stays in regulation down to 6.5 volts input. This 5 volt bus then provides power to 3 subsystems, LED ring array, Fan, Raspberry Pi.

Supplies

Prototype 1

IMG_20200206_174048.jpg

First test in packaging:

The team had a Pi 3 from a previous year that was available for testing. A pi camera, a DC-DC buck/boost circuit and an Andymark ring light was added. https://www.andymark.com/products/led-ring-green.

At this time I hadn't considered the Pi 4 so wasn't worried about power needs. Power was supplied via USB from the roboRIO. The camera fit in the case without modification. The ring light was hot glued to the case cover and wired to the boost board. The boost board plugged into the GPIO ports 2 and 6 for 5 volts and the output was adjusted up to 12 volts to run the ring. There was no room inside the case for the boost board so it was also hot glued to the outside. Software was installed and tested using targets from the 2019 game year. The software team gave a thumbs up so we ordered a Pi 4, heat sinks and a fan. And while they we on there way the enclosure was designed and 3d printed.

Prototype 2

IMG_0636.JPG
IMG_0635.JPG
IMG_20191222_173321.jpg
IMG_20191222_155758.jpg
IMG_20191222_165431.jpg

Enclosure internal dimensions were OK, but port locations were offset, not a show stopper.

This was completed just after the new game reveal so software could test against the new target locations.

Good news and bad news. Ring light output was not adequate when we were greater than 15 feet from the target so time to rethink lighting. Since changes were needed, I consider this unit as prototype 2.

Prototype 3

IMG_20200206_174444.jpg
IMG_20191203_191257.jpg

Prototype 2 was left together so software could continue to refine their system. Meanwhile another Pi 3 was found and I cobbled together another test bed. This had a Pi3, a USB lifecam 3000 direct soldered to the board, a boost converter and hand soldered diode array.

Again good news, bad news. The array could light up a target from 50+feet away, but would lose target if off angle greater than 22 degrees. With this piece of information the final system could be made.

Final Product

IMG_20200206_132039.jpg
IMG_20200206_132143.jpg
IMG_20200206_132253.jpg
Vision Processor v2.jpg
IMG_20200206_132218.jpg
IMG_20200206_114926.jpg
RasPi Camera Enclosure v1 v0.jpg
RasPi Camera Lid.jpg
RasPi Camera Base.jpg

Prototype 3 had 6 diodes approximately 60 degrees apart and facing directly ahead.

The final changes were to add 8 diodes spaced 45 degrees apart around the lens with 4 diodes facing forward and 4 diodes canted out 10 degrees giving a field of view of 44 degrees. This also allows the enclosure to be mounted either vertically or horizontally on the robot. A new enclosure was printed with changes to accommodate a Pi 3 or Pi 4. The face of the enclosure was modified for the individual diodes.

Testing did not show any performance issues between either Pi 3 or 4 so the enclosure openings were made to allow either Pi to be installed. The rear mount points were removed as well as the exhaust openings at the top of the dome. Using a Pi 3 will further reduce the cost. Pi 3 runs cooler and uses less power. In the end we decided to use PI 3's for the cost savings and software team wanted to use some code that would run on the Pi 3 that had not been updated for the Pi 4.

Import the STL into your 3D printers slicer and away you go. This file is in inches so if you have a slicer like Cura, you will probably have to scale the part to %2540 to convert it to metric. If you have Fusion 360 the .f3d file can be modified to your own needs. I wanted to include a .step file but instructables wont allow the files to be uploaded.

Basic tools needed:

  • Wire strippers
  • Pliers
  • Soldering iron
  • Heat shrink tubing
  • Wire cutters
  • Lead free solder
  • Flux
  • Helping hands or forceps
  • Heat gun

Wiring Diode Array

IMG_20200130_114652.jpg
IMG_20200128_184235.jpg
IMG_20200129_155051.jpg
IMG_20200129_160922.jpg
Light Ring Schematic and Layout v2.jpg
IMG_20200129_170022.jpg
IMG_20200130_120136.jpg
IMG_20200130_152142.jpg

Safety Notice:

Soldering Iron
Never touch the element of the soldering iron....400°C!(750°F)

Hold wires to be heated with tweezers or clamps.

Keep the cleaning sponge wet during use.

Always return the soldering iron to its stand when not in use.

Never put it down on the workbench.

Turn unit off and unplug when not in use.

Solder, flux and cleaners

Wear eye protection.

Solder can “spit”.

Use rosin-free and lead-free solders wherever possible.

Keep cleaning solvents in dispensing bottles.

Always wash your hands with soap and water after soldering.

Work in well ventilated areas.

OK lets get to work:

The enclosure face was printed with diode holes at 0,90,180,270 points are canted at 10 degrees out. Holes at 45,135,225,315 points are straight.

Place all diodes in enclosure face to verify 5 mm hole size. A tight fit will keep the diodes pointing at the correct angle. The long lead on a diode is the Anode, solder a 100 ohm resistor to each diode. Solder leads of the diode and resistor close and leave a long lead on other side of resistor(see photos). Test each combo before moving on. AA battery and 2 test leads will dimly light the diode and verify you have the correct polarity.

Put diode/resistor combo's back in enclosure and position leads in a zig-zag pattern so each resistor lead touches the next resistor to create a ring. Solder all leads. I would mix some J-B weld Plastic Bonder (https://www.amazon.com/J-B-Weld-50133-Tan-1-Pack) and epoxy the diode/resistor combo in place. I considered super glue but was unsure if the Cyanoacrylate would fog the diode lens. I did this at the end of all my soldering but wish i had done it here to reduce frustration when diodes would not hold in place during soldering. The epoxy sets up in about 15 mins so a good place to take a break.

Now all the cathode leads can be soldered together to create the - or ground ring. Add 18 gauge red and black wires to your diode ring. Test the completed array using a 5 volt power supply, USB charger works good for this.

Buck/Boost Wiring

LM2596 DC-DC Buck Converter.jpg
IMG_20200206_084702.jpg
IMG_20200206_101845.jpg
IMG_20200206_092626.jpg

Before wiring in the Buck converter, we will need to set the output voltage. Since we are using the PDP to supply the 12 volts I wired direct to a PDP port , fused at 5 amps. Clip a voltmeter to board output and start turning the potentiometer. It will take quite a few turns before you see a change as the board is factory tested to full output then left at that setting. Set to 5.15 volts. We are setting a few millivolts high to match what the Pi is expecting to see from a USB charger and any line loading from fan and diode array. (During initial testing we were seeing nuisance messages from the Pi complaining of low bus voltage. A internet search gave us the information that the Pi was expecting more that 5.0 volts as most chargers put out slightly more and the typical power supply for a Pi is a USB charger.)

Next we need to prep the case:

The buck converter and Pi are held in using 4-40 machine screws. #43 Drill Bit is ideal for creating precise holes for taping 4-40 threads. Hold the Pi and buck converter to the standoffs, mark then drill using the #43 drill bit. The height of the standoffs allows enough depth to dill without going completely thru the back. Tap the holes with a 4-40 blind tap. Self taping screws used in plastic would work well here, but I had the 4-40 screws available, so that was what I used. Screws are needed to allow access to the SD card (no external access to card is provided with this enclosure).

The next hole to drill is for your power cable. I picked a point at the bottom corner so it would run along side of the Ethernet cable externally and to side of and then under the Pi internally. I used a shielded 2 wire cable as its what I had at hand, any 14 gauge wire pair will work. If your using a non jacketed wire pair put 1 to 2 layers of heat shrink on the wire where it enters your enclosure for protection and strain relief. Hole size to be determined by your wire choice.

Now you can solder the wires to the input lines on the DC-DC converter. The connections are labeled on the board. Red wire to in+ Black wire to in-. Coming out of the board I soldered 2 short bare wires to act as wire post to tie in the fan, Pi and transistor.

Final Wiring and Epoxy

IMG_20200206_085901.jpg
IMG_20200206_085809.jpg
IMG_20200206_104520.jpg
IMG_20200206_110424.jpg
IMG_20200206_110932.jpg
IMG_20200206_112648.jpg
IMG_20200206_114916.jpg
IMG_20200206_115820.jpg
IMG_20200206_132039.jpg

Only 4 connections are made to the Pi. Ground , Power, Led control and camera interface ribbon cable.

The 3 pins used on the Pi are 2, 6 and 12.

Cut a red, black and white wire to 4 inches. Strip 3/8 inch off insulation on both ends of wires, tin ends of wires and tin pins on the Pi.

  • Solder red wire to GPIO pin 2 slip 1/2 inch of heat shrink tubing apply heat.
  • Solder black wire to GPIO pin 6 slip 1/2 inch of heat shrink tubing apply heat.
  • Solder white wire to GPIO pin 12 slip 1/2 inch of heat shrink tubing apply heat.
  • Solder red wire to buck out+
  • Solder black wire to buck out-
  • Add 1 inch heat shrink to white wire and solder to 100 ohm resistor and from resistor to transistor base. Insulate with heat shrink.
  • Transistor Emitter to Buck -
  • Transistor collector to Cathode side of diode array
  • Diode array Anode/Resistor to Buck +
  • Fan red wire to buck out+
  • Fan black wire to buck out-

Last Connection:

Push in camera interface cable. Cable connection uses a zif connector(Zero insertion force). The black strip on the top of connector needs to be raised up, the cable placed in socket then connector is pushed back down to lock it in place. Use care to not crimp cable as the trace in the insulation may break. Also connector needs to be inserted straight for ribbon cable to pin alignment.

Check your work for stray wire strands and solder blobs, clip back any excess length on the buck solder posts.

If your happy with your work the fan and camera can be epoxied in place. A few drops at the corners is all you need.

Software

BlueGoal-132in-Center.jpg
BlueGoal-228in-ProtectedZone.jpg
BlueGoal-Far-ProtectedZone.jpg
RedLoading-048in-Down.jpg

While the epoxy is curing lets get software into the SD card. you will need an SD card adapter to plug into your computer(https://www.amazon.com/Reader-Laptop-Windows-Chrom....

Go to:

https://www.raspberrypi.org/downloads/raspbian/ and download Raspbian Buster Lite. To flash the SD card with raspbian you will need another software tool BalenaEtcher and it can be found here, https://www.balena.io/etcher/

The epoxy should have cured enough by now that you can install the SD card and screw down the buck/boost board. Before snapping the cover on, check that no wires interfere with cover and camera cable does not touch the fan blades. After cover is in place I blow on fan and watch to see it move to ensure there is no interference from wires or the ribbon cable.

Time to power up:

First time powering up you will need a hdmi cable, if a Pi 4 a mini hdmi cable, usb keyboard and hdmi monitor along with a internet connection. Wire to a 12 volt power supply, PDP with a 5 amp breaker.

After logging in, first thing to do is run the configuration tool. This is where SSH can be set along with enabling the PI camera. https://www.raspberrypi.org/documentation/configur... has instructions to help.

Reboot before installing Chameleon Vision https://chameleon-vision.readthedocs.io/en/latest/...

Please visit their site before using their software, they have a wealth of information. One note, on their supported hardware page the Pi cam is shown as not supported, but it is with their newest release. The web page is need of updating.

From Chameleon vision web page:

Chameleon Vision can run on most operating systems available for the Raspberry Pi. However, it is recommended that you install Rasbian Buster Lite, available herehttps://www.raspberrypi.org/downloads/raspbian/ . Follow the instructions to install Raspbian onto an SD card.

Ensure that the Raspberry Pi is connected via Ethernet to the Internet. Log in to the Raspberry Pi (username pi and password raspberry) and run the following commands in the terminal:

$ wget https://git.io/JeDUk -O install.sh

$ chmod +x install.sh

$ sudo ./install.sh

$ sudo reboot now

Congratulations! Your Raspberry Pi is now set up to run Chameleon Vision! Once the Raspberry Pi has rebooted, Chameleon Vision can be started with the following command:

$ sudo java -jar chameleon-vision.jar

When a new version of Chameleon Vision is released, update it by running the following commands:

$ wget https://git.io/JeDUL -O update.sh

$ chmod +x update.sh

$ sudo ./update.sh

LED Array control:

Your LED array will not light with out software control.

First robotics this year has a rule against bright led lights, but will allow them if they can be powered off and on as needed. Colin Gideon "SpookyWoogin", FRC 3223,wrote a Python script to control the LED'S and that can be found here:

https://github.com/frc3223/RPi-GPIO-Flash

This system will also run FRC vision if your team has already invested the software time in that platform. With FRC vision the complete SD card is imaged so no need to download raspbian. Get it here https://github.com/wpilibsuite/FRCVision-pi-gen/re...

This will get you a vision system in a cool form factor. Good luck at the competitions!