Jacarebs

  • *
  • 22
  • My drone will eventually get along with my mag
AuxMag won't get a decent orientation
« on: March 18, 2017, 08:28:12 am »
Hey! I've been struggling to fly my drone, since the mag won't get calibrated, I think. I used this video as a guideline on how to calibrate the AuxMag on my Ublox 6m GPS:



I can pretty much nail it down, but as soon as I move the drone in the yaw axis, the mag reading start to get wrose and worse, until I rotate it by roughly 180 degrees, then it starts lowering the error percentage again. I've also tried to correct the AuxMag orientation and I could manage to get the bargraphs down to 0, but as soon as I move the drone, they start to go off by way more than 10 units.

I just want to fly my drone and I've spent way more than 100hrs trying to build this drone. The only thing that keeps me from flying it is this damn mag. I could fly it before when I was at the beach, somehow I could get the calibrations right, but as soon as I got back to the city, I tried taking off with it and I saw, by the LibrePilot app, that themag readings were red. I tried taking off anyway and it just flew erratically and I ended up crashing-landing it. It wasn't too bad, it is still in one piece, but I got pretty frustrated when I tried recalibrating it and could not get it working.

What am I missing? I'm calibrating it in my bedroom, attached to my laptop by a 1.5m USB cable. The AuxMag is sitting with the GPS up in a pole, tightly fixed.

Please help!
« Last Edit: March 18, 2017, 08:32:00 am by Jacarebs »

Mateusz

  • *
  • 791
Re: AuxMag won't get a decent orientation
« Reply #1 on: March 18, 2017, 04:14:07 pm »
To adjust orientation of AuxMag to match internal Mag you need first good calibration of both magnetometers.

  • You can't have good mag calibration if you put your copter on floor while it's calibrating or too close to metal items/wires
  • Calibration collects samples all time from start, not just when it asks you to rotate copter, so any disturbance will cause error

Best is if you take it outdoors, use OP-link modem and attach battery. Keep it in the air and rotate it slowly without putting on the ground. You don't need to follow instructions in wizard, you can just click to last step (6th step) and rotate it slowly in all possible directions, then finish last step to save calibration.

If that is done correctly, then you can adjust AuxMag rotations, to have bars at zero. If you still don't have bars at zero, then there are high power currents messing up one Mag readouts. Basically Mag must be green all time, to be able to adjust AuxMag rotation. (On the movie both mags <0.5% error in green boxes).
« Last Edit: March 18, 2017, 04:20:52 pm by Mateusz »

Jacarebs

  • *
  • 22
  • My drone will eventually get along with my mag
Re: AuxMag won't get a decent orientation
« Reply #2 on: March 18, 2017, 06:11:19 pm »
To adjust orientation of AuxMag to match internal Mag you need first good calibration of both magnetometers.

  • You can't have good mag calibration if you put your copter on floor while it's calibrating or too close to metal items/wires
  • Calibration collects samples all time from start, not just when it asks you to rotate copter, so any disturbance will cause error

Best is if you take it outdoors, use OP-link modem and attach battery. Keep it in the air and rotate it slowly without putting on the ground. You don't need to follow instructions in wizard, you can just click to last step (6th step) and rotate it slowly in all possible directions, then finish last step to save calibration.

If that is done correctly, then you can adjust AuxMag rotations, to have bars at zero. If you still don't have bars at zero, then there are high power currents messing up one Mag readouts. Basically Mag must be green all time, to be able to adjust AuxMag rotation. (On the movie both mags <0.5% error in green boxes).

Yeah, I get that the mag is capturing data all the time and I can skip to the 6th step and rotate it, I've been using this method lately. The problem is that I don't think my OP-link is working anymore... is there a way that I could do it without it? With, like, a really long USB cable? I will try to do it outdoors today and see what comes out of it.

Yeah he's got less than 0.5% of error, but he has his board outside his drone. Should I do it as well or should I keep my board in my drone?

Thanks!

Mateusz

  • *
  • 791
Re: AuxMag won't get a decent orientation
« Reply #3 on: March 18, 2017, 06:48:57 pm »
Yeah he's got less than 0.5% of error, but he has his board outside his drone. Should I do it as well or should I keep my board in my drone?

The whole purpose of calibration is to account for quad-copter itself. So taking FC out from quad for calibration would defeat the purpose. I think the movie is just for demonstration how to do alignment of two magnetometers. For that it is required to have good calibration. But it's not how calibration should be done for flight purpose.

Magnetometer is sensitive to metals, conductors or whole quad-copter frame. Also both mags must have fixed position. All bodies nearby magnetometer are taken into account when doing calibration, so magnetometer gets cleaner picture. What cannot be accounted for is changing magnetic field. Changing magnetic field comes from wires conducting electricity for example motors pulling more or less current when motors spin faster/slower. That cannot be removed by calibration and is the reason why you need magnetometer far from these sources.

But once your have good mag calibration, you can find rotations. Rotations are needed to tell software how external magnetometer is mounted as every manufacture can place it differently. Internal magnetometer is convenient tool for that, as it's orientation is known. When both mags are aligned, both show the same curves in scopes and both bars are at zeros.


I forgot one more thing. The only way to isolate from magnetic field is couple of meters of concrete wall. You can't do that on quad-copter, but you can redirect magnetic field, by making it weaker in one direction and stronger in another. Direction of magnetic field is like on (see attached Fig1). If you twist wires then you make magnetic field weaker in the direction perpendicular to the horizontally twisted wires (see attached Fig2). In Fig1 magnetic field is stronger in the direction perpendicular to wires.
That's why people often twist higher current wires if they run below magnetometer. It may help. I don't recommend surfaces that redirect static field (nu-metal) as that would isolate  your magnetometer. You would probably get less interference from motors but magnetometer would sense only noise.
« Last Edit: March 18, 2017, 06:58:36 pm by Mateusz »

Jacarebs

  • *
  • 22
  • My drone will eventually get along with my mag
Re: AuxMag won't get a decent orientation
« Reply #4 on: March 18, 2017, 07:45:47 pm »
Yeah he's got less than 0.5% of error, but he has his board outside his drone. Should I do it as well or should I keep my board in my drone?

The whole purpose of calibration is to account for quad-copter itself. So taking FC out from quad for calibration would defeat the purpose. I think the movie is just for demonstration how to do alignment of two magnetometers. For that it is required to have good calibration. But it's not how calibration should be done for flight purpose.

Magnetometer is sensitive to metals, conductors or whole quad-copter frame. Also both mags must have fixed position. All bodies nearby magnetometer are taken into account when doing calibration, so magnetometer gets cleaner picture. What cannot be accounted for is changing magnetic field. Changing magnetic field comes from wires conducting electricity for example motors pulling more or less current when motors spin faster/slower. That cannot be removed by calibration and is the reason why you need magnetometer far from these sources.

But once your have good mag calibration, you can find rotations. Rotations are needed to tell software how external magnetometer is mounted as every manufacture can place it differently. Internal magnetometer is convenient tool for that, as it's orientation is known. When both mags are aligned, both show the same curves in scopes and both bars are at zeros.


I forgot one more thing. The only way to isolate from magnetic field is couple of meters of concrete wall. You can't do that on quad-copter, but you can redirect magnetic field, by making it weaker in one direction and stronger in another. Direction of magnetic field is like on (see attached Fig1). If you twist wires then you make magnetic field weaker in the direction perpendicular to the horizontally twisted wires (see attached Fig2). In Fig1 magnetic field is stronger in the direction perpendicular to wires.
That's why people often twist higher current wires if they run below magnetometer. It may help. I don't recommend surfaces that redirect static field (nu-metal) as that would isolate  your magnetometer. You would probably get less interference from motors but magnetometer would sense only noise.

Yeah, I've seen people twisting their wires and I get the physics around it, but since I can't event calibrate it when the motors are not spinning, I don't really think that the magnetic field generated by powering the escs are actually being the real problem; I think that I'm not calibrating it properly. I just calibrated it outside and I asked a friend to hold the drone while I skipped to the 6th phase of the calibration. Then I took the drone and gently rotated it in all directions possible 2 times and then I asked my friend to hold it again and I saved the last position. After that, I just put it on the ground and tried to get the orientation of the AuxMag correctly. As you can see in figure 1, the mag of my GPS is in the bottom of the GPS board, so it has 180 degrees of roll rotation. In figure  2 and 3, you can see that the GPS is rotated in the yaw axle by -145 degrees, roughly, considering that the white wings are the positive region and that the red wings are the negative region; note that the FC is pointed to the white wings, so it has a 90 degree rotation in the yaw axle. The problem is that when I input this information, the bargraphs do not align. Also, even though I got an error margin of 2% at max after the calibration, as soon as I rotate the drone, the readings go off the chart, reaching as high as 50~60% of error. To be honest, this part of the process has always been a problem and I could never get this right. Do you think my auxmag could be broken? I don't think it is, since it reads the values, but I'm nearly giving up and buying another GPS. Could you describe me how you calibrate your mags or what could I do?

Thanks for the help, man.

Mateusz

  • *
  • 791
Re: AuxMag won't get a decent orientation
« Reply #5 on: March 19, 2017, 06:55:53 am »
You can take two small papers and draw on them (USB port, Bottom/Top, FC/GPS and L833 chip orientation) see attachment.
To match both L883, I did +180 roll and -45 yaw of the paper with GPS label on it.

If you do -145 that's very strange rotation. It's 45 deg then another 100deg. But board is square and chip is perpendicular to it's edges, so extra 10 deg makes no sense to me. I am not sure in which direction + or - is, but you could try a couple of combinations.

Maybe just give a try +180 roll and -45 yaw and if that does not work, check other +/- options ?

Jacarebs

  • *
  • 22
  • My drone will eventually get along with my mag
Re: AuxMag won't get a decent orientation
« Reply #6 on: March 19, 2017, 07:51:17 am »
You can take two small papers and draw on them (USB port, Bottom/Top, FC/GPS and L833 chip orientation) see attachment.
To match both L883, I did +180 roll and -45 yaw of the paper with GPS label on it.

If you do -145 that's very strange rotation. It's 45 deg then another 100deg. But board is square and chip is perpendicular to it's edges, so extra 10 deg makes no sense to me. I am not sure in which direction + or - is, but you could try a couple of combinations.

Maybe just give a try +180 roll and -45 yaw and if that does not work, check other +/- options ?

Well, I tried a lot of combinations and neither of them worked. I got my aux mag calibrated though, it seems, because I do not get red alarms in it, even at 1m from my laptop. I think that I just need to calibrate the onboard mag and see if I can match their rotations. Does the onboard mag calibrates at the same time with the aux mag or I need to take off my aux mag to calibrate the onboard one?

I tried flying my drone today with the aux mag only to see what would happen and it actually took off, but it was quite erratic: I was flying a stabilized mode with GPS assist and attitude/attitude/axislock/alitudevario as its configuration and the drone would keep drifting and going towards the wall or something and up or down, so I would need to compensate for it constantly. I tried to switch to PositionHold after taking off and it went on in circles.

Do you think that my problems reside on my mag configuration?

Mateusz

  • *
  • 791
Re: AuxMag won't get a decent orientation
« Reply #7 on: March 19, 2017, 09:11:01 am »
Well, I tried a lot of combinations and neither of them worked.

Roll 180 and yaw -45 also didnt work ? Flight controller and GPS have the same magnetometer chip. If they both point in the same direction, then rotation is 0,0,0. What you set in GCS is the rotation for external (aux) mag.

I got my aux mag calibrated though, it seems, because I do not get red alarms in it, even at 1m from my laptop. I think that I just need to calibrate the onboard mag and see if I can match their rotations. Does the onboard mag calibrates at the same time with the aux mag or I need to take off my aux mag to calibrate the onboard one?

From what I remember you need to select "Use Both" magnetometers to get the calibrated together at the same time. And that's the correct way to do it.

I tried to switch to PositionHold after taking off and it went on in circles.
Do you think that my problems reside on my mag configuration?

Flying in circles so called toilet bowl is typical to bad calibration of magnetometer or bad mag readings. I doubt your rotations are correct, 145 deg makes no sense to me.
If you have all sensors telling EKF that front is front and Mag tells front is back. Then you get oscillations in EKF states and toilet bowl.
If you look inside flight controller you see chip L883 (dot). So if you imagine that reading this from left to right and above that label is forward direction, you have to match that with the same chip on GPS module. If I am not wrong I think it's 180 roll and +45 or -45 yaw.

How is the horizon in PDF behaving ? Are the scopes showing the same pattern when you rotate copter in all directions ? X,Y,Z for MagSensor should follow exactly X,Y,Z lines for AuxMagSensor if you set rotations correctly.

Jacarebs

  • *
  • 22
  • My drone will eventually get along with my mag
Re: AuxMag won't get a decent orientation
« Reply #8 on: March 19, 2017, 06:33:51 pm »
Roll 180 and yaw -45 also didnt work ? Flight controller and GPS have the same magnetometer chip. If they both point in the same direction, then rotation is 0,0,0. What you set in GCS is the rotation for external (aux) mag.

Nah, unfortunately the 180/-45 didn't work... I followed your example yesterday and I was trying to figure out the rotation of the mag, but since I don't think the onboard mag is calibrated, it was worthless to continue until I get it calibrated.

From what I remember you need to select "Use Both" magnetometers to get the calibrated together at the same time. And that's the correct way to do it.

Oh. I was actually selecting AuxOnly. Well, I'll calibrate it again today with both and see what comes out of it. Thanks :D. Oh, by the way, do you know somehing about virtual board orientation? Do I need to set something other than 0,0,0 if the FC is actually pointing forward?

Flying in circles so called toilet bowl is typical to bad calibration of magnetometer or bad mag readings. I doubt your rotations are correct, 145 deg makes no sense to me.
If you have all sensors telling EKF that front is front and Mag tells front is back. Then you get oscillations in EKF states and toilet bowl.
If you look inside flight controller you see chip L883 (dot). So if you imagine that reading this from left to right and above that label is forward direction, you have to match that with the same chip on GPS module. If I am not wrong I think it's 180 roll and +45 or -45 yaw.

How is the horizon in PDF behaving ? Are the scopes showing the same pattern when you rotate copter in all directions ? X,Y,Z for MagSensor should follow exactly X,Y,Z lines for AuxMagSensor if you set rotations correctly.

Well, then we seem to have found the culprit to why all these things are happening: it really is the mag, then. The horizon is pretty neat, even though it wiggles a bit even when the drone is stopped. The scopes are shown on figure 1 when it is pointing towards me and on figure 2 when it is pointing to the right. It should not move, right?

Thanks

Mateusz

  • *
  • 791
Re: AuxMag won't get a decent orientation
« Reply #9 on: March 19, 2017, 07:19:17 pm »
Oh. I was actually selecting AuxOnly. Well, I'll calibrate it again today with both and see what comes out of it. Thanks :D. Oh, by the way, do you know somehing about virtual board orientation? Do I need to set something other than 0,0,0 if the FC is actually pointing forward?

No if FC is flat and pointing forward you don't need to touch virtual board rotation. It's only for FC. In future if you would rotate your FC and adjust virtual board rotation, you would need to adjust also AuxMag rotation. In your case you don't touch virtual board rotation, as your FC is pointing forward already (front motors 1 and 2).

Well, then we seem to have found the culprit to why all these things are happening: it really is the mag, then. The horizon is pretty neat, even though it wiggles a bit even when the drone is stopped. The scopes are shown on figure 1 when it is pointing towards me and on figure 2 when it is pointing to the right. It should not move, right?

Magnetomer is like a digital compass it's measure a vector [x,y,z] in 3D space pointing where strongest magnetic field is (preferably north). So when you rotate it then these x,y,z curves should also change. What I see on your scopes is that MagSensor.x goes up and at the same time AuxSensorMag.x goes down in opposite direction. This means one has different orientation. When they are both aligned and have matched orientation curves from aux/internal behave the same (x follows other x, y follows other y etc..). Both magnetometers must give the same information, not conflicting. So when you turned it, both MagSensor.x and AuxSensorMag.x should go either up or down but together and not opposite directions.
« Last Edit: March 19, 2017, 07:25:47 pm by Mateusz »

Jacarebs

  • *
  • 22
  • My drone will eventually get along with my mag
Re: AuxMag won't get a decent orientation
« Reply #10 on: March 19, 2017, 07:33:13 pm »
No if FC is flat and pointing forward you don't need to touch virtual board rotation. It's only for FC. In future if you would rotate your FC and adjust virtual board rotation, you would need to adjust also AuxMag rotation. In your case you don't touch virtual board rotation, as your FC is pointing forward already (front motors 1 and 2).

Well, then I won't mess with it :). Thanks.

Magnetomer is like a digital compass it's measure a vector [x,y,z] in 3D space pointing where strongest magnetic field is (preferably north). So when you rotate it then these x,y,z curves should also change. What I see on your scopes is that MagSensor.x goes up and at the same time AuxSensorMag.x goes down in opposite direction. This means one has different orientation. When they are both aligned and have matched orientation curves from aux/internal behave the same (x follows other x, y follows other y etc..). Both magnetometers must give the same information, not conflicting. So when you turned it, both MagSensor.x and AuxSensorMag.x should go either up or down but together and not opposite directions.

Oh, I get it now. Well, I will try to calibrate it today with both mags active at the same time - by selecting Both in mag usage, on the Magnetometer tab - and I will post the results.

Thanks a lot :)

Jacarebs

  • *
  • 22
  • My drone will eventually get along with my mag
Re: AuxMag won't get a decent orientation
« Reply #11 on: March 19, 2017, 08:36:49 pm »
Ok, I just tried calibrating it again and this time both mags wouldn't give me a red warning at any time. They would give me orange warnings sometimes, but not a red. However, the orange warnings would go as high as 11%. Well, I tried getting the orientation right and it would not work again, with any combination. I tried flying it again and it would fly worse than before, I couldn't even take off properly, it would either flip to the side or take off and fly away in a direction.

On a side note: I noticed that sometimes a motor will spin really slowly before taking off, so I always need to apply a roll command to make it spin normally, and it has always occurred, even from day 1 of this drone.

Do you think any of my sensors are broken or something? If I could log a flight on LP, would it help? If so, do you know how I could do it?

Mateusz

  • *
  • 791
Re: AuxMag won't get a decent orientation
« Reply #12 on: March 19, 2017, 08:45:10 pm »
Orange is 11% is not good. Must be green all time. Did you calibrate it indoors perhaps ? Are you trying to fly indoors ? For flying you should set it to AuxOnly, cause internal one will read bad stuff when motors are running. Just use both for calibration and setting rotations when motors are not running, then switch to AuxOnly.
What we know is that AuxMag is flipped 180 deg, cause it's bottom of GPS board, and Mag on FC is top. So you just need to roll it 180 deg and then adjust yaw. Then you should see curves in scopes behaving the same, do they ?

Be careful with USB cable, not to break micro-usb port on Revo, it can rip off if you pull cable accidentally.

One more thing that comes into my mind. You use I2C for aux-mag right ? Can you check scopes by adding I2CStatus UAVObject and checking if there are no event_errors or timeouts ? Is I2C box always green ?
« Last Edit: March 19, 2017, 08:59:35 pm by Mateusz »

Jacarebs

  • *
  • 22
  • My drone will eventually get along with my mag
Re: AuxMag won't get a decent orientation
« Reply #13 on: March 19, 2017, 09:02:50 pm »
Orange is 11% is not good. Must be green all time. Did you calibrate it indoors perhaps ? Are you trying to fly indoors ? For flying you should set it to AuxOnly, cause internal one will read bad stuff when motors are running. Just use both for calibration and setting rotations when motors are not running, then switch to AuxOnly.
What we know is that AuxMag is flipped 180 deg, cause it's bottom of GPS board, and Mag on FC is top. So you just need to roll it 180 deg and then adjust yaw. Then you should see curves in scopes behaving the same, do they ?

Be careful with USB cable, not to break micro-usb port on Revo, it can rip off if you pull cable accidentally.

I did it outdoors, on the penthouse of my apartment building, with clear skies. I calibrated and tried the rotations with it set to Both and motors stopped. Then, I tried to fly it with it set to AuxOnly.

In figure 1, it was facing me and then I rotated it to face right. Notice that the onboard mag seems constant. I tried zooming in and the values were really not changing.

Mateusz

  • *
  • 791
Re: AuxMag won't get a decent orientation
« Reply #14 on: March 19, 2017, 09:06:52 pm »
I did it outdoors, on the penthouse of my apartment building, with clear skies. I calibrated and tried the rotations with it set to Both and motors stopped. Then, I tried to fly it with it set to AuxOnly.

In figure 1, it was facing me and then I rotated it to face right. Notice that the onboard mag seems constant. I tried zooming in and the values were really not changing.

Indeed this looks interesting. Can you change colors, so they're not the same as AuxMag for Mag ? To me it looks like AuxMag is constant on this plot.