Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

How to code servo with a gyro?!?


I just sent you some pics and a video. Right now I’m using a pololu a * 3 to you four and a mpu6050 to try and accomplish what I need to do. I also have a maestro mini 6 channel servo controller I can use as well. Please advise. I got everything ready I just need to code knocked out


I need some help regarding the code for my 32u4 astar microcontroller. I currently have it running a continuous rotation servo where the servo is supposed to follow the movement of my mpu6050 gyro accelerometer. So the mpu6050 rotates 360 degrees continuously and the servo is supposed to follow it accordingly , degree by degree. However, consequently, what it does is it will follow the movement of the gyro all the way up to 180 degrees, then it reverses its direction and goes back 180 degrees to complete the 360 degrees movement. What I needed to do is I need the servo to continue to follow the gyro all the way through the 180 degree mark up to the 360 degree Mark and continue to do so. Can anyone help me out? thanks in advance

Mpu6050 and 360 servo code issues

You will need a shaft encoder in order to make use of a continuous rotation servo, as there is otherwise no way to know how the servo shaft is positioned.

Since you will need an encoder, I would recommend to use a step motor or brushed DC motor instead of a continuous rotation servo, as you will have better control.


Yes, that is an option I suppose. However, I have seen numerous videos on YouTube of guys that have built self-balancing robots that just use modified 180-degree servos. None of them used encoders.


What is a “modified 180-degree servo”?

As you can quite easily verify, you have no control over the shaft angle of a continuous rotation servo, without using some sort of angular position feedback.

But is that not what you meant with this comment? “Fehler1977, post:12, topic:16271”: the servos are continuously rotating servos, and I don’t believe that they can accept angle input data.


@Fehler1977 I am not entirely sure about this, but it sounds like you might not be expecting the right kind of behavior from a standard servo modified for continuous operation. If you modify a standard servo for continuous rotation by removing its physical end stops and disconnecting its feedback potentiometer, you will lose the ability to control the position of the servo output (though the output will now be able to rotate 360 degrees). Just like when controlling a continuous rotation servo, modifying the pulse width of a hobby RC signal will allow you to control the speed of the output of the modified standard servo (and that servo will not have any way to tell how far it has rotated since its feedback potentiometer has been disconnected).

However, the behavior you’re describing sounds more like what I might expect from a 360 degree servo (like a sail winch servo), which does not do continuous rotation. Can you send a link to a datasheet or product page for the servo you are using?