Fighting with computers

Computers are not always friendly.

Sunday, December 13, 2015

Presentations' clock

I was recently invited by Pablo Murillo to give a talk at Zaragoza Maker Show and I wanted [among other things] to present and hands-on project to the audience, outlining the process I followed to get it done.

I was lucky my friend and fellow "Arduinist" Colin Dooley gave me away a 15-led addressable RGB stripe a while ago. Unfortunately, the Cylon effect (aka Lasrson scanner for those old enough) was already taken as one example from FastLED library, so I had to do something else.

I have chosen the title "Beyond Blink" for my talk, so it would be nice to get something that, while blinking, performed a more useful work. So what I decided was to use the 15-led stripe as some sort of presentations clock, that will help the speaker to know the time elapsed, a new led lit each minute, while of them is blinking each second.

But as many talks are longer than 15 minutes, I repeated the same pattern with changing colours for each next quarter. Red being the last color, since third quarter on. Talks should probably be no longer than 45 minutes anyway.

Later I thought that this contraption may also be of interest for the audience, so they too have some feedback on how time is passing during the talk, so I ended up placing it facing to the public during my talk.

I have made no effort on getting a very accurate time measurement, so I won't be surprised if is the thing is a bit off after half an hour, but if there is shift I assume it would be pretty small. Time starts ticking as soon as you plug it in. I used a USB port on the same laptop used for my presentation and I rushed to finish my talk during the allocated time frame. Looking at it instead of checking your watch during the talk looks likely better too.

I told the audience it would be my Christmas gift for them to post the code, so no matter you celebrate it or not you can grab it from here too.

Hardware-wise you just need three wires to connect the stripe to the Arduino, +5V, GND and data pin. I am using D9 pin as a data pin, but you may change it to any other pin you want. Please note you need FastLED library installed on you Arduino IDE or you get a compile error.  For a portable unit you can use an Arduino Pro Mini and a battery or a Nano or Pro Micro and a USB power bank.

Friday, December 11, 2015

Better accuracy from your encoder without more interrupts

Since I published my DC motor control project on youmagine I have got some feedback from users with 2000 PPR (pulses per revolution) encoders or more where they end up having trouble above 3000 RPM. The reason is that the poor Arduino cannot process the interrupts fast enough and the system becomes unreliably.

While optical encoders are available quite cheaply, some of the magnetic sensors from AMS are very competitive and offer very good accuracy (from 12 to 16 bits). One interesting model (due to its low price) is the AS5600, that provides a 12bit angle measurement for less than $2. Measurement data is read by means of an I2C serial bus and needs no interrupts.

Hopefully those having trouble with interrupts can switch to this type of sensor, but model AS5600 is most likely a bad choice as it is intended to replace manual knobs in hi-fi equipment and it will not work at high RPMs (in fact the manufacturer does not provide the max RPM at all).

But for position control applications maximum speed will not reach more than a few hundred RPM tops and for those this cheap sensor maybe a good fit.

I contacted moti project developer who is using this same sensor for his intelligent servo and he was pleased with it.

While chip manufacturer provided an Arduino library I cut the only piece of code I was interested and copy it to my project as a simple function. Time measurement showed that a standard I2C speed (100Khz) took 0.92 milliseconds, but after pumping up the I2C clock speed I lower it to 0.22 milliseconds.

One additional thing to address if your application uses multiple turns is how you manage the wrap around of the angle measurement. It took me a while to figure it out, but within a certain bound of rotational speeds checking for a gap between previous and current value larger than 3500 did the trick for me.

Below you can see a piece of code to get you started, providing a measurement between 0 and 4095 representing an angle between 0 and 360 degrees.

Sunday, December 06, 2015

Getting dropcutter to work

For my CAM project I was using a 3D offset of the parts to compensate for the tool diameter. But i have recently have incorporated a new feature so 3D assemblies of blocks can be represented in 3D. For the automatic assembly (courtesy of Carlos Sánchez) I cannot use the offset surfaces but I have to use the original meshes.

One way of machining a 3D mesh is dropcutter algorithm, that in a nutshell works by modeling the milling bit and setting the z-depth at each XY location so the model is barely touched by the tool. As meshes are made of triangles, each feature of them is tested for contact: edges, facets and vertices. The feature with the highest z-depth value will set it for that particular location.

I have found a lot of insight and useful information in Anders Wallin blog. Though my initial approach was to adapt his monocam's C# code to Java, I ended up with a buggy result. Anders released later a C++ library, opencamlib, that is most likely a much improved version, but I did not test that. Instead I built from scratch my own Java version that now seems to begin to behave properly.  It was not too hard as I am only implementing the ball-nose cutter (that is why you see the yellow spheres above representing the tip of the cutting bit).

You can can have a better view of the above here:

And in case you are wondering what the hell this part is, you can see where it will fit in:

Wednesday, December 02, 2015

Native 64bit Meshmixer version

I have just noticed there is a new version of Autodesk's Meshmixer software available for Linux but this time is no longer running over wine but it is compiled to run in Ubuntu 14.04 64bit. And the first tests suggest it works reliably (only crashed once when searching on the online 123D library).

It is a great program and it is free to use so I find myself using it from time to time. There are quite interesting but unexpected uses.

It is been a while since I last checked, so do not bash me if this is not new news for you, I now it was released first around March 2015, but I am a bit slow :-)