Any Arduino Gyro Projects

Any old or new electronic projects on the go
Post Reply
Pchristy
Posts: 413
Joined: 16 Feb 2018, 13:57
Location: South Devon, UK

Re: Any Arduino Gyro Projects

Post by Pchristy »

Hi Martin,

Yes, you were right! I'd got the wires swapped! D'oh! :oops:

I think what confused me was the Futaba plug on the JR colour coded lead and the JR plug on the Futaba colour coded lead! (That's my excuse, and I'm sticking to it! :P )

Just to make sure, I re-uploaded the sketch and it uploaded and verified fine. It actually uploads quite quickly here. I didn't time it, but around 10 secs? My workshop computer is fairly old - by the standard of these things - an AMD quad-core Bulldozer, running pure 64-bit Slackware Linux.

Whilst I had the gyro out of the model, I moved the receiver slightly to make more room for it - the two are adjacent:

ImageGyro_install by Peter Christy, on Flickr

A bit of a tight squeeze, but its in there!

All looks to be working as expected on the bench. I'm hoping to get out this evening and give it a try, though I may not have a camera person with me.

Watch this space....

--
Pete
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: Any Arduino Gyro Projects

Post by Martin »

That's good news! :D Keeping my fingers crossed for this evening's test!

If you ever need to take the gyro out again, you could edit the config.h file to use:

GYRO_AXIS AXIS_Y
instead of
GYRO_AXIS AXIS_Z

and you may also have to edit

DIRECTION NORMAL
to
DIRECTION REVERSE

... and then you could mount the gyro with the wires emerging from the top - which would free up a bit more room for your receiver.

I investigated why my USBasp upload was so slow, and swapping to a different USBasp that has an ATmega48 instead of an ATmega8 reduced the total upload/verify time from over 36 seconds to 2.15 seconds! So I investigated updating my USBasp firmware, and after that the very slow ATmega8 unit takes less than three seconds!

I watched this Youtube video showing how to do it:



The actual command I used was slightly different as I didn't want to alter my paths. In Windows cmd line, I cd-ed to the directory:

C:\Program Files (x86)\Arduino\hardware\tools\avr\bin

...and then used this command (all on one line):

avrdude -C "C:\Program Files (x86)\Arduino\hardware\tools\avr\etc\avrdude.conf" -c usbasp -p m8 -u -U flash:w:C:\Users\Desktop\Desktop\usbasp\usbasp.2011-05-28\bin\firmware\usbasp.atmega8.2011-05-28.hex:i

obviously if you unzipped the .hex file downloaded from https://fischl.de/usbasp/ in a different place, you'd change the :C:\Users\Desktop....28.hex:i part to the path where you unzipped it.
Pchristy
Posts: 413
Joined: 16 Feb 2018, 13:57
Location: South Devon, UK

Re: Any Arduino Gyro Projects

Post by Pchristy »

Just as well I don't need to do that! Neither of mine has any jumpers - or even the lands for them - at all!

They both appear to be the same, and have a 5/3.3v switch, but that's only accessible on one! The other is in a sealed translucent case. I can just make out enough to see its the same board, but with an inaccessible switch!

Tonight's test is 50/50 at the moment, though I may risk a quick hop in the garden. There's not much "escape" room there, though!

--
Pete
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: Any Arduino Gyro Projects

Post by Martin »

One of mine had no jumpers, but there were two unmarked plated through holes underneath the main chip. Shorting those together with a bit of wire put the USBasp into 'firmware update' mode. Anyway, you don't need to do that because your USBasps are already working reasonably fast.

If I were you, Pete, I'd wait until I could get somewhere a bit more open - there's no rush. No point risking the heli in a restricted space - especially as, providing the initial tests go okay, the next tests will involve lazy eights or pirouettes or similar - to test the gyro and heli more thoroughly.
Pchristy
Posts: 413
Joined: 16 Feb 2018, 13:57
Location: South Devon, UK

Re: Any Arduino Gyro Projects

Post by Pchristy »

Well I've given it a quick hop in the back garden, being ultra cautious again. I set the gains initially to 50% in both directions. Normal mode behaved - er - normally, though without flying it around, I can't confirm there are no problems. It seems OK in the hover, though.

HH mode is another matter! It seems to have a mind of its own! Although everything works correctly on the ground, as soon as the model gets anywhere near lift-off, it goes unstable - just like it did originally, but somewhat slower! I reduced the gain down to 15% and tried again. At first it seemed OK, but as soon as either I applied any correction or a gust caught it, it gave a quick wag and tried to pirouette again.

In short, it seems to go unstable when disturbed for whatever reason. I'm at a loss to explain it. Something to do with the accelerometers, perhaps?

What I really need is one of the hovering aids that were marketed donkey's years ago! It was like a turntable that you could strap your heli to! It could freely rotate without any movement in the other axis. I'll ask around and see if any of the old timers have one in the loft!Its the only way we are going to diagnose this safely!

Sorry its not better news, but I'm sure there is a solution somewhere!

--
Pete
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: Any Arduino Gyro Projects

Post by Martin »

Thanks for trying it Pete. Although the MPU6050 contains three gyros (on the three axes) and also three accelerometers (and a temperature sensor!), my sketch is only currently reading the one, selected, gyro - so it's not an accelerometer effect.

I suspect that in heading hold mode, I need to apply the normal "rate" correction, PLUS a correction based on how far the current heading is away from the target heading - at the moment it's only doing the latter of those two terms in heading hold mode.

I think I need to do something more like a PID controller: if you're familiar with those, you'll know that the three letters stand for the three terms that are used to provide the feedback:

Proportional - the instantaneous error.
Integral - the instantaneous error integrated over time - so it corrects for longer-term offsets.
Derivative - the rate of change of the error signal.

If you're trying to drive your car to keep alongside a motorcycle, the output of the PID controller would be how far you're pressing down the accelerator, and the input, so-called "error", would be how far you're currently behind the motorcycle. The I (integral) term accounts for the fact that when you are actually keeping station alongside the bike (zero error) you still need to press the accelerator a certain amount, or you'll drop back behind the bike. The D (derivative) term allows for the situation where you're still behind the bike but rapidly catching it up - you have to ease off the accelerator before the error reaches zero or you'll overshoot.

I have some spare heli tail rotors, tail gearboxes and tail booms in a box somewhere. I'll lash up some kind of test stand with a vertical shaft around which the contraption can rotate, and the tail parts of a heli with an electric motor and battery to drive it - it will be like the "model heli on a turntable" thing you suggest, except that it won't have a main rotor.

It will likely take me a few days to get that built, and then do the development tests. I might test it out with a commercial heli gyro first to see the sort of performance I'm aiming for, and then I can hopefully tune my Arduino sketch to perform the same.

So please don't try to use heading hold mode until I've made and tested a "version 3". It's up to you if you want to do any other tests in the meantime using only the "rate" (normal) mode.
Pchristy
Posts: 413
Joined: 16 Feb 2018, 13:57
Location: South Devon, UK

Re: Any Arduino Gyro Projects

Post by Pchristy »

Cheers, Martin! Its definitely a stability issue of some kind. I seem to remember being taught "Nyquist's Stability Theorem" a long time ago, but don't ask me to explain it now!

Our standard servos have a kind of velocity feedback, which reduces the drive as the error drops below (say) 10%. Perhaps the gyro needs something similar. On a servo, without the "velocity" feedback, it will continually oscillate around neutral. Some advanced servos - before they started using speed controller technology - were deliberately left slightly unstable, as the mass and drag of the control surfaces provided a degree of damping.

Basically, I think the heading hold is working, but needs to be damped! Whether this is with velocity feedback - your derivative feedback - or just plain damping, I don't know, but its currently unstable.

In the meantime, I'll do as you suggest and cautiously expand the "normal" test regime. I'll keep you informed how I get on.

--
Pete
Pchristy
Posts: 413
Joined: 16 Feb 2018, 13:57
Location: South Devon, UK

Re: Any Arduino Gyro Projects

Post by Pchristy »

Took the Voyager-E out again today - somewhat lees windy - and gave the "normal" setting a good try out. No aerobatics, as the Voyager isn't really powerful enough for that, but lots of lazy 8s.

"Wagging" set in at about 80% gain, with 75% showing a reasonably well damped response to sudden inputs. It took a little more than the perfect 1.5 oscillations before it settled, but bearing in mind I'm only using a slow servo, that's not bad!

I've actually got a faster servo that's a "plug-in replacement" for the one in there. I took it out of another model because it seemed to have gone slow in one direction, but it behaves perfectly on the bench. Time to give it another go, I think!

Not sure when I'll be able to do the upgrade and test fly again, but normal mode seems fine, so far.

To be continued...

--
Pete
Martin
Posts: 744
Joined: 16 Feb 2018, 14:11
Location: Warwickshire

Re: Any Arduino Gyro Projects

Post by Martin »

Thanks Pete. Sounds encouraging. Maybe the available gain range in normal (rate) mode is a little too low if you're able to use 75% gain with a slow servo. Perhaps I should double the available range for version 3?

I've been on quite a journey, so far.

I inspected all my spare and crashed heli bits and pieces and found an old Trex 450 SE (with a flybar) that had suffered the usual crash damage - bent boom, flybar, mainshaft, feathering spindle, broken blades, stripped main gear, but otherwise looked intact. It must be at least five years since I crashed it and put it to one side. I don't remember why it crashed, but it was probably pilot error. :lol: I found I had all the spares necessary to fix it (except for the tail boom), so spent yesterday fixing it up (I made a mandrel and straightened the boom which was only gently bent - not cracked or creased).

So today I was going to test fly it, and then make up a turntable stand for it to sit on (with blades removed) for gyro testing.

But it last flew on an old JR PCM10X transmitter, with a Spektrum module fitted, so I thought I'd transfer the settings over to one of my current transmitters. I got the 10X down from the loft - the battery died long ago, and it had one of those special (expensive) battery-holder come charger adapter things instead of a regular battery - I'd just removed the the old cells to prevent corrosion, before putting it away. I got the battery case apart, figured out the connections, and powered the transmitter from a bench power supply.

The "DSC" output on the 10X is weird - it's not quite a trainer port as it can't be used as a trainer master - only a slave - and is really designed for transferring model memories to and from a PC or another transmitter, or setting up a model on the bench without transmitting any RF, via a special interface to the servos. It does give out a PPM signal, but it's capacitively coupled and at too low a level to work with my PPM tester. So I built an OpAmp amplifier (LM358) to boost up the signal to the point where my PPM tester could read the signal.

Now I've jotted down all the readings and am about to set up my Taranis to duplicate them - then I can test fly the heli!

I found various main shafts, main shaft bearings, frames, and main gears in my box of bits which I think will serve as a good basis for making a turntable. I'm intending to design and 3D-print a suitable 'tray' that fastens to the heli skids and mounts to the main bearings - I can then clamp the main shaft in a workmate table, and I'll have a free-spinning heli stand for tests.

That's the plan, anyhow. :?

While I've been tinkering with helis, I've been thinking about the software mods. I plan to base the heading hold feedback, not on the current difference between the actual heading and the demanded heading, but rather on the difference between the demanded heading and the predicted heading a third of a second from now - and that predicted heading is based on the current instantaneous heading and the current rotation rate. I think that should damp the response. The "third of a second" figure comes from the fact that even slow "cooking" servos, like a Futaba 148, are supposed to give a sixty degree in 0.28s response time - but the figure will be editable in config.h if someone wants to optimize it for a modern fast digital servo.

I also plan to add an extra configuration option which will be the demanded pirouette rate, with full rudder input deflection, in heading hold mode. I'm thinking the default for this should be about 720 degrees per second for rapid "540 style" stall turns, but some people might want faster. You can always go slower, of course, just by limiting the end points of your transmitter's rudder channel.

I'm going flying the next couple of days too, so it will likely be at least Thursday before I have the new program tested.
Pchristy
Posts: 413
Joined: 16 Feb 2018, 13:57
Location: South Devon, UK

Re: Any Arduino Gyro Projects

Post by Pchristy »

Cheers, Martin! Sounds like you have a good plan for testing!

I'm not sure about modifying the available gain just yet. High-speed "digital" servos will run at a higher gain without wagging. 75% on a JR591 (probably the equivalent of your Futaba 148s) doesn't seem unreasonable to me, especially given that this is a small (and very old!) electric heli.

At some point we may need to recruit a serious 3D pilot to test, and that's probably the time to look at tweaking the available gain. I can think of a couple who would help.

Anyway, keep up the good work! ;)

--
Pete
Post Reply