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.

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.





Milling a PCB

In order to better speed up my prototyping and in consideration of possibly small scale manufacturing I have begun milling my circuit board designs.

This picture should give you a clear idea why this is so important. This is how myself, and many others, make circuit boards at home. By wrapping wire around the back and soldering in place. Its tedious and error prone.

I haven’t mastered it yet by any means but I can tell you about my journey and give you some tips. I’m using a self made CNC machine. Everything I used is off the shelf.


I used Eagle to make the design. Its a popular software and free to use for non commercial. There’s so much to say on the subject of design and using the eagle software. Kicad is another. Not super easy to use and it gets a bit tougher if you want to export to a machine for production. After you make you schematic you click generate your board.

  1. You need to set the net thickness and spacing sizes based on your machine, bits, and personal skill.  I chose 30 mil size and 40 mil space.
  2. The measurements are not millimeters but thousands of an inch. Leave it that way and convert. Otherwise you’ll be fighting the software.
  3. Your origin is at the bottom left. After making you design you need to drag the entire thing to center it over your origin if you want to start your machine off in the center.

There’s a lot more to be said but I suggest you watch some tutorial or do research as needed. Use the cam processor and create your gerber files excellon file for next step


Creating G-Code to execute

A free software called flatcam can be used to transform the gerber files and excellon drill files into gcode. For simplicity same I made my project by using only two files the bottom.gerber and the drill.xls

Flatcam creates a tool path to isolate your circuits by using the layout and your input. A few key things.

  1. Your tool size must be smaller than the net spacing you entered in eagle. Otherwise it wont try and cam that area and you will have gaps. I chose .039 as my tool size which is a hair smaller than the 40 mil I put in eagle and is about 1mm for my sanity.
  2. I chose .5 for z travel because I have a floating Z I need .25 inches to lift the float and .25 for clearance. You will see more on floating below.
  3. Speed I use 3.5 and its running beautifully. The project you see above is milled in about 10 minutes.
  4. Flatcam cannot interpret drill files correctly. I’m still not sure why but two things I needed to do. When I imported my drill files they were miles away and huge. First type these two commands into the command line “get_sys excellon_zeros” and “set_sys excellon_zeros T”. Second open the drill file and set each hole size to .050 manually.

The floating Z

When you first try milling a pcb you will find that even the slightest unevenness between your board and the bit will result in all kinds of issues. There are two ways to solve this problem. The first is using a probe to electronically measure and calibrate for this issue over the entire board. The second is to just make the axis spring loaded and let it slide over the board and roll with the waves.

In the video I explain it and give you a good look. Those are just 6mm slide rails and a pack of miscellaneous springs. I now use a makita router due to runout issues from the cheaper router I had in this video.

Here is a video of it running.

I tried small drill bits without success and ended up using engraving bits. I had some really rough experiments where I was snapping bits left and right and making ugly cuts. Eventually I got my machine and software tuned.

Before floating… so much uglyness. Bottom right has tearing. The main line just lifts away
much better
didn’t have my origin set right

Finishing them up

Because I use the floating z and an enraging bit I would need to change my set up to drill them out. So for now my engraving bit marks the drill holes just a bit and I drill out the marking on my drill press. One drilled I lightly sand with 1000 grit, then use a steel brush then a nylon brush.

After I use compressed air to blow any dust off and check to make sure there the traces work with my multi meter by doing an audible continuity test.

After my designing and experimenting I can now take a circuit like this from a solder-less bread board to a finished project in about 2-4 hours.


Considerations on building a robot


One of my childhood interests has always been robotics. I think most people have at least somewhat of a fascination with robots when they are young. Over the last several years when I was working I began to realize that robots in construction are really underdeveloped.

The reason I believe this is because I spent a lot of time learning and teaching construction skills. I realized during that time that robots in construction are imminent and could have been introduced already.

My goal is to experiment and build a robotics platform that can accomplish some of those construction task and hopefully more.


Frequently in construction a skilled tradesman learns a variety of skills necessary to accomplish a task. In many situations the task can be broken down into several parts and an several unskilled people can perform the task in assembly line fashion even faster. The biggest limiting factor in this situation is keeping them mobilized because work gets done fast, and bodies have to be moved and the set up at each location. You also need expert intervention 5% of the time.


Here are some of my goals for a robot design that would make robotics go mainstream.

  1. The indifference to going mainstream( no hype benefit is obvious)
  2. Low production cost (self replication)
  3. modular hardware and software (easy to repair/upgrade, group learning, remote upgrades)
  4. Wide functionality ( building, cleaning, cooking, driving)
  5.  Remote intervention (1 person supervising 20 robots at remote location)


Final Thoughts…

Any one who knows me knows I’m trying to exit the economy. As a thought experiment imagine a square cube 18″ in size that glows with a soft white light. This box, by voice command, floats through the air absorbing zero point energy and can create any object imaginable. How would the world be different?  Self replicating robots have the power to make most people irrelevant or give them new purpose. The power to destroy conventional currency, which buys human labor, and replace it with a guaranteed deflationary electronic currency or simply replace currency with code. Robots will be necessary to build spacecraft as well or maybe fight a war. A war which  might be created because of the excess they themselves produce.

I wonder if the immediate downside is that it will increase production to such a large degree that our current culture of greed and conspicuous consumption in some countries and overpopulation in others may spiral out of control. There may also be a dramatic shift between people who understand how to manipulate the robots and the people who do not. Hopefully the smart and hardworking people can use the production increase to escape the current system and build something better.