Measuring ship movement using Gyroscope, Accelerometer and Magnetometer - Page 1
Forum section: electronics / projects

author: Sjoertdb
author_rank: Contributor
timestamp: February 24, 2017, 08:46:44 am
content: Dear All,I have been assigned with the task to develop a system that detects the azimuth (pitch and roll) of a inland ship using a gyroscope, an accelerometer and a magnetometer.The system to be build has its main function to tell the change in azimuth (Since accelerometers and gyroscopes suffer from random walk, temperature influence and bias instability, there are a few options i've come up with.I have been doing research to this topic, and I've come to the following possible solutions for a possible design approach:1. Using a (cheaper) MEMS 9 DoF, consisting of a MEMS 3 Axis Accelerometer, 3 Axis gyroscope and 3 Axis magnetometer in one package like the Invensense MPU-9250, with filtering options like Kalman or a complementary filter. (Like this one:http://eu.mouser.com/applications/sensor_solutions_mems/) I'll be using an Atmel SAMV71 micro for this.2. Using a more expensive and more precise single axis gyroscope (And add two more for a 3-axis system), and seperate magnetometer and accelerometer for measuring position and velocity3. Use 4 All-in-One 9 DoF sensors, and average all sensor outputs. (A thesis report here concludes that the noise levels reduce by 1 / sqrt(Amount of samples), so 16 sensors appearantly in 4 times better readingshttp://epublications.marquette.edu/cgi/viewcontent.cgi?article=1326&context=theses_open)Note: There will be GPS onboard, maybe the NMEA data from the GPS can be used to correct the position over time? A small offset to be integrated in the accelerometer reading will result in a huge error over time. (because of the double integration of the acceleration)Is this a good design approach, and wich one would you choose? Maybe there is a better approach?Thanks in advance!Kind regards,SjoertNetherlands

author: Fungus
author_rank: Super Contributor
timestamp: February 24, 2017, 10:15:24 am
content: It's a tricky problem.I wouldn't rely too much on gyroscopes for anything. They sound good on paper but any method that relies on accumulating/integrating sensor values over time simply doesn't work reliably (in my experience).Multiple magnetometers seems like a good bet but they'll need to be mounted outside the ship away from any metal structures and the earth's magnetic field varies as you sail around.You can probably compensate for the varying magnetic field by recalibrating via. a long-term average of the accelerometers (eg. average over a minute).

author: daqq
author_rank: Super Contributor
timestamp: February 24, 2017, 10:28:36 am
content: I don't suppose you could use two GPS receivers, one located on the stern and one located at the bow? You could get an orientation vector out of the difference of the two.

author: Sjoertdb
author_rank: Contributor
timestamp: February 24, 2017, 10:38:00 am
content: QuoteFirst of all,Many thanks for giving me a new vision on the design approahUsing multiple magnetometers sure is a good option! The pcb will be mounted in a plastic enclosure outside the ship, but I'm affraid things like AIS cause lots of noise for the magnetometers. Shielding like you would normally do on like an RF-modem doesnt work in this case.QuoteThat's an idea i'm going to do some research about.I really appreciate your inputThanks!

author: Sjoertdb
author_rank: Contributor
timestamp: February 24, 2017, 10:40:56 am
content: QuoteYeah, that might work as well! I'm using GALILEO GPS modules for this. GALILEO seems a precise measurement. I forgot to tell that the product I'm working on is a unit to be placed on a ship as a single unit. That means its impossible to place two GPS recievers at the stern and bow as it has to be inside one unit...

author: daqq
author_rank: Super Contributor
timestamp: February 24, 2017, 10:56:57 am
content: Also, be wary of MEMS magnetomers - you REALLY need to calibrate them, or at least have some compensations. The individual axis have wildly different offsets and gains - you can get an error of 30deg when calculating the magnetic heading from a raw uncalibrated magnetomer, at least that was the case in LSM9DS0 which I used. Calibration/compensation is a relatively simple matter.

author: Sjoertdb
author_rank: Contributor
timestamp: February 24, 2017, 11:08:57 am
content: QuoteAn offset of 30 degrees with raw data is huge! Maybe i can fine tune it with a complementairy filter or a kalman implementation.Calibration is needed, clear. Thanks daqq!

author: daqq
author_rank: Super Contributor
timestamp: February 24, 2017, 11:12:28 am
content: QuoteYou can't - this is not a time thing. The signal is relatively low noise, but has a significant offset and gain difference. This is a physical thing. But the compensation is relatively easy.See:https://github.com/kriswiner/MPU-6050/wiki/Simple-and-Effective-Magnetometer-Calibrationhttp://diydrones.com/profiles/blogs/advanced-hard-and-soft-iron-magnetometer-calibration-for-dummieshttps://www.ecnmag.com/article/2014/12/magnetometer-2d-calibration-accurate-angle-computationEdit: That said, you can (have to) do another compensation when you add, say, a magnetic metal screw somewhere near the magnetomers.

author: Fungus
author_rank: Super Contributor
timestamp: February 24, 2017, 11:21:30 am
content: Quote from: daqq on February 24, 2017, 10:56:57 amSure, but he's not trying to find where north is, he's trying to measure angles relative to vertical.Once you establish 'vertical' (eg. by a median of accelerometer readings over a minute) then magentometers should be able to measure angles relative to that, no problem (assuming no interference).

author: Sjoertdb
author_rank: Contributor
timestamp: February 24, 2017, 11:43:46 am
content: QuoteQuoteThanks for your input guys! Thanks for the links. I'm glad to hear that magnetometer calibration is relatively easy to do in C.Also, the accelerometer mean of a number of samples is perfect for finding 'Vertical'

author: cgroen
author_rank: Unknown
timestamp: February 24, 2017, 11:50:05 am
content: Sjoert,if you go the 9DOF IMU way, please have a look at Bosch BNO055. I have used both MPU6050 and MPU9150 and found them to be, errr, "funny" to work with (lots and lots of code required on the host processor. The BNO055 has everything included oncjip (it has its own ARM Cortex M0 CPU), you talk with it using a UART or I2C (I use I2C in my projects) and it delivers Euler angles, Quaterions, acceleration, and what not.Seems to do a really good job in my opinion (lots of eval boards you can get to test it out if needed).

author: Fungus
author_rank: Super Contributor
timestamp: February 24, 2017, 12:00:49 pm
content: Quote from: Sjoertdb on February 24, 2017, 11:43:46 amI'm sure there's a lot of demons hiding in the math though.

author: Fungus
author_rank: Super Contributor
timestamp: February 24, 2017, 12:03:37 pm
content: Disclaimer: I don't know is how bad the changes in magnetic field can be when you're out at sea.Will there be places on earth where it suddenly tells you you're listing at 60 degrees?

author: tatus1969
author_rank: Super Contributor
timestamp: February 24, 2017, 12:35:41 pm
content: I did exactly this three years ago, and it seems that we have the same target application (vessel load balancing). I used an Analog Devices 9DOF module, I think it was an ADIS16364. The final system achieved +-0.2° angular error, there was no way to get better at these levels of sensor output noise.Is it only average azimuth and pitch that you need to measure? Or does your system need to capture realtime pitch/roll movements? If the latter would not be needed, it would be enough to use only a 3DOF accelerometer, and only measure and low-pass filter the gravitational force vector. That would completely eliminate the gyroscope and its random walk from the equation, and you could achieve much higher precision at lower cost.

author: Sjoertdb
author_rank: Contributor
timestamp: February 24, 2017, 12:52:08 pm
content: I am glad i hear the experiences of some chips out there. I've been considering using the MPU-9250 (lots of code required i think, just like the MPU-6050 and 9150)Thanks for suggesting some good platforms to work with, i will have a look at the BOSCH sensor and the ADIS16364. thanks for suggesting, tatus1969 and cgroenQuoteYes, its for an antenna stabilization system (in case the signal gets lost). So, its average azimuth indeed. Its basically, what angle did the boat travel in order to get the signal back.Lots of math indeedQuoteI'll have a look at it. Thanks!

author: Conrad Hoffman
author_rank: Super Contributor
timestamp: February 24, 2017, 02:30:03 pm
content: I know nothing about this, so take ideas with a grain of salt. 1) GPS usually has lousy altitude accuracy unless using differential surveying units, making it questionable for angle measurements without a huge baseline. 2) Could you make a damped pendulum sensor, maybe a mass hanging in an oil bath, with magnetic or photoelectric or capacitative position sensing? 3) Same thing, but with a spring rod holding the mass so the travel/degree is limited and the size can be reduced?

author: vealmike
author_rank: Regular Contributor
timestamp: February 24, 2017, 02:42:06 pm
content: Do some reading on the Kalman filter.Basically it combines two sources of the same data & predicts the next data point.The further away from the prediction that the next measurement is, the more filtering is applied.The filter can be tuned to take into physical constraints, eg. mass and therefore inertia.HTH

author: daqq
author_rank: Super Contributor
timestamp: February 24, 2017, 03:11:53 pm
content: Do they make MEMS (or reasonably small) gyrocompasses? Seems like if you mounted a gyrocompass onto the antenna being positioned you should be able to point it where it's supposed to be regardless of the ship?

author: mubes
author_rank: Regular Contributor
timestamp: February 25, 2017, 10:58:06 pm
content: Sjoert,If you only require Roll and Pitch and you can fix the unit in a known orientation then I don't think you need a Magnetometer, which helps remove a whole load of complexity from the situation.... Having a Gyrometer in conjunction with an Accelerometer means you will get a faster response to impulses and the additional sensor helps remove noise from the system. You can easily get 500Hz response even with a low end sensor and 4KHz sampling is supported by something like a MPU-9250.Edit: actually, I'm not sure what you gain via a magnetometer since the movements you want are related to the transverse and longitudinal axes of the vessel, not the earth, so the fixing is the important thing unless you want to be doing some interesting math on the sample data afterwards.Lookup Mahony and Sedgwick Quaternions (e.g.http://x-io.co.uk/open-source-imu-and-ahrs-algorithms/)....you can use them in '9D' (Gryo, Acc, Magno) or '6D' (Gyro, Acc) mode. Beware though that there appears to be a calculation error in the code on that site and you will need to replace the Gradient Descent calcuation in the Sedgwick code to make it fly properly.I have small boards (35x50mm) with a STM32L151 on them that can do exactly this. Since you're in NL I could possibly help if you are looking for a leg up with a (semi-)commercial solution so I will send you a PM with further information. I don't want to be plying for work or advertising on the forum.RegardsDAVE

author: Kleinstein
author_rank: Super Contributor
timestamp: February 26, 2017, 10:07:05 am
content: The normal gyro and accelerometer should be enough. The gyro for the faster movements and the accelerometer to give the low frequency / long time direction and correct drift of the gyros. With a ship, I don't think fast sampling is an issue - it is more that the typical frequencies are rather low for the gyro. So the quality (stability of drift rate, LF noise) of the gyro could be an issue.I don't think a magnetic compass would help very much, as it usually is rather noisy and would not work in all directions anyway. It is only the heading of the ship where an compass would be needed as the accelerometer can measure that and a gyro only system would drift, unless super high quality.At night is is more like a camera to watch the stars would be an option if super low noise is needed.

author: mubes
author_rank: Regular Contributor
timestamp: February 26, 2017, 12:29:42 pm
content: The fast sampling rate allows you to reduce the sensor noise. Chips like the 9250 have a LPF built in which helps remove things like vibration. I would be a bit surprised if you needed anything more complex than that.Dave

author: Sjoertdb
author_rank: Contributor
timestamp: February 26, 2017, 08:23:56 pm
content: Dear all,I appreciate your input! Many thanks from this side!

author: radar_macgyver
author_rank: Frequent Contributor
timestamp: February 26, 2017, 08:54:38 pm
content: I'm working on a similar system (antenna stabilization) but with a commercial sensor module from Kongsberg Norway. The sensor module contains three gyros and a three-axis accelerometer, all three gyros are low-drift, high precision (mechanical) units. Ship's heading is sensed using two GPS receivers that are lined up bow-to-stern. Since it's a commercial system, I don't know much about the internal algorithms used, but the documentation does reference using an EKF to fuse data from the various sensors. Stated accuracy is 0.01 degrees for pitch and roll. Yaw is worse, about 0.1 degree.It should be possible to get better than 0.1 degrees with modern MEMS accelerometers alone, but if you want to dynamically compute the roll, pitch and yaw, I'd strongly recommend using an EKF to combine gyro data with the accelerometers and GPS. Consider using one of the Trimble carrier phase tracking GPS receivers with decent antennas to block multipath reception.

author: Sjoertdb
author_rank: Contributor
timestamp: February 27, 2017, 08:40:25 am
content: QuoteThanks for the replyI have to use MEMS sensors for this job, because a commercial unit is too expensive. I'll have a look at how such an EKF works.Many thanks radar_macgyver!

author: 3db
author_rank: Frequent Contributor
timestamp: February 27, 2017, 09:20:34 am
content: Gyros can be pretty stable.I have experience of a vertical gyro used to stabilise an echo sounder transducer against the roll and pitch of the vessel.That system worked very well.There are also some gyro compasses that when you rotate the compass enclosure quickly it's as if the compass card was fixed to the deck.3db

author: Sjoertdb
author_rank: Contributor
timestamp: February 27, 2017, 10:29:51 am
content: QuoteIn what order of magnitude did the gyro have to perform? Like what gyro specs did you have to meet for the system not to drawn in the noise levels and zero-rate level of the gyro?Thanks for your input

author: 3db
author_rank: Frequent Contributor
timestamp: February 27, 2017, 09:02:00 pm
content: Quote from: Sjoertdb on February 27, 2017, 10:29:51 amThe beam width of the tranducer was about 3 Deg and had a diameter of about one metre.I can't remember the degree of roll and pitch the system was designed for.I think the gyro was made by Anschutz.The whole stabilisation system was a servo mechanism where the field coils of a rotary machine were controlled and the output of the machine fed the motors to control roll and pitch.These field coils were fed by rather large tubes about 3 inches in Dia in push pull two for roll and two for pitch.The system did work quite well and was typically used on research vessels.For example to survey the Marianas trench.I think on one axis it might have been about +/- 15 deg.Sorry I can't remember more details.I was a long time ago.3DB

author: Sjoertdb
author_rank: Contributor
timestamp: February 28, 2017, 11:01:24 am
content: Many thanks 3db!

author: Fungus
author_rank: Super Contributor
timestamp: February 28, 2017, 04:13:00 pm
content: Quote from: 3db on February 27, 2017, 09:20:34 amGreat big mechanical ones, sure.Microscopic electronic ones? Not so much. They can tell you about small fast rotations but anything more than that is drowned in noise.

author: 3db
author_rank: Frequent Contributor
timestamp: March 01, 2017, 08:11:17 am
content: Quote from: Fungus on February 28, 2017, 04:13:00 pmThe gyro used in the compass I mentioned was small compared to others of that time.I think it was called a flexure gyro. It was perhaps 2 inches in diameter from memory.That gyro compass was unlike anything I had ever seen before.This was all decades ago.Here's a link to the current model of that compasshttp://www.yymarine.com/en/uploadfiles/201372152617251.pdf3DB

author: Sjoertdb
author_rank: Contributor
timestamp: March 01, 2017, 02:58:56 pm
content: I did a teardown of an existing unit during a company visit.They used 3 gyros, analog ones from Murata, an inclinometer (also from Murata) and a Honeywell magnetometer. Those parts aren't recommended for new design since they are obsolete.Its funny that they used a plastic block to mount the gyros.

author: mubes
author_rank: Regular Contributor
timestamp: March 01, 2017, 03:36:18 pm
content: What is your application? What accuracies do you need?DAVE

author: Sjoertdb
author_rank: Contributor
timestamp: March 01, 2017, 10:21:22 pm
content: QuoteIts a setup that has to sense the heading of the ship in order to control the azimuth of the satellite dish to the last known azimuth. This is in case the ship sees a blockage like a bridge.

author: 3db
author_rank: Frequent Contributor
timestamp: March 02, 2017, 12:45:26 am
content: Quote from: Sjoertdb on March 01, 2017, 10:21:22 pmYou could take a feed from the ships gyro compass.3DB

author: BrianHG
author_rank: Super Contributor
timestamp: March 02, 2017, 05:09:18 am
content: Quote from: Conrad Hoffman on February 24, 2017, 02:30:03 pmI like this idea, however, I would use 2 load cells, one detecting the X axis bend and one right above detecting the Y with a weight (pendulum) mounted below. No oil, no bath, just a 2 channel scale reading the X&Y load cells. I bet just by increasing the weight, you can measure hundreds to thousandth's of a degree off the vertical axis. The math for this part would be easy, but, you wont receive orientation, just a vertical reference fix relative to gravity.

author: Sjoertdb
author_rank: Contributor
timestamp: March 02, 2017, 08:24:40 am
content: QuoteI have also thought of that, but that was not an option. The unit must be self contained with a gyrosensor

author: Sjoertdb
author_rank: Contributor
timestamp: March 02, 2017, 08:28:38 am
content: QuoteHow would you think it could be implemented? Should i think of a custom box with a pendulum with XY axis, and adjustable mass?Great idea!

author: BrianHG
author_rank: Super Contributor
timestamp: March 02, 2017, 09:06:19 am
content: I was thinking of using 2 of these ultra cheap load cells you see in scales (see attached image). The load cell reads the positive and negative bend from the left side to the right side, so if you mount it vertically, one on top of the other twisted 90 degrees, with a weight pulling down below, both load cells should read 0grams, if everything is perfectly balanced. If your fixed axis at the top has any angle on it, each load cell will read it's pull or bend in their x&y axis. Obviously, the load cell closer to the top will read more than the one next down, but with a 1kg weight, you can read parts of a mg of weight in each direction when the pendulum bends the apparatus off axis.With a 10kg weight, you multiply your sensitivity at least 10x, though, with the boat swaying, you will need stronger load cells.