Sunday 3 March 2013

Keepy Uppy hack at Science Hack Day Dublin

Loads of fun, more posts to follow but some pictures for a start.




And all of this gives us data like this ( dropping a ball and then a kick, followed by freefall followed by another kick and freefall pair of events:


Freefall   G:     72 Duration 0.00238265 Launch Delay 2.64402304
FreeFall End

Launch G:    313 Duration 0.00305754
Launch End

Freefall   G:     70 Duration 0.02869233 Launch Delay 0.37855668
FreeFall End

Launch G:    445 Duration 0.04812543
Launch End
Freefall   G:     26 Duration 0.37386897 Launch Delay 0.06773423

Saturday 10 November 2012

More adventures with Raspberry Pi and an IMU

Buying a cheap IMU is definitely a good way to learn about working with sensors. When I last posted about this I'd managed to get some sensible data out of 3/4 of the sensors but hadn't realised all the fun I had ahead of me.

Right now I think I'm about 25% of the way through getting to a stage where I'll be confident about working with this thing but at least I'm now getting good data from all of the components and my Raspberry Pi can tell me this sort of information with a refresh rate of around 100hz:


Accelerometer xyz  g: 0.008,0.023,1.005                                         
Gyroscope xyz    dps: -0.061,0.166,-0.674                                       
Mag xyz        gauss: 0.002,0.055,-0.074                                        
Bearing          deg: 2.045                                                     
Gyro Temp      deg C: 28.000                                                    
Temp           deg C: 25.900                                                    
Pressure      Pascal: 99334.000                                                 
Bar Alt  m (sea lvl): 167.353


That might not look like much but getting this far has involved a lot of work with documents like this beauty, from Freescale.

I'm not finished with the Compass\Magnetometer yet, the bearing data I'm getting right now is only roughly calibrated and not tilt compensated but I now know what I need to do to get that properly corrected. The Gyro Temp sensor doesn't work but that's not a big deal, the barometric sensor gives me a good temperature reading.

The next challenge is getting these properly calibrated and establishing how accurate\noisy the particular components are. The compass and gyro are the big headaches on this front, the gyro because it is inherently a noisy signal and the compass because I need to actually code solid routines for handling both hard iron interference ( ie magnetic interference fixed with respect to the reference frame of the sensor ) and soft iron interference ( magnetic interference that varies with position ).

After a couple of days failing to understand the sensor data I had thought the compass ( a Honeywell HMC5883L ) was broken. When I thought I should be getting numbers that would vary between +-(something) in each axis as I rotated the sensor I was getting something very different:

Bearing             X              Y                     Z
0 -683 -473 -442
45 -773 -420 -436
90 -800 -311 -433
135 -749 -222 -436
180 -647 -194 -441
225 -561 -258 -447
270 -545 -354 -451
315 -589 -436 -449
360 -683 -472 -442


I blame the amount of time I have to work with PowerPoint for the fact that I couldn't see a pattern in that. In any case I thought I should simply be able to apply a tilt transform to make this better but that actually made things a lot worse. I really should have read the Freescale white paper earlier.

Anyway I got led on a number of wild goose chases as a lot of people seem to have issues with this sensor but none of the code that I found helped. I even tried switching over to an Arduino and testing code from a number of sources for that. The code worked, the values still didn't.

The light bulb moment came from a comment on a blog post about the HMC5883(L) from a guy called Cory who worked on a similar IMU that gave me the clue I needed to solve the problem. The comment wasn't actually about the IMU that I have but he said that the BMP085 pressure sensor they used was actually magnetic to some degree and my IMU also uses that pressure sensor. That meant that that there was probably a fairly significant hard iron interference issue on my little board and a quick graph of the above sample data showed me a smoking gun. Ideally, on a calibrated compass with no interference, the data below would have been a circle around the origin but the fact that what I was seeing was vaguely circular was enough to tell me that it was working and all I needed to do was to sort out the interference problem if I wanted it to be useful.


The really important lesson in this is it is always worth trying something visual if you are trying to make sense of data. I think that needs to go into The Rules, preferably with a number somewhere high up the list, just after the bit where you actually pay attention to things like calibration and sources of interference.

A slightly larger data set has given me a baseline transform for the hard iron interference - this is simply an x,y,z offset so it's only trivial code and while it is not as accurate as I want to get to it's more than enough to tell me that the sensor is working correctly. It now reliably indicates that North, East, South, and West are approximately 90deg apart at any rate.

All code is up on Bitbucket ( I seem to be having some sync issues with this right now, that should be sorted out shortly Fixed..).

Wednesday 24 October 2012

Raspberry PI - Interfacing with an IMU

I picked up a dirt cheap I2C capable 10-DOF "IMU" breakout board with from e-bay ( this one here ) just to see how hard it would be to get some motion sensing capability for my Raspberry Pi. I know that we've had all these sensors built into phones for years now but it's still amazing that I can now buy a 3-DOF Accelerometer, 3-DOF Gyro, 3-DOF Digital compass and have a temperature\barometric pressure sensor thrown in for €20. 

After a bit of minor soldering a quick test proved that all the parts were visible over the I2C bus but I could only find Python libraries for the pressure sensor. This was not a surprise, and frankly I wanted to have to work a bit to get sensible data and I really wanted to have a project that I could use to learn Python. 

The breakout board has these sensors:


The extremely useful AdaFruit Learning System has a basic tutorial, complete with a working interface library for the BMP085. I already had one of those working ( it's on a second Pi that I bought because my first one was taking so long, so now it's monitoring the temperature and pressure in my attic - you can see that data here: https://cosm.com/feeds/80617 ) . That sample gives me enough of a framework to try building up the necessary libraries for the other three sensors. 

I've had a couple of evenings to hack away at this and I've now got sensible, if uncalibrated, data from both the accelerometer and magnetometor via Python. AdaFruit's Raspberry Pi WebIDE has been a joy to use for this sort of learning exercise - it's clean and simple (which I need right now) and its integration with Bitbucket means I can easily point people at the code I've managed to hack together so far:
This stuff just about works and I'm sure anyone who has any sort of Python skills will find a ton of newbie errors and bad practices in there but hey, they work and I will be cleaning them all up as I learn how to do all this properly. And hopefully I'll have the L3G4200D Gyro in there over the next couple of days. 

Tuesday 20 September 2011

Interesting Times

I’ve been thinking a bit about the fact that we’re living in a time of monumental change that is running rings around the established systems of the world.

First consider that the world we live in now is one where the average computing power, and digital storage available to individuals is increasing at a rate that is roughly equivalent to a 64x improvement in performance, capacity or cost-effectiveness over the lifetime of an average political leader ( 8 years ). Those in nominal control of things haven’t got the beginnings of a clue what that actually means, they are struggling to come to terms with the concept that stuff that was functionally impossible a handful of years ago is easily managed by a school-kid with a phone today. And the idea that such school kids might actually have experience with the complex multi-tasking needed to marshal armies is something that I suspect rarely bothers them but it probably should, after all hundreds of millions of hours are spent by the youth of today doing just that, only they call it online gaming.

Have a read of Ben Hammersley’s awesome speech last month to the IAAC. He puts forward some ideas there that are well worth reading at any point in time but it is truly worrying to think about the conceptual problem the rulers of the world have given the things that are happening right now.

So there are clear problems with “The Suits” trying to get their collective heads around security and governance in a world that changes faster than they can change their ties and pin stripes but so far they have mostly only been dealing with the effects of revolutions in communications capabilities and patterns. Now even those can be dramatic – the Arab Spring and the London Riots both showed how social networks and cell phones can pose existential threats to governments. It is interesting to note that these are proven existential threats, unlike the fake existential threats that Hammersley talks about that have prompted the ridiculous security theatre of Airports and the rest of the pointless moves towards a ubiquitous surveillance society.

Now think about the following two articles I read today about some interesting legal edge cases in the world of 3D printing.

3D Printed parts for Automatic Weapons.

ATM Skimmer Gang invests in 3D printer.

Once the ability to print your own guns, and any other illegal machinery of your choice, gets out there it will be out there and no amount of banning will put that genie back in the bottle.

Interesting Times doesn’t even begin to describe what I suspect is about to happen.

I think that despite my previous rant about being able to buy Rule-34 as an e-book that I really should go out and get a copy.

Friday 29 July 2011

What the austerity plan actual means to you and me.

So we now have some fairly solid information about what the next three to four years worth of budgets are going to look like.

It’s pretty fucking savage: To put it in easy to understand terms, take 60% of your current gross salary - that’s effectively what you will be earning in 2014 in todays terms.

Now I know that this is what is needed in order for this particular plan to succeed but I don’t think the average sod on the street understands precisely what that means for the amount of money they will have left if it does actually work.

Oh and that’s before we even begin to consider paying for the banks. This part is just about getting our current budget balanced.

There are actually some long overdue and good ideas for reform in the plan too, but I don’t think there will be anyone worthwhile left in the country by 2014 for them to matter.

 

The Numbers, for those who are interested.

Income Taxes: The plan outlines €1.5bn in tax increases from additional individual direct taxation ( ie you pay more tax, get lower tax credits or pay some new taxes ). Since there are about 2.2million individual tax payers in the country tat will average out at an extra €700 per annum. given the income distribution of those earners the _average_ PAYE tax payer will be paying around €1000 more in direct taxes next year. 

Spending Cuts: Then there will be €2.1 billion in spending cuts. A significant chunk of that will hit the less well off via social welfare cuts, and a nice chunk should be realised by trimming down the civil service numbers but at least €500m or so will come from reductions in general “benefits” – many things that are now free, or subsidized will have to be paid for adding up to another €250 or so per taxpayer. That’s money you have today that you wont have this time next year.

Where we have to get to: Now remember that we are €18bn or so out of balance and need to bring that down to about €15bn to hit the deficit target. This first step addresses €3.6bn of that. So by the start of 2014 every tax payer in the country will take home (on average) €4000 or so less than they do today on the same earnings. Those that earn around the average wages for the country will end up with about €5000 less net take home pay per annum.

Net Income per person: To put that in context someone on the average income in Ireland today (€35k) who will take home about €28k (after PAYE, USC, PRSI and the rest). Or in other words they will pay about €7k in tax. By 2014 the plan is that they will pay €12k in tax – an increase of about 71% in the individual direct tax burden.

Inflation: Meanwhile we have high double digit increases in Medical Insurance (20%+ so far), Electricity (Bord Gais 12%), Gas (Bord Gais again 22%), Petrol is up about 15% over the past 12 months and there is no sign that it will abate. These increases will continue and on average we will all pay about €1500 per annum more for these core necessities each year. Even if the now freeze those costs we are all going to be €1500 worse off per annum next year based on the increases that have already been confirmed.

Mortgages: A 20 year mortgage for the average house price as it was in 2008 ie €300k , calculated on a monthly repayment basis, at 4% costs €1812 per month. If the rate rises to 6% that increases to €2138 per month. The increase is €3920 per annum. The actual average outstanding mortgage is probably only €200k but even at that level your average punter will end up €2700 worse off.

Putting it all together: An average PAYE earner on €35k gross who has €28k to live on today will find that in three years they have the same buying power at that point in time that someone who earns €21.5k gross has today (about €19k net).

Thursday 16 June 2011

The Power, or something.

I was sitting on the bus this morning, giggling away to Gift Grub, and reading a pretty engaging book on my phone (Joe Abercrombie’s “The Blade Itself”, quite good I have to say) when I noticed that the bloke beside me clearly had just acquired a new phone. Glancing across I then noticed that he was wearing a pretty sharp suit, lovely shiny shoes and had an impressive briefcase tucked under his seat.

Good for him I was thinking, nice to see the mercantile classes roughing it with rest of us on the suburban bus run.

Then I noticed that he was reading something called “The Power!” or “The Power of You” . I’m not sure of the name, blue sky with clouds on the cover, tag line of “Believe it and it WILL happen!!” or some such. I was having trouble not breaking down in fits of hysterics –– grinding my teeth and screaming “SAVE ME FROM TEH STOOPIDZ!!!” silently inside my head..

I could see that he was opening it for the first time and I developed the impression that this bloke had just landed a new job, after some level of desperation given the current climate, this was his first week and the new boss had given him his “favourite book”. So here he was trying to read some of it to see if the success his new boss seems to be able to command could possibly rub off if he could just find the right set of instructions. He hadn’t been able to read it earlier because he was so busy making sure he was impeccably turned out, no doubt the boss also says things like you can judge the quality of a man by his clothes. At least that’s how it played out in my head.

Now he might have been a journalist struggling through this drivel so he could write a really compelling critique on the stupidity of this type of self help book and I’d love that to be true but I strongly suspect my first impression is closer to the mark.

I mean even if you were such a journalist you wouldn’t be caught dead reading something from the inner circle of literary hell on Bloomsday, of all days. Surely.

Anyway I really wish I’d found this particular presentation yesterday because if I had I would have pulled it up on my phone, tapped him on the shoulder and told him that he would learn far more watching this for 5 minutes than from reading that whole book full of drivel.

 

Sunday 29 May 2011

Growth, Default and Pay in Ireland

I’ve been following some rather disheartening debates about some fundamental aspects of our economy over the past few weeks. The lack of joined up thinking, and the complete unwillingness of most of the players in this game to honestly explain their long term objectives says a lot about how dishonest those who have any power in this country actually are.

The recent debates have covered both the high level macro problems of balancing growth, total employment and deficit reduction, as well as the (more) micro issues of the individual effects of taxation (in particular the new Universal Service charge), minimum wages and unemployment. There have been some interesting ideas and observations made but I’m astonished at the lack of joined up thinking.

We have, for example, the various business groups calling for things like reductions in minimum wages and the removal of agreements that enforce premium rates of pay for Sunday work. The main thrust of their arguments are that our minimum wage is too high (compared to the rest of Europe) and the premium agreement is an anachronism. This is not that different to the popular German view that Ireland shouldn’t be bailed out because we pay ourselves too much. And there is some merit in these points when taken in isolation.

Say we were to remove the minimum wage and remove the sunday premium. I don’t know how much either actually contribute to overall employment costs but since the existing premium under debate amounts to 30% and a market driven drop in real minimum wages is unlikely to drop total wage costs by more than 50% for those on the margin I think it’s reasonable to assume that the overall effect on employment costs can’t really be more than about 10-15%. Those are not trivial numbers but they aren’t huge either. Still let’s take them at face value. Our total Income tax take is about €8bn (and dropping) at the moment at an average effective tax rate of 10% or so indicating total income (of employees) coming in at around €80bn or so.

So if we were to drop the two rates and delivered the savings that the business groups would hope to see we might be able to remove about €8-12bn of their cost base (bonus!) but also a reduction in net individual income of the same amount from the economy (hmmh).

For the people we are talking about here (virtually all minimum wage, low end jobs) the effect cannot be that the affected employees will compensate for the reduction by saving less: they have no effective savings for the most part. They will either consume less, or consume less expensive replacements. For the non-export part of economy it means that there will have to be a contraction, GDP will be reduced. And there will be a multiplier effect, all sectors that serve the poorer sectors of the economy will contract by at least as much, and possibly some multiple of that. And there will be an effect on Government revenue – the reduction in pay will reduce USC and Income tax revenue directly by 10% or so and again the multiplier effect of the loss of that expenditure will impact VAT, Excise and Corporate tax revenue (from those low end product\service providers). It’s also worth noting that such downward personal income pressures will typically push up import substitution, hurting local businesses, since we are stuck in a fixed currency zone and comparative advantage pretty much dictates that most things can be manufactured and served more cost effectively from other countries.

The other core argument, and it’s a good and valid one, is that reducing business costs will increase employment, in particular in the vulnerable lower end of the market and increase overall competitiveness. These too have significant multiplier effects, assuming they result in lower product\service costs, and they should certainly drive export competitiveness, which by the way includes domestic tourist and entertainment revenue. This is why we are seeing the real push for this change coming from the larger business organisations and the catering\hospitality sector rather than the broader smaller firm groupings.

How big each effect will be is an unanswerable question, and the argument about merit hinges on the final equilibrium state you believe would be reached. Such changes are not a universal win.

However what is certain is that such changes, if implemented, will drive down personal income across the board. This is the desired outcome and we need to be clear what that means. The reality is that larger businesses and certain sectors desperately need us to deflate the local economy severely (by 20-30% at least) in order to regain global competitiveness. If we had a universally fair reduction in income coupled with a reduction in costs of living then this could seem like a “neutral” change in the longer term but one thing this cannot do is reduce our debt. And if we reduce income (either personal, or government) then our debts become more of a burden.

This is the core problem. We might be able to reduce government deficit, and reduce average wage costs and costs of living. These are things that are technically under our control but we cannot reduce the lump sum of our debt in this way. And if we make this extremely hard changes, and are successful, we will effectively inflate our debts by the same amount. That €100bn to €200bn hanging over our heads effectively becomes equivalent to €150 to €300bn. A 10 year repayment and austerity environment becomes a 15 year trial.

Add to this the reality that our current austerity regime has already started to produce contraction – we’ve got 0% growth at the moment and facing into 2-3% over the next 12 months. Add in the above contractions and deflationary pressures and our ability to  service our debts, let alone repay them will disappear completely.

We’re living proof that for countries reducing expenditure when you are in a recession makes the recession worse.

We’re owed some better explanations about that the overall resolution plan actually is. The current platitudes about austerity, deficit reductions and returning to the market do nothing to explain how we can get from here (effectively bankrupt) to a viable end state in 3, 5 or 10 years time. Detailed analysis of how we can successfully reduce employee wage costs and cost of living in a sustainable way while not turning a horrific but arguably manageable national debt into something that will kill the country would be a good start.

And that’s before we start to talk about things like the effect on society of having 40% of the under 25 male population who are available for work being unemployed. That’s a social catastrophe of monumental proportions that would be very hard to deal with even if the economy was healthy. 5 years of those rates and you are breeding a widespread criminal or revolutionary class of the dispossessed – countries have fallen on a lot less.

The last few weeks have generated some positive buzz for Ireland with our high profile visitors and some interesting oratory by our glorious leader but I’m sorry to say that the big picture looks a lot worse today than it did three weeks ago.