How does maghold work ?

This forum is dedicated to software development related to MultiWii.
It is not the right place to submit a setup problem.
Software download
Post Reply
Kayle
Posts: 141
Joined: Sun Feb 13, 2011 6:45 pm

How does maghold work ?

Post by Kayle »

Hello all,

i try to understand how maghold works. I don´t use Arduino IDE for Programming. I use Bascom on an Atxmega. My MAG is a CMPS10 I2C and i gives me values between 0 and 360.

My Question is:

For example the desired degrees are 0°. How does multiwii code prevent that the actual degrees jump to 360° ? My code use a PID to adjust a PWM. There is no Problem if the desired degrees are for example 100°. But if the desired degrees are 0° the PID Controller adjust the PWM so far that the actual degrees become for a little moment 360 - 355 °. So the Servo ( PWM ) turns on full rotation until the degrees are nearly 0°.

How Multiwii handles this ?

Kind Regards
Kay

User avatar
Plüschi
Posts: 433
Joined: Thu Feb 21, 2013 6:09 am

Re: How does maghold work ?

Post by Plüschi »

You subtract actual direction and wanted direction. Then you norm this to -180 to +180 by subtracting or adding 360. Aint too diffcult.

Nice sensor. Tilt compensated ...

Kayle
Posts: 141
Joined: Sun Feb 13, 2011 6:45 pm

Post by Kayle »

Thanks for your fast reply. I will Test it tomorrow.

Kayle
Posts: 141
Joined: Sun Feb 13, 2011 6:45 pm

Post by Kayle »

It works. Thank you Plüschi.

Post Reply