Video Streaming Update 2020 – Robotic Vision

Since my old video streaming tutorial get a lot of view I wanted to add some new info and an introduction. If you are building a robot and need to stream video this is for you!


Why android to desktop


The android device I use is an old old v21 phone. I can buy them for $5 a piece or just ask around for an old phone in someones junk drawer. I waned something cheap and available. Lots of sensors too. Compare that to a naked raspberry pi at $35 with no camera and much weaker software.


If you are using neural nets then you need some processing power. Sending video is a good option to avoid weighing down your bot.

Streaming from android

The older posts that you linked from used the basic camera api. DO NOT use the basic camera api.

The second thing I found is bigflake. Its useful but its complicated and I don’t think its that fast although it was difficult to benchmark.

Every app that uses an android is using the webrtc framework; google video, snapchat, signal etc. However webrtc has a very limiting api an is designed for video calls. However I found this library on github. It opens the api and allows you to extract video frame by frame. My remote computers start video command has a 740 ms turnaround before recieiving its first nal from the remote camera on my home network.

video rec


These two txt files are the classes that extract video from my android. I draw them on a texture but you dont have to if you want a blank screen. It takes 16ms to encode and 5 ms to packetize and send using the packetizer from the older tutorial.



FFmpegframegrabber is used to grabframes and display them.

My first hang up was installing.  You need to install the latest release as library.


final FrameGrabber grabber;


grabber = new FFmpegFrameGrabber(inputStream, 0);

Although I still cannot benchmark it properly I have got it working in “real time” . I had to download the snapshot,  change a variable by hand, build it and then paste that jar to replace the javacv.jar that came in the release files you downloaded above/

line 926  change it from 0 to 1 to eliminate the latency

// Enable multithreading when available

Heres my stack overflow question.

The older section goes into detail and the packetization is still required. The other parts are worth a read too.

0-10 to 5 pwm

I purchased a diode laser from amazon. Bigger than my older laser. Has pwm cause im fancy.

But i needed 5v pwm and my mach3/breakout board provides 0-10v analog. The easiest solution I could think of was once again to slap a nano on it.

Here I am testing the circuit.

The circuit uses 2 10k resistors as a voltage divider to accept the 0-10 volt signal into the arduino analog inputs. The other component is a 5v regulator to power the arduino off the cnc power supply and the knob simulates the mach 3 for testing.

The arduino library makes the code so easy. Pin 5 gives a 980hz signal and other pins give different lower signal so choose accordingly. I cant think of a reason to hassle geting into the Timers and increase the HZ.

#include <Arduino.h>

//duty is 0-255
int duty = 0;

void setup()
    //pin 1 reads 0-10v /2
    pinMode(A1, INPUT);

    //output a pwm at 980HZ
    pinMode(5, OUTPUT);     


void loop()
    duty = map(analogRead(A1), 0, 1023, 0, 255);
    analogWrite(5, duty);



When its done I put it in a 3d printed case and hot glued it to power supply.

Casting aluminum a bit more

I have had some more practice with casting aluminum and now I have even upgraded my oven. My original ovens electrical plan did not account for wire durability based on wattage and length of wire so it quickly wore out.

I also attached an arduino nano to the oven so I could quickly enter rising and falling temperature times.

Further, because I now havea 3d printer I have been doing lost pla casting. Its much faster and the shrinkage can be predicted pretty accurately.

Below is a cut and paste of the results. Most of the time you need 105% enlargement for parts that can fit in your hand.


Name Description 3d length 3d width 3d inside wax length wax width wax inside alum length Alum width alum inside target length target width target inside shrinkage Oversize Post Calc notes
7mm roller pin pin for hypocycloid 7.5 7.41
hypo cam spacer spacer for 100:1 cams 18.8 38.7-38.8 14.92 18.2 38.2 14.75
7mm roller 103% scaled up na/ stem 7.03-7.15 5.02-5.12 6.81 4.79
cam spacer 103% scaled up 19.45 40 15.3-15.4
square block 103% scaled up 11.87 65.37 26.74-26.84 11.4 64.61 26.88-27.12
Eccentric 103% scaled up 82.29-82.38 4.89-5.13 10.10-10.20 4.83 9.8 Stipling came in perfect but required light sanding which quickly pulled .2 of item
tree 6.91 6.71



Here is an example of how easy it can be to cast. Casting is not really ever easy. Its time consuming.

lost pla casting


Below is my whole aluminum casting setup. You can see the oven is upgraded with a control unit and relay. I use a vacuum as normal to draw down pressure during pour. The toaster oven preheats the parts so they don’t have moisture.

Below are two of the parts. I whacked it with a hammer to see if it would do anything. It didn’t.





3d printing

So 3d printing has made me pretty lazy. I really hate milling aluminum when I can just 3d print. I have 3 printer right now. 2 FDM and 1 SLA. I never use the sla tbh.

I bought the ender 3 printer and upgraded them with new firmware, raspberry pi an auto level and a few 3d printed hardware pieces. The whole thing is tented to preserve heat. Works great and prints incredibly strong and accurate parts.

The featured image of this post is a perfect example. Something incredibly tie consuming to make and requiring several pieces of equipment can now be churned out in an hour as I read a book.

I’m glad I got some experience with other methods of fabrication because 3d printing is like heroin. Its really hard to stop and makes you really lazy. But its so useful. Check out the mini table saw jig I made to cut steel. Its powered by a little fishing weight.


Here are a few pics of my setup. The ender 3 is a great printer. Notice Im printing tough pla left and polymac pc on right. Both super durable.

Then I turn up the heat.

Here’s the SLA. Quality is great but the parts are fragile. Still I’m keeping it around I keep it enclosed in black and I have venting set up to keep my work space air clean at all times.



Computer Screens Cause Blindness

If you didn’t know count yourself lucky to find out now.I was dumbfounded and angry when I found out.

 I had unknowingly subjected myself to an experiment and lost some vision in my right eye as a result!

Below is my computer set up with two screens. After about a year of this my right eyes vision started to deteriorate. Dry eyes and pain still plague me to this day but I am recovering to some degree.

computer screen cause blindness

My front screen was opened to an IDE with a black background and my right screen was opened to a search engine with a white background.  In about a year of installing that second screen I started to notice my right eye was struggling to focus.

I though I was just getting old, working too hard, all kinds of excuses. But thankfully someone recommended me to get blue light glasses.

I purchased glasses on amazon to block out the damaging light and I wear them all the time now because my right eye remains sensitive and is prone to being strained. Check them out through the amazon link below as it helps my website out.



What would a blind person pay to have their vision restored?

The most embarrassing part was my brother had recommended them to me a few years earlier but I just didn’t even care at the time. Now I have to suffer, as even 1 year after starting to wear them I still have eye strain.

Your eye are damaged by certain types of light toward the colors blue. These radiate from all sorts of thing like light bulbs to computer screens.

Save your vision while you still can! I tell everyone I meet to get a pair of these. I preach it like a religion. Blue light glasses, 3d printing and java are my holy trinity.

Toyota Tundra Backup Camera

Vehicle back up cams are kind of a pain to install. this was no exception but the results are nice. I installed this in my 09 tundra. With this kit from amazon. Please use link as it help support my website.

Open and in reverse.

tundra backup cam

When its closed.





The kits only $25 so it not that bad. The hard part is figuring out the wiring.






Electronic Speed Controller

Every project I take on teaches me something new. Oddly enough its never humility.

My recent design of an electronic speed controller for a brush less motor was a long and winding road in understanding how a motor could be controlled.

The why is simple. If you want to build a robot there are zero…I mean Zero low cost and effective solutions for actuation. Take that servo and send it back to wherever the hell it came. Its weak and expensive. However there are, separately a large selection of very powerful and cost effective motors thanks to the quad copter market.

If you have ever noticed though these motors require an electronic speed controller (esc) and the esc does quad copter things. Like accelerate in a single direction. That’s pretty much it. So I set out to make this motor do exactly what I required from it. EVERYTHING.

I chose arduino nano simply because I do not want to buy a motor control chip and rely on sourcing parts. These arduinos are cheap and I buy them in bulk becuse everything I own has an arduino hot glued to it.

The code

The code is simple in concept. Allow power to flow in and out of stator at different wires at different times in order to attract the stator coils to the magnets in a coherent and useful way.

* PIN Chart   PWR  GND   Comp/BEMF
 * Phase A      2    3      8     
 * Phase B      4    5      9
 * Phase C      6    7      10
 * Phase Cycle Chart
 * PWR GND BEMF     Step        Short-Step
 * A    C   B       11010000    11011100
 * B    C   A       11000100    11110100
 * B    A   C       01001100    01111100
 * C    A   B       00011100    11011100
 * C    B   A       00110100    11110100
 * A    B   C       01110000    01111100



My arduino used 6 pins to control 3 high and 3 low side mosfets. As you can see I attempted to use back emf but this is no good for robots because the motors cant be guaranteed to be traveling fast enough. I ended up adding low active hall sensors which work great.

The codes broad strokes are as follows:

timer_1: This is used for timing steps. Each time its called a step counter is incremented. This allows precise step timing.

timer_2: This is used for pwm. It also actually checks if a step is due to be taken and performs the pin changes.

Besides these 2 function which are precisely timed everything else is in a loop and is done as needed as fast as it can. These other functions include reading serial comm, or the hall sensors. When data is read it pushed to a variable and the timer 1 or 2 sensor will notice affect the change when appropriate. Only a thousand lines of code but between debugging the board and my code it took me a while to build up to this.


Below you can see a preliminary test.


I’m still working on the code and probably will be for some time because I have included a strain gauge to help the motor determine when it should attempt to move a load or give up.

I’m also using the hall sensors as position encoders. They work great on their own and even better when you consider the gear ratio of 39 attached to the motor.

In the below video you can see the 3d printed support for the hall sensors is attached


The board

I feel more comfortable coding and board design sometimes is like black magic when my calculations don’t work out and I end up just guessing for a better result. The circuit isnt too crazy. Six mosfets 3 high and 3 low side allowing power in or out the 3 connections. The hall sensors are attached to 10k pull up resistors and leds for debugging.


Below is my end goal of building a cheap, powerful actuator for robotics. This video is my first test run of connecting a motor to a gearbox. It was exciting bu the motor could only move 1 lb at 10 inches. I have since moved 10lbs at 10 inches which is as far s I know makes it one of the strongest fastest and cheapest robotic actuators ever assembled. Cant wait to get this out to people!

Gear Design


1.  Types of gears

2. Gear arrangements

3. Considerations – Strength, speed,  friction/noise/vibration

4. Layout Calculations

5. Hypocycloid

6. Differential planet

1)  Types of gears

When looking at involute gears there are several categories of this type. Gear arrangements and types of gears are often used interchangeably but in my mind they are different. Lofting a gears dimensions to change the angle at which is attaches another gear does not make it inherently different to me .

Spur gears are easy and have the lowest tooth friction from rubbing friction.

Helical gears are stronger due to inclined teeth. Increased friction as teeth slide together but the transition is less dramatic and therefore smoother (noise, vibration)

Worm gears have the highest friction. Almost impossible to back drive. Properly designed can transmit high torque at significant reductions.

It’s fair to mention that each type of gear above can be designed simply or with great detail. A spur gear may be as simple as a wooden wheel nails in the radius. A worm gear may be a worm and helical meshed by single tooth or a throated worm gear. A helical can be mirrored into a herring bone. It goes on and on…


2.  Gears can be arranged a variety of ways. Not much to add except there are numerous other layouts and arrangements and gear shapes.  These layouts below are the most common. In each arrangement You will see variations in the cogs themselves that reflect the types listed previously.

Linear System






3. Design Considerations can become complicated quickly. Factors to consider are torque ratios, the speed at which the gears will operate, the loads they will encounter, the required lifespan, the noise or vibration created,  the types of metals and friction coefficients. I’m going to focus on planetary gears after observing someone else’s work designing gearboxes.

4. Layout calculations

If a gear system already exist its very easy to calculate the reduction ratio. For example  if two gears connect in linear and one has 25 teeth and the other 50 then its obvious that the small gear will need to turn 2 times to turn the big gear once.  Or observing a worm gear you will see that one turn of the worm will move the worm wheel 1 tooth forward.

When lay outing out gears on you cad software you need to be precise. Lets start easy and work towards the planetary gear system. Gears can be drawn as circles based on their pitch diameter. When two gears mesh and interact they both meet at their pitch Diameter. Below its the green circle between the smaller(root diameter) and the larger (outside diameter) in white.

gear layout In order to figure out a gear reduction we get the radius of the pitch diameters and divide.

x/1 = R1/R2

So a 100 mm pd (pitch diameter) circle and a 50mm pd would be

2/1 = 50/25

Now the next question is how to actually place them adjacent to each other. We simply add both radius up and place center points that distance away.

One last important number is module. Module = pitch diameter/ # of  teeth

There are other important names and references but they refer mostly to how the teeth interact. Briefly the most important 3 are…

Pressure angle = angle of top half of teeth

Clearance or backlash = extra spacing around teeth

Helix angle = helical gear cog/tooth angle

Based on the information above you could design a linear or compound system in cad fairly easily. But for a harder example let look at a planetary gear set. There is a lot to know about planetary gear sets but ill touch on the important starting points.

Planetary or epicyclic gears are similar to any linear gear arrangement except the are circular in arrangement. As seen below a center gear called a sun is surrounded by smaller gears called planets and then encased by a ring or annular gear.

These gears use the same spacing convention when designing in cad as linear gears. The use very similar reduction ratio math with two major differences.

First, the number of teeth on the planets is not used to calculate the reduction ratio. Add the sun gears number to the ring gears numbers to get conversion ratios.

Second, assume that 1 gear is drive gear, one gear is the load gear and one is fixed stationary.

So, imagine a gear as follows. Sun = 10 teeth, planets = 10 teeth(we will use 40), ring = 30 teeth. Using these number we make a fraction with the load gear as numerator and drive gear as denominator.

ratio = load/drive

Ring fixed and sun drive planets 40/10 = 4:1

planets fixed ring drives sun 10/30 = 1:3

The same math can be done using pitch diameter and circumference as shown in previous examples. Also consider if you could mechanically lock each of these gears or input/output force at will. You could get all sorts of interesting combinations on the fly similar to an automatic transmission.

There are other types of very interesting planetary gear systems.


Hypocycloid Gears

Here is an example gif that says it all.

Pitch diameter only plays a roll in the mechanical strength. Obviously there are ratios to maintain but to calculate reduction use this…

Ratio = (outter cogs/ cam cogs) – cam cogs

The example above has 11 outer cogs that look like white half circles and 10 inner cogs which are the yellow bumps. This gives a gear reduction of 10:1.  Green is the power and purple is the output. These can also be stacked very efficiently such as below to create a differential cycloid. You can see pitch diameter is less relevant as angular velocity is the deciding factor as opposed to tangential velocity. The example below is the single cam in a motor mounting gear reduction box that produces a parallel or co-linear output.

Calculating the difference in a differential hypocycloid is done as following.  I consider the bigger cam the drive side.

drive = d, load = l, ring = r, cam = c

so… drive cam = dc and load ring = lr

ratio = 1/( 1-(dr*lc/ dc*lc))

There are a few scripts and editors for different software to create these. I did mine in fusion 360.


Differential Planet

Here is a cool gear design I found on thingiverse. The creator uses two planetary gears stacked with separate rings and suns and connected by their planets only. Each stack is geared differently.

Planets #1    Sun = 10 planets = 10 and ring = 30

Planets #2     Sun = 18 planets = 16 and ring = 50

Below is a front view and it works like a normal planetary gear. As expected with previous formula 40/10 is 4 turns of the sun causes the rotation of the planets once. The interesting part is the backside.

The backside is geared different from the front and this gives the back ring and additional 25:1 reduction ratio.  On top of the 4:1 to one.

This is accomplished by creating a light difference between the front and back ring tooth count.  The tangential velocity of the front planets are a perfect match to the front ring. But because the back ring is slightly different in size and the planet gears must move with the front sun gear the back ring is forced to move slightly forward or backward. Much like a tire slipping on a wet surface.

To make this easier to imagine imagine just the back ring. If the planet gear were unable to rotate the exterior ring would rotate 1:1 with the planets. Juxtapose the planets could rotate at the exact speed needed to keep the outer ring from moving. Then when you alter that speed even slightly you end up with a very string very slow gear ratio.

I never found an documentation but I tried to define it mathematically.  All these refer to tooth but could probably be done with pitch diameter too.

D = drive ring, L = Load ring, S = Sun, P = Planet, R = annular ring,

LR/((LR/LP – DR/DP) * LP)/ ((DS+DR)/FS)

There may be an issue with this formula as it does no always match the reported gear ration of the device I’m measuring. Sorry for math styling, I do computer stuff so that’s how it should look to me!

Lastly there is also harmonic gear types. I did not do much research into these as the solutions above were suitable for my current needs. At this point the project I’m working on seems to moving forward but I would very much enjoy coming back to some of these gears designs and exploring more.

The Struggle of Custom Parts

Custom parts are hard to come by. Off the shelf parts are literally forming a trash island in the ocean. This is my dive into making custom parts. I could have gone at it a few different ways but my limitations are as follows.

Time – I don’t want to spend 10 hours milling a part

Money –  I don’t wan’t to buy a bunch of new machines

Space – My workshop is packed.  A lathe really wont fit…and I want one really really bad!


My solution is to use my cnc to make mold which I can then fill with aluminum. My goal is to create a worm drive.

In my mind I have defined 3 basic levels of tolerance for parts.

  1. Low tolerance – Toys, piston engine or machine exterior, frame/structural
  2. Medium tolerance – Low rpm gearboxes, actuators, machine interior
  3. High Tolerance – Internals of engine, high rpm gearbox

This worm drive is medium tolerance.

My first attempt started innocently enough with some foam purchased as the hardware store. Its housing insulation and its only $5 a sheet. Its reasonably dense and can be machined very very quickly. Here I am making half of a worm.

My original thought was to make a plaster mold of this foam cut out. But in reality the foam didn’t machine that cleanly. I tried to make a plaster mold of the screw by simply cutting the half’s out and placing them into plaster molds. Here is a mold I made and in this picture its doesn’t look half bad. But it looked terrible up close and because I cut the foam pieces out the precision was lost and it was lop sided. Second the plaster adhered to the foam because the foam had a rough surface after milling. Finally I was using paraffin wax which didn’t separate easily from the foam mold.

Below you can see the pieces I am working with. Not terrible but not great. I may still experiment with this foam and plaster because it would be a cheap and easy method if I could get it working.

I abandon the wax model I created and instead of a plaster mold I tried doing a “sand casting” with delft clay. This was the first time I have ever poured aluminum in my life. Fun, but I knew right away that  I could make it better. Obviously my pours and molds would get better over time.

Here you can see the result. I don’t think this is half bad for a first pour.

Here is my oven that I made. It gets pretty Hot.


Conclusions on first attempts. Sand casting can make type 1 low tolerance items. If I practice more I’m sure I can make items that will need further machining to finish them or parts that will not have any significant mechanical interaction. I’ve even seen lost foam pours into buckets of playground sand on you tube that looked very decent. For low precision work lost foam or wax molds from plaster can make decent items quickly and cheaply.

Moving On…

Now I was getting upset and worried I would not be able to make the parts I wanted. I knew I needed to exert pressure on the aluminum so I finally stumbled upon vacuum casting.

My previous mistakes and experience helped me tremendously. Instead of foam I ordered some machinable wax. I was recommended tooling board but tooling board is kind of a pain to come by and use.

Below I’m machining each half of the worm just as I did in foam except I’m using a tool change to speed it up and I also widened the cavity and added some reference keys so the negative if these would mate.

See the bumps and reverse female sections. Not sure what that big line was about! I used a flat 1mm end mill and the result is very rough. But I will continue with this as the machining lines will make great reference details to compare to my final pour.

Next I poured a two part silicon into each cavity. This is a A45 silicon so its harder and less flexible version than most you will run across prima facie. I could probably stand to increase that number a bit as well.

Here is my setup. I mixed the silicone on my lab scale. I built the vacuum chamber to degass my materials. After mixing I put the red cup in and degassed till the bubbles were evacuated. Then I poured them into the wax molds. Then, once again I degassed silicone in the mold and locked the chamber for maybe 10 minutes before bringing back to normal pressure.

This process resulted in a very successful silicon mold. Every detail was captured perfectly. Hooray!

Next I injected a jewelers wax into the mold. Once again I met a reasonable amount of success.  I could find no difference between the initial machinable wax and this with the naked eye.

After that I forgot to take a few pictures.  But basically I put this wax into a mold with a refractory plaster including degassing it twice. After loosing the wax and curing the mold I poured molten aluminum into the mold and quickly switched on the vacuum.

Here is the result. As you can see the machining marks are identical in both the machinable wax and the aluminum casting. I haven’t done any measurements to compare sizes but I see no reason the size of the final product won’t be 100% predictable and within tolerance of a machined product.

I’m not 100% there yet but you can see after 3 pours things are moving in the right direction.  Problems to still overcome are as follows

  1. Get machinable wax milled perfect texture (or lack of)
  2. Increase silicone mold side wall thickness and reference points
  3.  Glue my sprue on better. I made a mess at connection!
  4.  Minor bubbles were in refractory and show on aluminum
  5. Polish aluminum in vibrator
  6. Determine size variation formula between 3D model and final product

Based on today’s pour I think it will be possible to pour metals the engage in moderate mechanical action.





System -> model -> model -> System

What is the difference between working hard and working smart? I attempt to define that here. A very long time ago I read a Richard Maybury book and it touched on how the brain is attempting to model how the world around it works.

Being a curious person and always trying to sharpen my understanding I easily agreed with that. I built my strategy for accomplishing goals around this simple belief. The title of this post is a strategy I believe in, which is essentially common sense to me now. It goes as follows.

  1. There is an existing system I do not understand. It is abstract.
  2. I create a model based on my interactions. A model is a bunch of beliefs about that system.
  3. I create a model for how to best interact with that system. Synonym is strategy.
  4. I create my own system which will apply my desired model. Think routine, or long term planning.

For example consider fitness. The human body is the system. Too complex for me to fully understand with current research. In my mind I build an approximation of that system on belief at a time to create a model. For example that model says that I need food as sustenance and sleep to rework neurotransmitters and hormones. These are just a few of the many beliefs I have that make up the entire model.

Now lets say for example I want to get in shape. Based on my model of how the body works I need to create a model of interaction that will get me what I want. So for example I need to eat healthy or I need to perform physical training 3x a week. Well knowing what to do is great but doing it is another thing. Now I need to create a system that will enforce that model. So I start a workout journal, and begin packing healthier lunches or researching healthier restaurants, maybe I set a workout alarm or get some workout equipment.

Its easy to just overlook these things and say they are all kind of similar. But that would not be true. If you are attacking an enemy base you know there are soldiers inside(system). But knowing that the west wall is least guarded(model) gives you a strategy to attack there(model). However you failed to apply a way for recruiting and training soldiers(system) so your attack is rebuffed.

Imagine you have a well trained army but you attack at the south wall because you didn’t know about the west wall and still get your butt kicked. Really most people if not all people can take the model of the west wall being the weakest and create a model that focuses an attack there. The hard part is building the model of the foreign system and building your own system to properly utilize the information you have. Those take planning, patience and creativity.