Freesteel Blog » Machining

Monday, February 16th, 2015 at 8:49 pm - - Machining

Quick report on the misery of trying to get any good data out of these fancy good-for-nothing data sensors.

I did a bike ride on Sunday around Yorkshire, from Barbon to Dent, up the valley, down to the very fine Cafe Nova in Sedburg and then back to Kirby Lonsdale via a bridge over the river Lune where Becka and I went kayaking in January and got scared (it looked a bit tame in these water levels). This was the day after the day before where I broke my caving famine and did a nine hour Easegill traverse from Pippikin to Top Sink while the hard people (incl Becka) did the reverse route and went out Bye George to celebrate Tom’s birthday. (This was the same Tom who drove out to Austria with me last May so I could go hang-gliding when Becka stood me up to go on a caving holiday.) Hint: for my birthday I will not be going caving.

So, anyway, you’d think something as simple as the GPS-altitude and barometric readings would be somewhat related.

This is what the plot looks like of barometric pressure along the X-axis (zeroed at 990Mb) vs altitude, which ranges from 102m to 305m. Yellow is the first hour, where we went over the hill, and blue is the second hour peddling up the valley from Dent.
baroalt1

Not a great correlation. Here’s the same picture zoomed in. The squiggles are predominantly left and right accounting for the noise of the barometer readings.
baroalt2

Suppose I take a rolling average of sequences of 7m and plot the same here without all the noise, getting the yellow line.
baroalt3
Still pretty wobbly. The cyan is the plot of the barometric forumla which is:

101325*(1 – 2.25577e-5 * altitude)5.25588

This is near as damnit a straight line of slope -0.08488715682448557. Applying simple linear regression to the slope gives -0.08992119168062143, which is not a great match.

Maybe I ought to work out a way to do this calculation in run-time on the device itself to give a measure of how rubbish the altitude-barometer agreement is during operation so I don’t have to bring it back here and run these complicated python programs on the data.

Then I could see if it’s responsive to the mode of travel, eg bike vs walking up and down the hill.

The next correlation to look at from this data is tilt of the bike frame registered from the accelerometer vs the slope climb according to the GPS. I’ve got very little hope this will work, so have put it off. I’m already sure that the temperature vs altitude signal is completely lost in the noise, probably due to the proximity to the ground on which the sun was shining.

I hope to see something better if I ever get this thing in the air. Right now I’m 3D printing enclosures to grip on to the base bar and am gathering a desk full of lots of bits of useless bits of plastic. Got to push on and not be distracted.

Wednesday, February 4th, 2015 at 11:14 pm - - Machining

So I had to bodge the wind sensor interrupt readings and filter out the glitches. Beyond that, there’s a heck of a lot of variation in the readings when in front of the fan (getting 12mph wind, according to the proper device), and even at the nozzle of the vacuum cleaner (where the wind speed was 42mph). Either there’s still turbulance or the sensor is wobbly. Not impressed.

fandrier
Next up, there’s the sudden-air-temperature-from-flying-into-a-thermal detector based on the analog TMP36 connected to a large capacitor to bring the voltage changes down to zero, and so they can be put through two op-amps (one for positive and one for negative changes).

I turned on and off the hair drier behind the fan that points at the dangling circuitry and got this trace.
fandrierplot
(more…)

Wednesday, January 28th, 2015 at 11:52 am - - Machining

As I suspected, this is where all my grand designs go completely wrong. Recall that I proudly got the wind speed probe to convert each passing of the fan blade into a square wave voltage spike earlier this month.

Well, the reading of this signal was to be done with the following code:
(more…)

Friday, January 23rd, 2015 at 11:25 pm - - Machining 1 Comment »

After spending a few days with all my bits and break-out boards in a bowl and stirring them around aimlessly, I got all the major SPI components lined up on a breadboard, like so:
breadversion

That’s an SD card writer, an OLED screen display, a bluetooth low energy and a GPS module.

The additional devices are on short 4-wire phone leads in plastic printed boxes of dubious design.

After a great deal of unplanned soldering and the use of header sockets so that none of the bits are permanently stuck in the wrong place, I’ve got a thing that looks like this:

breadversion2

There are issues. The barometer has a separate power supply and now doesn’t communicate, the wind-meter has a degree of noise in its signal, the I2C accelerometer is too complicated, the dallas temperature sensors can only be read one at a time, and all three SPI devices are incompatible with one another.
(more…)

Monday, January 5th, 2015 at 9:00 pm - - Machining 1 Comment »

It’s been a lot of work, and I need a break. This has now outperformed my target over New Year period moping around Bull Pot Farm while everyone else goes caving.

I am now able to make numerous slices on this impellor model made of 38474 triangles with an angle change tolerance between contour sample points of 18degrees in about 5 to 10 seconds per slice using Pypy (or 80 seconds in Python3). The code is at bitbucket.org/goatchurch/barmesh. Use it at your peril. It’s just beginning to work, and the next thing I will do is break it.

Here are some pictures of the results of slicing an impellor shape that’s 20mm in diameter with a sphere of radius 0.2 using the command:

pypy -O main.py –stl=stlsamples/impellor1.stl -v -tswapyz -r0.2 -n52

slicer02surf
Slices with ball radius 0.2 with the STL model shown

slicer02nosurf
Offset slices without the STL model so you can see all the internal contours from the ball rolling along the inside surfaces of the model. These internal contours will need to be detected by connectivity and deleted.
slicer02top
View down the top so you can see the inner and outer offset slices of the central cylindrical through-hole.

From my initial profiling, 99% of the time is spent in the two functions MakePointZoneRF() and CutbarRF(). This is fantastic news as this is where all the point-line-triangle distance/offset-intersection calculations are done. And it’s intended to be very GPU-friendly. (I don’t actually have any experience with GPUs yet, but it could happen now I’ve got a real world use case.)
(more…)

Tuesday, December 23rd, 2014 at 7:39 pm - - Machining

I printed this beautiful box for my speedy accurate barometer at the DoESLiverpool Xmas party designed on Openscad.

greenprinting
(more…)

Friday, December 19th, 2014 at 9:46 pm - - Machining

I’ve been having “fun” trying to deal with the noise on the MS5611 altitude sensor. It’s an extremely accurate piece of kit (detecting approx 10cm of altitude). Last month I discovered that it is very sensitive to its own working temperature, which depends on how frequently it is read. You miss one interrupt and it throws everything out of whack.

So I got one of these Adafruit Trinkets, which is a tiny microcontroller board just to poll the barometer on a timed loop, and attempted to bit-bang the values down one of its output pins to a digital read pin on the main Arduino. Here’s what the the code looks like:

void sendbitbangbyte(uint8_t v)
{
    digitalWrite(PinOut, LOW); 
    delayMicroseconds(BITTIME); 
    digitalWrite(PinOut, (v & 0x01 ? HIGH : LOW)); 
    delayMicroseconds(BITTIME); 
    digitalWrite(PinOut, (v & 0x02 ? HIGH : LOW)); 
    delayMicroseconds(BITTIME); 
    digitalWrite(PinOut, (v & 0x04 ? HIGH : LOW)); 
    delayMicroseconds(BITTIME); 
    digitalWrite(PinOut, (v & 0x08 ? HIGH : LOW)); 
    delayMicroseconds(BITTIME); 
    digitalWrite(PinOut, (v & 0x10 ? HIGH : LOW)); 
    delayMicroseconds(BITTIME); 
    digitalWrite(PinOut, (v & 0x20 ? HIGH : LOW)); 
    delayMicroseconds(BITTIME); 
    digitalWrite(PinOut, (v & 0x40 ? HIGH : LOW)); 
    delayMicroseconds(BITTIME); 
    digitalWrite(PinOut, (v & 0x80 ? HIGH : LOW)); 
    delayMicroseconds(BITTIME); 
    if (v & 0x80) {
        digitalWrite(PinOut, LOW);
        delayMicroseconds(BITTIME); 
    }
    digitalWrite(PinOut, HIGH);
}

Sensible programmers wouldn’t do this because they’d use one of the many standard libraries available that operats on a standard protocol. But I wanted to tactically slot this into the main loop that polls and waits (9 milliseconds) for the barometer/thermometer to make its reading with the minimum disturbance possible. It’s important to keep everything regular and synchronized.
(more…)

Friday, December 12th, 2014 at 9:02 pm - - Machining 1 Comment »

The fact is that this is probably what most visitors to this blog are going to be most interested in.

I’ve another session hacking the barmesh slicing code, which is now creating these interesting subdivisions:
closeslicesubdiv

It can even generate 17 slices of a part without crashing, though it takes a few minutes:
impslices7

It’s still only testing against the points, and not the edges and faces (hence the arcs), but that will only make it crash less as the shapes will be smoother.

It’s a little unclear what to do next. Maybe I should tidy the code further and clear up all these special cases I’ve been hitting and had to hack in to make it work. When a subdividing line crosses the r=0.5 threshold and I calculate it’s location, I’m setting it back to exactly 0.5. I don’t think this is the most reliable way to make it work.

The crucial functions are:
(more…)

Sunday, December 7th, 2014 at 4:14 pm - - Cave, Kayak Dive, Machining

I’m going to do some other coding, now that I got this result. The code would fall apart if I touched it again.
impslicesubdiv

Next on the list of things to do is clear out the vast quantity of rubbish left in the code, completely redo the subdivision loops and make the logic robust, apply it to multiple z-levels and plot slices, then make it test against edges and faces (not just points), and package it into a self-contained (but very slow) version of the slicer.

I don’t know how long this will take, as there are many other distractions available.
(more…)

Wednesday, December 3rd, 2014 at 7:43 pm - - Machining 1 Comment »

By popular demand, I am working on a new Z-slicing algorithm, which is open source and in Python and can be found here. (My latest parts order is taking too long to be picked and come in the post.)

The code is not in any state to be used by anyone as I conduct some very meandering software development. I am unexpectedly basing everything on these BarMesh structures. This is a neat way to represent a triangulated manifold, such as the STL triangle file that contains the 3D input geometry. But also, instead of basing the slice on a strict XY grid (or weave) as I’ve done before, I’m using a second BarMesh to handle the 2D partitioning of the plane.

impellorslice1

I don’t really know what I am doing, but if it gets messy and results in malformed folded cells, at least I can choose to constrain the BarMesh to conform to an XY grid weave structure, which I know works.

I’m just slicing (with a radius) against the points in the input geometry as this creates a more difficult slice geometry to begin with (here it’s an impeller shape with 38474 triangles, so I’m not starting with a toy example).

When the slicer is working, I can extend the code to test against the edges and faces of the input geometry.

I’m going for simplicity, and not being too constrained by speed or memory useage. There’s a lot more memory available than we need, and I’m counting on investigations into some weird Python compiler systems to provide the performance of C++, without the disadvantages of using C++.

I maintain the fact that if you take away the speed advantage of C++ on a particular platform, it loses its point of existence. Therefore the question of whether you should be using C++ is not to be found by looking at C++ itself, but by trying to beat what it supposedly does best using another language.

I can’t predict what will win. But the experience I am about to have ought to be extremely relevant to a programming team that is starting a new product and is having to choose what language they commit to.

This particular slicer will be for 3D printing and it will not notice the problem of mismatching triangle edges or self intersecting input geometry. (Self-intersecting inputs can come when you throw in some support structures.) It will be optimized for taking hundreds of slices and different Z-levels. It will work by finding the offset surface at a particular radius, and then offsetting back in by that radius to get the “true” surface, after the interior contours have been identified by tracking them up and down in 3D to prove full enclosure.