Flat of Angles [1]

So, things have been progressing. Without further ado:


That’s the first test run of the data logger. running at 5Hz. The eagle-eyed among you will notice there are no lean angle values. The reason for this is simple – the ADXL335 that I’m using will never ever measure a lean angle in a dynamic system with any accuracy. It’s measuring acceleration, so in a static system, you can calculate a lean angle with no problem. However once things are moving, and bouncing around, there’s going to be all sorts of accelerations in all sorts of planes, and so extrapolating a lean angle is next to impossible. Certainly for me anyway. I’m sure it can be done – just not by me. So, I’m now looking at a gyro, to go with the accelerometer, to give me lean angle. This may not be possible on the Uno that I’m using, due to the number of inputs I have to play with. But we’ll see.

Talking of the platform, if I was to do this again, I’d probably use a Mega, rather than an Uno for development. The extra serial pins would be useful to run both the GPS and a serial console for debugging. As it is, I’m flashing LEDs and dumping to the SD card when things go wrong, which is adequate for such a simple project. In fact, it’s quite good fun, and reminds me very much of my early days programming in 6502 assembler.

So, next step really, is to hook up the TPS properly (you can see it’s reading zero above – I still don’t have the voltage regulator built yet, so I daren’t plug it in) and work out a good way to mount all this to the bike. But, as a first test, I’m happy with that. It must be said, that building the map is ridiculously easy. Just load up the .csv file as a Google Fusion Table, and visualise it as a map. That’s all there is to it.

Postscript: So I hooked up the TPS:


Nothing exploded, and there’s no sign of the magic smoke. Obviously needs calibrating, and it’s a bit jittery so I may do some smoothing. But that’s that really. It all works. Just need to sort out the whether I can get the lean angle sensor working, and why Excel is stripping the hour off the timestamp in the graphs.

[1] Still can’t quite believe that there’s never going to be another Fall album.


Living by Numbers

I’ve been a bit out of sorts recently. Restless. Fidgety. Bad-tempered. At times, it’s got so bad that even tea hasn’t restored my karma, and I’ve taken to firing up the coffee machine. Yeah, it’s been bad. I put it down, mainly, to the weather really. The false start to Spring that we had a few weeks ago really got my hopes up that the seasons were changing, and then we had a couple of cold snaps which sent us right back into the depths of winter, and me back into my gloomy place.

I needed a project. So, I was sitting in my shed the other day, just looking around. On my workbench were the remnants of the fork valve conversion that I recently performed on the TRX. Sitting next to that graveyard of unwanted bits was a small pile of Raspberry Pi computers, with bits of wire hanging out of the box, leftover from when I was having a bit of a clearout a few weeks back. The first book on the end of my bookshelf, Data Science at the Command Line, grabbed my attention.

Motorbikes. Computers. Data… s’obvious, innit? Home-made datalogging. So, I did what any normal person would do. Put the kettle on, and had a cuppa. By the time I’d finished the cuppa, I realised that a Raspberry Pi was pretty unsuited to the job at hand, so I’d ordered an Arduino Uno, and a few bits of wire.

Spurred on by this, I decided to write down what I’d actually like to log, and came up with:

  • Speed
  • Throttle Position
  • Revs
  • Brakes

And that was about it really. I was starting to wonder if this was going to be a bit of a rubbish project, but, I was intrigued enough to want to put some thought into how I’d collect this data, and how to present it to the Arduino, and then, importantly, seeing that the Arduino has no real storage to speak of, how to actually log anything. This was rapidly turning into a multiple tea project.

So, first up, speed. Just take a feed from the speedo. Oh – of course, I’ve got a mechanical speedo drive. Hmmm, I could buy a GPS speedo, and see if I could hack into it to get a serial feed, or… hold on a moment… idea time! Get a GPS card for the Arduino, and use that to extrapolate speed. As a bonus, I could also map my journeys, and I love maps. Really. I spend hours looking at them. So, back to the internet, and a quick bit of googlage found a few Arduino GPS shields that also contained an SD card socket. So, two birds, one stone. Nice.

Next: Throttle position. I have a TPS on the TRX, so it should just be a case of feeding it into one of the analogue pins on the Arduino. I put this to one side for the time being, as it seemed pretty straightforward.

Revs: I thought about this for a while, and decided to put this one on hold – I need an oscilloscope to look at the feed to the rev counter to see what it’s doing, and how I’d feed that to the Arduino. I don’t have a scope, so I’ve put this idea on hold for now.

Brakes: This one took me by surprise really. I thought that a pressure transducer would be cheap and cheerful, the kind of thing that you pick up on eBay for 99p. So, I’d fit one, and again, take a feed to one of the analogue pins. This idea lasted for as long as it took me to find the price and availability. So, plan B was hatched. I’d just take a feed from the brake light circuit into one of the digital pins instead. So, I’d get an on/off indicator for the brakes – this is still useful, as at the track, I can tell how long I’m holding the brakes on for, and how soon I get on the throttle once I come off the brakes. But, a complication came up – the brake light circuit is obviously 12V, and the Arduino input is 5V. Also, vehicle electrical systems are notoriously noisy. I scratched my head, and put the kettle on, and again, fired up Google. And of course, someone has already beaten me to the whole bloody idea: http://www.instructables.com/id/Racing-Datalogger-With-an-Arduino/ – where I found this brilliantly simple circuit:


At about this time, I phoned Sol of 150bhp Katana fame, and we got chatting, and the idea of measuring lean angle was thrown into the mix. I was expecting an inclinometer to be expensive. But, I was surprised to find that an ADXL335 accelerometer can be had for under a fiver, and with a bit of trigonometry, lean angle in three axes can be calculated.

By this time, I had quite a pile of bits on my desk, and the Arduino IDE fired up on my PC. The GPS unit still hadn’t turned up, so I set about measuring lean angle, and throwing together the brake like opto-isolating circuit. I came up with this:


And, with no surprises whatsoever, it didn’t work. The lean angle was all over the place, and the brake sensor steadfastly refused to do anything. Considering its only function is to emit either a 1 or a 0, this is a pretty poor state of affairs.

I put the kettle on. The lean angle (the ADXL335 is the little square thing on the end of the long ribbon cable for those who are interested) was just me screwing up the maths. I really should have listened to my maths teacher in school, as really, it’s just A-level trigonometry – in the end, I just grabbed the code from http://bildr.org/2011/04/sensing-orientation-with-the-adxl335-arduino/ and hacked around with it a bit. Then again, my A levels were 32 years ago, so it’s not surprising I’ve forgotten things. The brake light thingie was incompetence on my part. I shoved 12V straight into the input, without going through the resistor first. Luckily the things cost something like 18p each, and come in packs of 10. Once I’d fixed this, it was all fired up again, the code reflashed to the arduino, and all was well with the world. Next step was just to transfer the prototype brake circuit to stripboard for mounting to the bike:


I still need to cut the board to size (excellent! Angle grinder action ahead…), but that’s ready to be wrapped in heatshrink, and fitted to the bike now. Down in the bottom right hand corner of that photo you can see the GPS shield, which has now turned up. A quick bit of poking with the lovely TinyGPS library has shown that it’s giving me location data, and as a bonus, there’s a function in that library to calculate speed already. So, that saves me a job. Writing data to the SD card has also been tested, and that works OK too.

And that’s really where we are right now. Need to finish the coding to write the GPS data to the SD card, to go with the lean angle and brake status the code currently logs. Then I need to shuffle out to the garage to work out how to grab a feed from the throttle position sensor. I may have to do something with the voltage on this one – if it’s between zero and five volts from closed to fully open, I’m good, as I can just stuff that straight into an analogue pin on the Arduino. May want to see about filtering it somehow to prevent spikes. I have no clue how to do this, so any ideas will be gratefully received.

Total cost, so far, is refreshingly not very much at all. The Arduino was old stock, and I got it for about a tenner. The most expensive thing was the GPS unit, at about £20. The accelerometer was under £5. Resistors, optocouplers, and stripboard also came to under a fiver.

Next instalment should, with any luck, contain some actual ride logging data. Need to crack on with that coding. This may take some time, as I’m not a good programmer at the best of times, but I’m thoroughly enjoying diving into the Arduino IDE and learning about GPS protocols. I really should get out more.

Firstly though, I’d best put the kettle on. I’m done with coffee for a while now.

Never Understand

Blimey. Conclusive proof that people actually read this… I’ve had a request from my good mate Champ, to go into a bit more detail about how forks work, and how the emulator valves will help to make things better. This is a bit of a first for me. I’ve never been asked to explain anything (other than some rather inappropriate behaviour in my youth) before now, particularly in writing. Oh, hold on. No. Scratch that. I did have to write a letter to my headmaster explaining the incident attempting to abseil out of the library window.

So, anyway, Here goes. Firstly, the basics. What is suspension? Well, in it’s most basic form, it’s a spring that suspends the chassis of the bike from the unsprung bits (basically, the wheels and brakes really, and the solid bits that hold them in place). Those springs allow bumps in the road to move the wheels up and down, without transferring that movement directly to the rider. A spring, by itself, isn’t much good though – any forces imparted to the spring will cause the system to start oscillating. If you’ve ever ridden a C90 with clapped out shocks you already know what this feels like. You hit a bump in the road, and by the time you get to your destination, the thing has just about stopped pogoing up and down like the front row of a UK Subs gig. So, we need damping. This is basically a way to lose some of that energy by dumping it into a viscous medium. Oil, usually. Although in the case of the aforementioned C90, I think it’s some secret concoction of hamster piss and bilgewater. But, the principle is sound. For basic suspension, we need a spring, and a damping mechanism.

A spring is a spring is a spring. As long as you get one the right length, and the right spring rate (basically, how far does it move for a given amount of force), it’ll do the job. Too high a spring rate, and the suspension will be too ‘stiff’ for want of a better word. The spring won’t be able to deflect enough to absorb the bumps, and they’ll be transferred to the chassis. Too low a spring rate, and the suspension will bottom out – the spring will use all of its travel too quickly, and the suspension will hit the end of its travel. So we want something in between. As for spring length, well, that’s self explanatory really. No point in having a three metre long spring in a 30cm fork tube.

Which brings us to damping. On the TRX, this is done by forcing oil through holes, to slow things down and absorb some of the spring movement. On the compression stroke, there is no adjustment – there are a pair of 7.5mm holes through which the oil must flow. And on the rebound stroke, there is some adjustment – there are four holes of different sizes. And, of course, we can change the thickness (or weight) of the fork oil, so we can move it more quickly through the same size hole. (Think of drinking a glass of water vs. a thick shake through a straw. For the same amount of effort, you can shift a lot more water, as it’s runnier). Now, the problem with the TRX is that compression damping – if you hit a large bump in the road, the hole can’t flow the oil quickly enough to allow the spring to compress, so the force is transferred straight to the rider. If you put thinner oil in, it means the rebound damping is then so weak, that when the forks are compressed, they subsequently extend too violently, which is kind of OK when you’re upright, but if you hit a bump in a corner, the rebound action will make the front end of the bike pop up quite quickly, leading to unpleasant handling, and the possibility of ending up in a ditch.

So, what we need then, is a way to independently adjust the compression and rebound damping, over a greater range than the stock forks provide. This is where the emulator valves come in. With these installed, you can open up the compression damping holes (or just drill more, as I did), and control the flow using the sprung restriction in the valve. On the rebound side, you control the flow purely using the thickness of the oil (you can also physically drill the rebound drain hole a bit bigger in the fork internals if you run out of adjustment, but hopefully I won’t need to do that).  So, what we now have is the ability to flow enough oil to cope with large bumps, the ability to control that flow of oil on the compression stroke, and a completely separate way to control the damping on the rebound stroke. Which is exactly what we wanted. To make changes to the compression damping, we need to fish the valves out of the forks, and give the spring tensioners a twiddle. To make changes to the rebound damping, we use a different weight oil. I’ve tried to sum that up in the following table – no idea how WordPress will justify this, but let’s give it a go:

Rebound Compression Action
High High Thinner oil
High Low Thinner oil, increase compression adjuster
High OK Thinner oil, increase compression adjuster
Low High Thicker oil, reduce compression adjuster
Low Low Thicker oil
Low OK Thicker oil, reduce compression adjuster
OK High Reduce compression adjuster
OK Low Increase compression adjuster
OK OK Cup of tea

Of course, it goes without saying, that pretty much any modern bike will have a better setup than the stock TRX850. Really, anything from the 90s onwards, with upside down forks, will have this range of adjustment built in with separate damping adjustment possible

And even more of course, Racetech have a far better description of all this, complete with some nice pictures: http://www.racetech.com/page/title/emulators-how%20they%20work – this description makes no mention of the rebound damping adjustment that needed to be removed in my case, but the principle is exactly the same.


Le Sacre du printemps

For pretty much as long as I’ve ridden the TRX, I’ve wanted to do something about the front suspension. The forks, somehow, contrive to be weedy, bouncy, clattery, harsh, underdamped and overdamped. All at the same time. Looking on the bright side, well, the spring rate is about right for my weight, and they do keep the front wheel pointing in the right direction, but that’s about all they really had going for them. I’m probably being a little unfair, as the roads that I ride on around here are notoriously bumpy, and even well suspended bikes are soon tied up in tankslapping knots. Just avoiding the rapidly approaching dykes can be enough to keep your hands full at times. So, I had a few days off work this week, the bike was up on stands for a bit of routine maintenance, it was the perfect time to do something about it. A lot of TRX850 owners take a fairly radical approach to this problem, by just throwing the stock setup away, and replacing it with a set of forks from a YZF750. I briefly considered this, but ruled it out on the grounds that I fancied having a crack at fitting some cartridge emulators. If they don’t work, I can always throw them away, and then fit a fancy front end from a proper bike.

So, stage one then, was to determine what to buy. Racetech have always been the standard for cartridge emulation, but there’s a long lead time, and they’re pretty expensive. Enter the YSS PD fork valve. £63 a pair, the right size, in stock, delivered. That’ll do nicely. A litre of Rock Oil suspension oil completes the shopping list. “But what about the new seals?” I hear you ask. Well, yes, that would have been prudent. But, I put new seals in there when I rebuilt the forks, and it’s perfectly feasible to fit emulators without disturbing the seals, so I left them as is.

A couple of days later, a nice parcel turned up, and the valves dropped out:


I pottered out to the shed to fit things. This would have been much easier if it wasn’t 8 degrees below freezing, but at least I have a heater in the shed. Fitting emulators consists of five steps really:

  1. Drain oil, remove springs, spacers, damping rods.
  2. Shorten internals to allow new valves to fit.
  3. Open up oil flow in damping rods.
  4. Remove old damping gubbins.
  5. Refit everything.

So, pretty straightforward then. At first glance it seems like there’s a lot of complicated things to do, but break it all down, and it’s easy enough.

Step one passed without drama. The forks were dropped out of the bike, the caps removed, and then the springs and spacers came out with the aid of the magnet on a long stick. I turned the forks upside down in a bucket, and let the oil drain out. While that was happening, the damper retaining bolts were unscrewed from the bottom of the fork legs, and the dampers fell out with a nice clonk. Everything was cleaned up, and the forks just left in the bucket to complete draining.

Step two: making sure everything fits. Well, first step I guess is to measure the thickness of the valves. Out with the calipers:


I make that about 14.5mm, give or take. It’s not that critical. Now, we can either remove that amount of material from the spring, the damper rod, or the spacer. If I had a lathe, I’d probably remove that from the top of the damper rod, as that would make step four a lot easier (more of which later). Under no circumstances would I attempt to shorten the spring. Which leads to the spacer. Transferring the dimension to the spacer is trivial:


As well as not having a lathe, I don’t have any engineers blue either, so I just used a Sharpie, so the line scribed by the caliper was more visible. A quick appointment with Mr. Hacksaw later, and the spacers were about 14.5mm shorter. Again, a lathe would have made this easier. I really should start saving up.

Step three. Where were we? Ah, yes, increasing the oil flow. As standard, the damper rods have a pretty restrictive flow, which I think is responsible for the horribly overdamped high-speed damping in stock form. So, we’re going to replace a pair of 6mm holes with six 8mm holes. I chose to go this way, rather than just opening up the existing holes, as this bit of metal supports the entire weight of the bike under heavy braking. And I know I’m famous for saying “what’s the worst that can happen?” but in this case, I don’t even want to think about that. So, let’s mark up the damper rod where the new holes are to go:


Again, no engineers blue, so the Sharpie was pressed into service. I tried to keep things as well spaced as possible, with the middle set of holes at 90 degrees to the others. A whack with the centre punch, and a bit of drilling, and we’re left with this:


Which looks a lot more meaningful. What’s important here isn’t so much the drilling, as the cleaning up and deburring afterwards. We really don’t want to leave any swarf lurking in there to rip out the seals and get stuck in the valves later, so I spent quite a bit of time filing off the burrs internally and externally, and flushing the things out with solvents and compressed air. I’m resigned to the fact that they won’t be 100% perfect, but they’re as good as I’m going to get them without some very specialist equipment.

Step four: removing the existing damping gubbins. This is the most involved aspect of the job. The first stage of this is easy enough. Pop out the circlip from the damping adjuster:


With that removed, just pop the adjuster out of the damper rod. The little spring and ball-bearing used for the detent mechanism will fly out, so be careful you’re not looking too closely. Of course, this will land in a dark corner of the shed, never to be seen again. Here be spiders. With that removed, you now need to block up the five holes left at the top of the damper rod:


As mentioned earlier, if I had a lathe, I’d simply have taken 14-15mm off the top of the damper rod, which would have removed the four small holes used by the damping adjuster detent. But I don’t, so I had to think of another way. It’s perfectly feasible to sleeve the inside of the rod, and I considered using the old adjusters to do this, but they would have needed lots of machining to remove the core of the casting, and I just don’t have access to that kind of machinery. So, I cleaned everything up as best I could, and broke out the MIG and angle grinder:


Now, it’s worth remembering that in the hands of the right person, an angle grinder can be a precision tool. Looking at the above, it’s safe to say that person isn’t me. Anyway, again, this isn’t brain surgery – it just needs to be clean, and oil tight. Again, give everything a good clean in solvent to get rid of any swarf left behind by the grinding. Also worth mentioning that I cleaned things up a bit more with a Dremel to get into all the nooks and crannies. Finally, (and this really should have been covered in step two), I chopped the adjuster rods off near the top:


This is purely to stop them clouting the new valves when everything is buttoned back together. Which brings us on to:

Step five: putting everything back. Again, give everything a good clean, then put the damper spring and little red plastic seal back on the damper rod. Drop it into the fork, and refit the retaining bolt. Prepare to say goodbye to the little valves:


Drop the valves on top of the damper rods, with the long bit of the adjuster on top. Refill with oil (I used 10 weight), and the book figure is a 130mm air gap, compessed, with no spring. Now, when pumping the forks to expel any air from the damper mechanism, chances are that you’ll push the valves up out of their seat, and they’ll land again at a funky angle. This isn’t what we want at all, so spend some time with the spring and dampers fitted, bouncing things up and down, checking that the caps will fit without undue pressure, to ensure that the valves are seated correctly.

And that’s it really. Any difference? No idea at the mo. There’s eight centimetres of snow outside, and no way I’m going for a test ride. So much for the rites of Spring.