Has anyone used the MPU-5060 3-axis Gyro? I need help setting up coding for it...

rocketdoc

New Member
I have 2 of these for a project for my thesis. I am NOT a great programmer, and I want to learn more, I am just LOST with this idea, but, I want to understand it completely. I can provide a data sheet available for free online here:

http://www.bt2000.co.uk/datasheets/invensense/mpu6050.pdf

I want to design a small but complete gyro stabilizing setup for large scale model rocket, that use servo's for controlling the gymballing of the rocket nozzle. I want to use this for my Thesis, and I have about 6 months to complete it. I will also use this in a test model, for the means of using not only fins but pivoting the engine/nozzle for guidance and launch path programming.

I would certainly appreciate any help I can get... and would give the due credit for the help.

Thank you all!!!

Kim
 

SAborn

Senior Member
Do you intend to use I2C or SPI interface with the gyros, if you use I2C then the addresses would be %11010000 and %11010010, from a quick look at the data sheet the data returned would be 2 bytes for each axis X,Y,Z.

My only thought is the picaxe will be far too sloooooow for this project and you will require a MUCH faster chip to react to rocket changes quickly enough.
 

rocketdoc

New Member
I would be using a faster PICAXE speed...16Ghz

Thank you. I would obviously use a higher speed chip. If I were to use a high speed chip for just the guidance, I could possibly use another to monitor other things, without interfering with the correction couldn't I? I could not even use a Arduino if this is the case.
What would you suggest, as it appears that you are highly knowledgeable on this subject.

Also, Even if it is too slow, it would still work for my thesis, as a proof of concept, and for use as a discovery... I would consider using a full 8 or 32 bit processor if need be...

Any suggestions is really appreciated, as I said...

Kim
 

SAborn

Senior Member
I would be using a faster PICAXE speed...16Ghz
Thats dreaming!!, the picaxe is down in the Mhz range and far from the Ghz range.

About the best you could get from a picaxe is 64 mhz (20x2) and i would expect that to also be way too slow, there has been a few threads on building a Gyrocopter using a picaxe in the past and the general thoughts is the picaxe is far to slow, as far as i know it has never been done.

as it appears that you are highly knowledgeable on this subject
Dont be fooled, i am not highly knowledable in this, im just a fool who answered part of your question and have used many I2C devices, There is much smarter people here than me.
 

rocketdoc

New Member
I did mean 16 Mhz... sorry.... But thanks for the info. I will see how this works out.. I will try to design an interface.... at worst case, I could have a working and functional demonstration piece to use for the thesis. That is what I am looking for... Now to figure out the rest of the software and make it track at least, even if it is slow....Thanks for you knowledge, I am SURE to be the least informed, but, I am learning fast!!! AND having a lot of fun designing these things too!!!
 

SteveT

Senior Member
Hi there,
For starters, I'm no expert on what you propose, just throwing in a few thoughts here.

Servo's as well as your processor, your servo's are going to have to be pretty fast too. Fast enough? Don't know.

What sort of size would your rocket be? It could be that the required servo arm throw would be tiny, would a miniature stepper motor be faster? Don't know enough about steppers.

If servo is chosen, then a fast digital one would have to be used. Fast digital = power = larger current demand = bigger battery = more weight. Might not be so important if your mock up is 12 feet tall. But if it's 12 inches?

In my opinion, for what it's worth, a picaxe is more than fast enough for a proof of concept mock up. As to the real thing ??
 

rocketdoc

New Member
Both of the Servo's and the processor are fairly fast. The servo's are "MICRO" in Design, and have a .075 micro-second response time, and the processor, as I have figured out, WOULD have the speed needed to control the Rocket. Which in this case is almost 7 feet in length, and has a LONG burning Solid Rocket Motor...(17. 7 second burn time.)... Leading to a hopeful altitude of over 25,000 feet as an apogee. The servos can either move fin vanes, and/or a gymbal on the nozzle of the motor. The total weight if the servo's and electronics combined is only 22 ounces. Everything was designed using balsa, and basswood, minimal frame usage for mounting, and strong thin fiberglass epoxy shells. I have been working on this for quite some time already, and just need some help with coding the program so that the controls so that it will respond to the axis changes as they occur. I am almost certain it can be done, and with a substantial weight savings, along with a decent controlled ascent. Even if dithering occurs, it should be negligible, due to the system being set to its zero points using pre-tested parameters, during static tests. It should be able to keep it within 0.05 to 0.01 degrees of zero deviation,(Forward thrust), calculated by the CG(Center of Gravity), and CP(Center of Pressure) of the rocket itself. Those settings, mathematically calculated before flight anyway, should be easy to maintain by the guidance system, and included in the coding, so it does not over compensate during actual flight.

I always say.... "Nothing Ventured, NOTHING gained..."
I think it is well worth the experiment, and I feel it should be successful.

I am just NOT a good coding man for the software of it...

This rocket will have 7 different micro-controllers, [performing various functions], and all should STILL be able to be monitored by a central controller for safety. and accuracy.

ANYONE willing to help make this work, will get all the recognition they deserve, including inclusion in the thesis as well.

ANYONE INTERESTED HELPING IN CODING THE GUIDANCE SOFTWARE??? PLEASE??????

Thanks again for all of your responses... Oh, I may add that the servo's will be within 2 inches of the nozzle and protected from heat, so their linkages should be VERY short and direct, with no play at all.

Thank You Everyone.. please continue. I enjoy learning about these things... maybe someday, I could help someone else, as needed....

Kim
 

g6ejd

Senior Member
Observations:
Of all the model aircraft and helicopters I've seen, they have all used Arduino as their basis. Nearly (if not all) products on the market such as Arducopter, Arduflyer use Arduino as their name suggests. You are going to need to work in 16-bits as all sensors use the full 16-bits for their output.

Have you worked out your control surface loads? I expect a 'micro' size servo is barely adequate, but it depends on the surface size, weight, hinge types, etc.

If you are intending a controlled surface and you are expecting quite fast control surface variations, then your servo choice should be digital for both speed and torque.

You will have 9-axis to process, x, y and z of direction, acceleration and motion. What is your experience/ability of working with this type of data processing? Are you able to work out the closed-loop transfer functions, which you can then translate in to the needed code? So, that's taking the inputs and outputs of your intended control system and their associated differential equations and then deciding if any of these can be approximated to a linear solution with constant coefficients to make life easy in programming with a limited CPU capability, the linear function of which can usually be obtained by taking a Laplace transform.

You should IMO, set out your design, set out the parameters your going to control, estimate (or calculate) your control-loop needs - write your requirement, then from there the design can start to evolve. If this is a PhD Thesis(?) then you should really be a lot further forward in your thinking than you are projecting so-far; sorry, but that's how I read the thread. there are some clever folks on here, but it's difficult to proceed when they don't really know too much about your intended design and at what academic level you are at.

Please help us by giving a bit more information about you and your project.

The compass modules I've used with corresponding acceleration data, when applied to a control surface, have all needed to be updated every 20mS in my case, which is quite quick to do your calculations, so that's get the data, parse those through your transfer function, then update your control surface and then get back to check the next attitude and see if correction is required, so that's your control-loop needs in code. I doubt a PICAXE can do that fast enough, or you will need a lot of experience of working in 8-bit from 16-bit sensors, if for example you find that only the LSB (bits) are being updated when the loop is stable, I'm thinking here of just reading the MSB (byte) of the sensors, and using that to pass through your control loop, but then that ends up with quite course control - back to you defining your design needs.

What academic assistance do you have access to?
 

SteveT

Senior Member
It's all just gone way over my head now :)

Still sounds like a brilliant project that I, and I'm sure several others, would like to follow with interest.

BUT.

Playing devils advocate for a moment, perhaps this is one project that should NOT be available for all to see.
The magic words "guidance system" has probably already caught the attention of someone at GCHQ. Or am I being paranoid?

Don't get me wrong, I'm not saying don't help the OP but maybe to help behind closed doors??
 

Jeremy Harris

Senior Member
Playing devils advocate for a moment, perhaps this is one project that should NOT be available for all to see.
The magic words "guidance system" has probably already caught the attention of someone at GCHQ. Or am I being paranoid?

Don't get me wrong, I'm not saying don't help the OP but maybe to help behind closed doors??
I wouldn't worry too much, as this particular genie has been out of the bottle for a long time now. The DIY cruise missile site (http://www.interestingprojects.com/cruisemissile/) stayed up with enough technical detail available for someone to build one easily enough. I recall it being evaluated (officially) some years ago with the general conclusion that it would almost certainly do as Bruce Simpson said it would. After all, all he did was take WWII technology (a pulse jet powered aircraft) and couple it to the same sort of cheap GPS guidance systems being used by thousands of amateur UAV builders around the world (you can even buy an off-the-shelf complete UAV control system now).
 

g6ejd

Senior Member
The Arducopter and Arduflyer avionic boards have been around for ages and are truly amazing in their abilities - if anyone wanted to use one for subversive reasons they could easily do so. Adding one to a rocket would be trivial and the results certain, but designing one from scratch is a real skill. The problem with these projects is that the level of knowledge required is so high as to make it prohibitively difficult for most people without a wide range of academic knowledge to be able to bring it all together. Those who have studied electronic engineering should be OK as they would have covered control theory for amplifiers and the principles for a mechanical system are the same, then one needs to be able to code to translate the transfer functions into software and so-on...

there is an element of reality that needs to be applied to such projects and it needs real dedication.
 

Memran

Member
I've got one, and have had success getting it to work with my Arduinos (because there are a few libraries available which make it easy), but so far no joy with Picaxe. I guess I've got to try to convert an Arduino library to Picaxe basic...
 

Kimtex

New Member
LOL!!!! You folks are GREAT!!! Love the responses, and the ideas that FLY!!! GREAT MINDS!!!! My use is fully peaceful, and will be used for school and my hobby at this point in time. I have access to the Redstone Arsenal, and data for stability in design, plus, I have a LOT of programs available for designers to refer to.

I would like to try and help ANY of you all who may want to give me a helping hand. First, Coding from one language to another, I have done say, from "C" to modern Visual Basic. It was fairly easy, with a few challenges, but, we got he job done. I have a tremendous amount of investment in the Picaxe Chips and systems, and interfaces. so I would really like to see if we can make this thing "FLY" Pardon the pun!! LOL!!!

I have a flight computer setup, that will go along with this, where sensors and other control capabilities can be added, including FLASH memory cards, and camera's... Even staging events are covered in this, so that timing issues, and best available altitudes can be reached, monitored, and data even transmit back to the ground if need be. Otherwise, it is stored in a flash type card such as a SD card, or SD Mini Card. OR BOTH!! I have to date, used 4 controller chips, to control and monitor flight data, from burn time, to altitude monitoring, and want to advance this so that maybe even controlled ascent and path to recovery and apogee... ie.. Roll and pitch for flight tracking...

Can you direct me to these Arduinp programs, or upload them, and maybe together we can figure out a conversion for them, to GLADLY be shared for all of the Picaxe folks here too...
By the way, I live near the NASA Space Center, and have some contacts that may be able to help some too....

LETS ROLL!!

Kim
 

g6ejd

Senior Member
Well the original thread was started, asked for help, then never to be heard of again, so don't hold your breadth waiting... :)
 

rocketdoc

New Member
Ok, Follks!!! Sorry, I have been trying to work on conversions, and I got called to the hospital because of a friend being in there, and I just got to the point today the I could post something...

I would REALLY appreciate the help, and will share anything I come up with.

Thanks All...

Kim
 

Memran

Member
I gave up being lazy, waiting for other people to figure this out for me, so I got my hand dirty :)

The main issue I was having was the address. The datasheet says the address is $68 (01101000). The problem with this is that it is 7-bit (remember that the right bit is read/write) so we have to shift left and get $D0 (11010000). Now we can talk to the MPU.

Here is my sample code which can read the raw data from the device. You will still need to refer to the datasheet for specifics, but this should get you started. Bare in mind that the word values range from 0 to 65535, but they should be signed (-32768 to 32767). The signed values make more sense when viewing, so be sure to convert when outputting to terminal or whatever.

Code:
#picaxe 08m2
#com 3
#no_data

Symbol xa = w0
Symbol xa.lsb = b0
Symbol xa.msb = b1

Symbol ya = w1
Symbol ya.lsb = b2
Symbol ya.msb = b3

Symbol za = w2
Symbol za.lsb = b4
Symbol za.msb = b5

Symbol xg = w3
Symbol xg.lsb = b6
Symbol xg.msb = b7

Symbol yg = w4
Symbol yg.lsb = b8
Symbol yg.msb = b9

Symbol zg = w5
Symbol zg.lsb = b10
Symbol zg.msb = b11

Symbol temp = w6
Symbol temp.lsb = b12
Symbol temp.msb = b13

'Datasheet says address is $68 (01101000) however this is 7 bit
'format, so we must shift left to $D0 (11010000)
'hi2csetup i2cmaster, $68, i2cfast, i2cbyte
hi2csetup i2cmaster, $D0, i2cfast, i2cbyte
pause 1000

init:
	'set clock source
	'register 107 0x6B
	'reset / sleep / cycle / NA / temperature disable / [2,1,0] clock source
	'hi2cout $6B, (%00000000)'internal 8MHz
	hi2cout $6B, (%00000001)'clk source from X gyro
	'hi2cout $6B, (%00000010)'clk source from Y gyro
	'hi2cout $6B, (%00000011)'clk source from Z gyro
	'hi2cout $6B, (%00000100)'external 32.768kHz
	'hi2cout $6B, (%00000101)'external 19.2MHz
	pause 100
	
	'gyro full scale
	'register 27 0x1B
	'x-test / y-test / z-test / [5,4] full scale / NA / NA / NA
	hi2cout $1B, (%00000000)'+-250 degrees/s
	'hi2cout $1B, (%00001000)'+-500 degrees/s
	'hi2cout $1B, (%00010000)'+-1000 degrees/s
	'hi2cout $1B, (%00011000)'+-2000 degrees/s
	pause 100
	
	'accel full scale
	'register 28 0x1C
	'x-test / y-test / z-test / [5,4] full scale / NA / NA / NA
	hi2cout $1B, (%00000000)'+-2g
	'hi2cout $1B, (%00001000)'+-4g
	'hi2cout $1B, (%00010000)'+-8g
	'hi2cout $1B, (%00011000)'+-16g
	pause 100
	
main:
	'0x3B is accel X first register
	hi2cin $3B, (xa.msb, xa.lsb, ya.msb, ya.lsb, za.msb, za.lsb) 
	'0x41 is temperature first
	hi2cin $41, (temp.msb, temp.lsb)
	'0x3B is gyro X first register
	hi2cin $43, (xg.msb, xg.lsb, yg.msb, yg.lsb, zg.msb, zg.lsb)
	pause 100
	debug
	goto main
 

rocketdoc

New Member
Ok, now, if everything works correctly, all that is needed is to compare the ZERO rate of roll. and angle, at no motion, then use that info to move a servo the OPPOSITE direction, an specific amount, and adjust the rate according to the rate of pitch,/yaw... So monitoring the axis registers should be the only thing that compares to the set position of the gyro.
NOW.... Knowing this, it should be a simple matter to compare the +/- of the direction of the pitch/ yaw, & roll and adjust the "OPPOSITE" servo action to correct it.

I apologize for the length from the last post. I have had to have several surgeries since then, and an now healing at home, instead of the hospital. Thanks for all of your assistance so far. The registers we need only be concerned about are those 3 axis. Pitch/roll/yaw. all could be controlled with 2 servo's using a collective mixer between them mechanically, Sort of a elevator/aileron or elevon type design

Knowing this it should be fairly straight forward...

I will begin coding today.
 

PADJ

Member
I have 2 of these for a project for my thesis. I am NOT a great programmer, and I want to learn more, I am just LOST with this idea, but, I want to understand it completely.
Knowing this it should be fairly straight forward...
I still don't see what type of 'thesis' this is for? Have you done any Control system courses? Are you familiar with feedback and PIDs?
 

g6ejd

Senior Member
Yes this is my view too and I made the same point early on as knowledge of PID is going to be a fundamental requirement for producing code that works. P programming is the easy part, I needs some consideration as does D. We need to know to help in the right way and at the correct level of knowledge.

Recommend the OP reads about control theory and PID then this will all start to come together.

I have not studied the MPU-5060 data sheet but I suspect the x, y and z components cannot be treated as simple independent values, they don't behave like that in the modules I've used, as the resultant output is a vector determined by three values. To do what's been mentioned requires the addition of an acceleration sensor which the device might contain, if so, then that output needs to be combined to develop a control surface correction algorithm.
 

boriz

Senior Member
The difference between too little control deflection and too much is going to depend on lot's of factors, but is likely to be very small. A PID is essential, and it has to be a very good PID, like a Kalman filter (used by NASA I believe).

The algorithm loop time is going to be far too slow for a real rocket. And a real rocket will contribute lots of vibration and acceleration forces to complicate matters. And whilst a demonstrator can use a much smaller/faster algorithm, and look good, it's not going to be scalable to real rocket. So what use will it be?

If you just want something that looks good, Picaxe should have no problem.
 

g6ejd

Senior Member
PLEASE read the data sheet, and see for yourself. I believe it contains all of the components to do the job. I have a degree in applied pgysics, and working on an astro physics doctrine.

http://www.bt2000.co.uk/datasheets/invensense/mpu6050.pdf

Thank you!

Kim
OK the chip has the required capability, but do you understand control theory that's all we are trying to determine. If not you should start reading as it will make your coding much easier to do.

Which University did you study at? I am familar with most UK (Applied Physics) Courses and they all cover Control Theory.
 
Last edited:

PADJ

Member
and working on an astro physics doctrine.
I don't think I know what this is? Can you give more info to help us understand your academic level better?

And can you give some more info on your servos? They seem very fast to me.

Both of the Servo's and the processor are fairly fast. The servo's are "MICRO" in Design, and have a .075 micro-second response time,
Since I have little experience of rocketry I am curious what the velocity and altitude are at motor cut off/burn out.
 

g6ejd

Senior Member
They have to be 0.075 Secs or 75mS servos, I just checked a local model shop and the fastest currently/widely available are 60mS
 

rocketdoc

New Member
Well, this is for basically proving that the type of system is capable of doing the job as a guidance system. NOT for controlling model rockets... This is a sample of how it COULD, or should WORK, that is ALL I am looking for. I think everything is becoming too technical, and YES, a DOCTORATE IN PHYSICS is what it is. I am a former contract employee of the Redstone Arsenal & Missile Range. So I am in COMPLETE knowledge of how systems should work. Being a TECH, I never worked on guidance systems, per Se.... I installed telemetry, and other things, up to and including sequence devices, and escape systems.
I DO understand the fundamental of the guidance, and control portions, and have helped with them, and know about feedback, and sensor monitoring and such.

Pardon me I am not trying to sound ungrateful, or snobbish, just frustrated because this should be a SIMPLE matter to make a demonstrator. I think everyone is too worried about performance, when all I care about is that is operates the way a guidance system would work, AS A DEMO for school purposes. That is my whole purpose, not developing a commercial guidance system. A system that could demonstrate what it does when it is in operation.

I am grateful for the responses, so please take no offense, I am just a straight forward person, and there is no better way to say what I am trying to say....lol!!! Again, I am not being contemptuous, in any shape form or manner.

THANKS AGAIN FOR ALL OF YOUR INPUT....

One more thing, are all of the PICAXE chips available in Surface mount? I cannot seem to get an answer from anyone, they say YES, but cannot tell me where to purchase them...

Thanks...

Kim
 

boriz

Senior Member
I think you could get away with something as simple as this:

Code:
'pseudo code
do
   read x_angle_off_vertical, y_angle_off_vertical
   move x_servo to x_angle_off_vertical * 1.2
   move y_servo to y_angle_off_vertical * 1.2
loop
 

PADJ

Member
I getting very uneasy with this thread and the responses or lack thereof from the OP.
I'm out of here.
 
Last edited:

g6ejd

Senior Member
One thing I do know, is that everyone on this Forum wants to help and does in huge amounts. I think none of us want to write the code and solution for you, that said and following on from @BORIZ's prompt, here's some more pseudo code for you to contemplate and convert to PICAXE-BASIC:
Code:
PID:
   Control_Surface_Error = Required_position- Actual_Position
   Integral = Integral + (Control_Surface_Error * constant_time_period)
   Derivative = (Control_Surface_Error - Previous_error) / constant_time_period
   Control_Surface_Drive = (Control_Surface_Error * constant_time_period) + (Integral * some_constant_for_I) + (Derivative * some_constant_for_D)
   Gosub apply_control_surface_correction
   Previous_error = Control_Surface_Error 
   wait(constant_time_period)
GOTO PID
Make constant_time_period = 0.1 (sec), value depends on how fast you want to make corrections.
Make some_constant_for_I =1 to begin with, the bigger the value, the more Integral terms are added in.
Make some_constant_for_D =1 to begin with, the bigger the value, the more Differential terms are added in.

Experiment with this. The next stage of moving this to PICAXE is quite easy.

You will need to determine Required_Position and find out Actual_Position of your control surfaces. For the former you could use neutral or default (e.g. stick centre on RC controller) as that would represent (generally) straight and level flight. But if your craft was in a bunt manoeuvre, say a curved one, this routine would get it back to straight flight, which could be in any direction. So now you have to add a reference for Y as straight up, so that's where you take your reading from your attitude sensor and add it in to calculate your Desired_Position, if that makes sense. Eventually it would be corrected to vertical flight, except you have two planes to do this with, so a repeat set of coded for the other axis is necessary.
 
Last edited:

rocketdoc

New Member
I am curious why you are uneasy, just to create a demonstration unit. I have responded in kind to every question... but YOU are ultimately your deciding part, and I thank you for the input... Best regards on your journey...
 

rocketdoc

New Member
Thank you, I do NOT want people to write the code, just assist me in my learning of the coding. I AM A HARDWARE Electronics Engineer, and I had knowledge of PID, and feedback circuits, and such. I am 58 years old, and retired. I have worked as a sub contractor for the space agency, (NASA), and am just trying to continue my education. it keeps me YOUNG!!! besides, I like this new picaxe chip, I do not feel confortable with the Arduino, or what ever it is called. I like the basic programming language, rather than "C" coding. C is a reasearch language from Bell Labs, and is not a good learning base for programming electronics in my book... Just an opinion....

Thanks for the help. I will continue to work on this project until i get it right, or screw it up totally!!! that is the best way to learn!!!

Kim
 
Top