Welcome to Synthiam!

The easiest way to program the most powerful robots. Use technologies by leading industry experts. ARC is a free-to-use robot programming software that makes servo automation, computer vision, autonomous navigation, and artificial intelligence easy.

Get Started
Asked — Edited
Resolved Resolved by DJ Sures!

4 In One Orientation Sensor

I have purchased a 4 in One Orientation Sensor. My desire is to use the compass function.

Once loaded and running, I view the compass heading values in the Variable watch window.. The value fail to read correctly. I find when I set the device in 90 degree directions ( 0 - 90 - 180 - 270 - back to zero ) I get value that do not even come close to the set position., nor do they repeat. I have changed my location, and even tried it in a wooden shed without any potential magnetic interferences, and still it did not work.

Has anyone use this sensor and has been able to get it to display correctly?

My reason for buying this was for the compass only and I am disappointed to see it not work.

Ron R


Upgrade to ARC Pro

Your robot can be more than a simple automated machine with the power of ARC Pro!

I have applied the last update but I even after calibration $CompassX, $CompassY and $CompassZ are stuck to 129 (or -129).
Am I missing something ?
If it's not working, then yes you are:)

Here's the manual page for the MPU 9150 All In One module:http://www.ez-robot.com/Tutorials/Help.aspx?id=213

Also, unless you wish to perform serious math, as in my previous posts, do not pay attention to the $compassx $compassy $compassz variables - that's a whole new world that you most likely don't want to experience.

Follow the manual page and use the $CompassHeading variable only.


I might think of an EZ-Script command to throw in that will perform a range check between two degrees - should be useful for your needs. Let me think on that...

yes, that would be helpful I think. I was going to use a if $bearing <= $heading (or >= depending on which way I am turning), but being able to have a target range would probably be better. Will have to figure out what happens when I cross the 0/360 boundary to keep from turning to far. Figuring out the target $heading (ie $bearing) is easy, but knowing I have hit it trickier. For instance, if I am at 270 and my new target is 5, I need to keep going until I am greater than 360, and then continue until I am up to 5, so probably move in two steps instead of one. I'll figure it out.

Ok @DJ, I followed your advice and look only at the heading variable. However, the heading value don't change when I rotate the sensor, but only when I roll it...
Hi Alan,

I was wondering about converting 360 degrees to 1 to 179 positive and 181 to 359 as 1 to 179 negative numbers. 0 and 180 unsigned. This would allow the numbers to become directional. I haven't fully thought it thru, but what do you think? It should simplify the math?

Ron R

I forgot to mention invert the numbers, i.e. count + 177, +178, +179,180, -001, -002,-003, etc. 180 for example = South 0=North
Hi Dj.

I know it took a lot of work to get it right. Thanks very much ! I am sure many of us will put it to good use.

Ron R
I have been following this thread and decided to try the compass for myself. Perhaps I've missed something, but from what I've tried, the compass only seems to work when it is in a vertical position. Even then, it has to be turned in a circle, edgewise, for the readings to work out for 360 degrees. Is this correct?

I have calibrated it flat by putting it in the slot between JDs legs and again vertically by putting it in the chest slot. When flat it does nothing as I turn JD. In the chest, it only works when I tilt JD side to side.
WBS, you need to calibrate the sensor. View the ARC manual page for a video demonstrating.
I did calibrate it, twice. All according to the tutorial and the video in it. As I said above:


I have calibrated it flat by putting it in the slot between JDs legs and again vertically by putting it in the chest slot

Did the figure-8 thing and all. That seemed to go well. Ran the calibration once when I placed the sensor in the flat position, and ran it again when I placed it in the chest. When the chest position didn't work either, I put it back in the flat position and ran the calibration yet again. It works in both positions but only when I turned JD such that the board is upright (vertical) and rotated the robot such that the sensor board was turning in a circle with the edge of the board leading the way. Only then did the pointer in the control rotate appropriately, 360 degrees. If I rotated JD around the vertical (Z) axis while he is standing, the pointer did not move.
Hi @WBS00001,

I just tried it again with the new release. I started the init script., Hit the calibrate button and move it as was requested. Once the time zeroed, I placed the sensor flat on my desk. Rotating it on the horizontal plane I got the readings. I placed the sensor in three stacked ez blocks and found I could angle the sensor about 45 degrees from horizontal and still have it read.
If you get to close to the ezb it seems unable to work correctly.

Ron R
User-inserted image

User-inserted image
Hi Dj,
First, Again thanks for the upgrades of the compass.

The Quadrant displays are great. This will help with turns and direction.

Are we still able to get the "degree" numbers also? I want to experiment with both. I want to use them also as coordinates.

EDIT: Oops,, I messed with the setup and found the rounding works. This is great! Now I can go play.

Ron R
Thanks for the input.

Ok, I decided to start from scratch so I made a new project and tried the calibrate and run script with it. I even made sure the servos had no power going to them yet. And ... it worked perfectly! Progress! Set it to nearest 10 degrees and it still worked perfectly.

Then I imported the Auto Position control from the example so I would have a servo setup model from which I could load a servo profile to set and energize the servos. Still worked fine. Even tried another calibration with the servos energized, still perfect.

Finally I went back to the original project I was running last night. Went through the calibration process again and all went well this time.

I kind of hate it when that happens because now I don't know why it didn't work last night. I changed nothing in the project.

Anyway, now I'm going to try another unit (still in the original packaging) and see if the same thing happens with the project from last night.

All of which leads to a question .... Once calibrated, do the calibration values get stored on the MPU9150 itself or in the EZB project file?
I would say in each project because of how the config settings work with plugins but that is a good question.
I think in the project. Doesn't the sensor only send the raw data and Dj's all night math, makes the values work ? I am not even sure the calibration will stay accurate? We will need some more tests or confirmation.

Ron R
The calibration is required each time - because it is not saved, yet. Also, the calibration continues to "learn" the longer the compass is used. So, if you continue to use it the calibration will become more accurate over time.

What can really screw the calibration up is large jolts or bangs. The compass will need to be re calibrated if that happens - this is due to the physics of a compass module and how it works - if they are jolted the calibration will be lost.

The drawing of how to calibrate does not imply the compass should be thrown in a figure 8 :). Simply gently wave it in a figure 8 motion like you do with an iPhone when prompted.
Only had a little time for testing tonight, but the rounding function is perfect for my needs. I set it to 15 and it gives just the right amount of precision for navigation, and enough stability that I can trust my scripts not to overshoot their turn.


Wicked - it should come in handy the most with Roli because the PWM can be modified slightly for forward rolling turns to compensate for the compass variations.
Hi Alan,

Are your tests with the adventure Bot or Roli?

My goal is to get my adventure Bot to track on a compass coordinate until a ping distance then go to next step in the sequence script. The bot compass also is used to trim the straight line track by trimming the wheel servos. The compass also confirms turns are complete. Is this similar to what you are doing?

Ron R
I was testing with Adventurebot. I put an expansion cube off the front and then another on top of it and put the compass on that to get a little distance from the motors in the servos and any interference from the EZ-B itself.

My mid term goal is to put it in or on Roli.

Long term is a custom robot.