How sensitive will the compass be to the RC car’s motor?
EDIT: It’s probably worth noting that I need something pretty accurate. By how much, I don’t really know, but as long as the compass it pretty close it should be ok. I can always run a software filter on it.
Have in mind that this sensor is not tilt compensated. So when you robot is only on a flat surface it is no problem but when you drive over a hill for example it could be a problem
Sparkfun has also the tilt-compensate version but it is much more expensive.
Worked fine, but mind you mostly on a flat desk… not in a remote control car If you tilt it (I can’t remember what the threshold was), it doesn’t work overly well so there’s a reason they make the tilt compensated ones… but at 4x the cost, ouch
I had ported the code over from some other Basic derivative at the time to MikroeBasic and it wasn’t bad at all to read the sensor. I’m hoping to use one of these in a future project (too many lined up)… so if you post it, it would be appreciated!
What about getting a cheap one (no tilt)… and using a GPS to compensate? So if beyond a certain threshold, and it’s moving, use the GPS to find direction. Another option (though not sure how practical) would be to mount the module on a pivot like device (remember the old ship compasses?) so it’s constantly level regardless of the position of the vehicle.
Yeah, I thought about putting the compass on a pivoting mount running from the IMU feed, but that’s just one more failure point. I’d rather pay an extreme amount of money for a really good compass than try to bandaid a cheap one.
I suppose I could use GPS to compensate, but again, I’d like the compass to be able to find it’s own.
Honestly that’s probably not a bad idea… as it’s probably not worth the trouble. One less thing to break and less coding to worry about it Plus if it’s stopped, on an incline, and using the GPS compensation method, it won’t be much use.
your IMU will have degrees as a calculation that is possible. Since the gyro in it will be able to handle tilt. When compass is in tilt use gyro as your calculation as you are already paying for it. If the gyro in side is a heading hold version then even better.
So what i mean is you will know your degree of tilt. Once off base you can use the heading of the gyro to determine your heading from last point that compass was non tilt. The degrees of tilt will effect the reading like 2 degrees per degree of tilt. So checking the gyro as a backup will allow you to know your true degrees of turn or if you are still on course once you detect tilt with it. Just sync up you compass and gyro on init which should happen on level land.
@ bstag, Thanks. That’s very close to what I was thinking about doing. I might just do that instead.
@ cypher, Thank for the link. I have Sparkfun in my subscriptions, but for some reason that video didn’t show up when it came out. I’ll give it a though watch tomorrow!
I know, I know, that $150 compass is the one I should really be buying, but jeez, that is a lot of money to spend on a single sensor. Nevermind the fact that I still have to buy an IMU.
def wrap(angle):
if angle > pi:
angle -= (2pi)
if angle < -pi:
angle += (2pi)
if angle < 0:
angle += 2*pi
return angle
def magnetometer_readings_to_tilt_compensated_heading(bx, by, bz, phi, theta):
“”" Takes in raw magnetometer values, pitch and roll and turns it into a tilt-compensated heading value ranging from -pi to pi (everything in this function should be in radians). “”"
variation = 4.528986*(pi/180) # magnetic variation for Corpus Christi, should match your bx/by/bz and where they were measured from
Xh = bx * cos(theta) + by * sin(phi) * sin(theta) + bz * cos(phi) * sin(theta)
Yh = by * cos(phi) - bz * sin(phi)
return wrap((atan2(-Yh, Xh) + variation))