• Is there a way to know if a servo finished rotating?
16 replies, posted
Hello. I'm using a servo on Raspberry Pi using Phyton, connected to the GPIO pins. Just wondering, is there a way to return/know if the servo has finished rotating, after we sent the command to set its dutycycle? Right now, I set a function to calculate the time required to let the program sleep for that specified time, in order to let the servo finish rotating at various angle. But later, I planed to modify the speed of the servo rotation by alternating rotating the servos and resting it. It'll be very difficult to estimate the time required. How to know what angle is the servo rotation currently at? I need to know in order to stop sending command to the servo after it reach the desired angle. If possible, I don't want to calculate the times, because each servos speed will be different from each other, so its hard to make estimation for each one. Is there a direct way to return the current angle/rotation a servo is at? Thanks. Any hints are appreciated
What are you making? There are a number of things you can do but it depends on what your trying to make
I'm trying to control multiple servos, trying to make a robot leg. I can't put gyroscopes on each legs to measure the angle... I'm trying not to calculate the required time to rotate either, I thought it would be rather unpredictable Any other methods? [editline]13th February 2018[/editline] Wait, I got another idea. What if we calclulate the 'approximate' time the servo would take, and rotate the servo by alternating the pulse manually (to control rotation speed) for that duration (this step is done to adjust servo rotation speed) Then, after that approximated time, we rotate the servo at its default speed to an angle. That would make the servo rotate to our intended angle accurately, because I can make a function to convert dutycycle to angle. Although the speed will be different, but its just for a fraction of a second at the end, so it wouldnt be noticeable. This way most of the rotation speed will be the 'adjusted' speed, and only at the end will the servo original speed will take over at a fraction of the total movement duration, for correcting the final servo rotation to our intended angle. So, I dont even have to know the angle of the servo anymore, because I know that at the end, the servo WILL reach our intended angle, all that while most of the duration it'll be rotating at an adjusted speed, at least at like 3/4 of the the duration. Is this seems doable to you guys?
well if theres no power going to the servo then that is a pretty good indicator
Do you know the details about the servo motors? I feel like an actual servo motor should have positioning built in
Its just TowerPro 9g. I took a look at PiGPIO and Servoblaster library. But no servo position. Probbaly I missed something
A quick search says it operates at 0.1sec/60degree You should do some tests to see how accurate that is for you [editline]13th February 2018[/editline] [url]http://www.towerpro.com.tw/product/sg90-7/[/url]
Tried it, Its quite fast, will appear quite inhuman for a robot leg. Probably will knock off the body out of balance. Will try to slow down the rotation this weekend.
There's no direct way for you to know when when the servo has reached its position or is still moving towards it. From what I remembered working with these kind of microservos, you do not need to "constantly update" the duty cycle. You simply set the PWM to its corresponding degree when you want to move it, and the servo will stop advancing further automatically once the position has reached. The PWM directly translates to a position of the servo, not how much to move it by.
[QUOTE=B!N4RY;53130382]There's no direct way for you to know when when the servo has reached its position or is still moving towards it. From what I remembered working with these kind of microservos, you do not need to "constantly update" the duty cycle. You simply set the PWM to its corresponding degree when you want to move it, and the servo will stop advancing further automatically once the position has reached. The PWM directly translates to a position of the servo, not how much to move it by.[/QUOTE] Yeah, but then I can't control the speed of the servo rotation, if I just tell the servo to rotate all the way to the final target angle (because servos will use its maximum speed by default). So to control the speed, I wanted to rapidly switch servo rotation on/off, and by increasing the time its off, the overall rotation will be slower. But you're right, I dont need to return the current angle value. It turns out I will always know the current angle value, because I will increment the angle little by little (using the rapid on/off switching) anyway. I can keep track of the angle because I will add on miniscule target angle each time the servo switched on/off, and the current angle is always known and stored in a variable. I just need to stop moving the servo when that variable reach the final target angle. Can't wait to test this
You can use a potentiometer installed along the same axis as the servo, connected to both of the moving parts so that rotating the servo will also turn the potentiometer, which you can connect to some analog/digital converter and read the angle/value of of that
[QUOTE=hakimhakim;53130772]Yeah, but then I can't control the speed of the servo rotation, if I just tell the servo to rotate all the way to the final target angle (because servos will use its maximum speed by default). So to control the speed, I wanted to rapidly switch servo rotation on/off, and by increasing the time its off, the overall rotation will be slower. But you're right, I dont need to return the current angle value. It turns out I will always know the current angle value, because I will increment the angle little by little (using the rapid on/off switching) anyway. I can keep track of the angle because I will add on miniscule target angle each time the servo switched on/off, and the current angle is always known and stored in a variable. I just need to stop moving the servo when that variable reach the final target angle. Can't wait to test this[/QUOTE] but if you're making a bipedal robot you need to be holding a position the moment you stop pulsing it'll start sagging until it falls over
I'll try to see if the servo can hold its position based on its internal friction alone during off state. If it cant, I'll make some stepping forward/backward/side movement when the gyroscope value tips on a side. I'll still make it either way because the goal is for the leg to balance its feet if it tips forward/backward/sideways. Just an idea, still need to test
[QUOTE=hakimhakim;53130772]Yeah, but then I can't [B]control the speed of the servo rotation[/B], if I just tell the servo to rotate all the way to the final target angle (because servos will use its maximum speed by default). So to control the speed, I wanted to rapidly switch servo rotation on/off, and by increasing the time its off, the overall rotation will be slower.[/QUOTE] Then just change the pwm in small increments Eg: setpwm(50); sleep(10); setpwm(60); sleep(10); setpwm(70) rather than jumping to 70 right away from 50 You can just make the movement faster or slower by adjusting the amount of sleep between each increment I feel like you're thinking way too hard over a simple problem. There is no complicated physics or feedback system needed
[QUOTE=hakimhakim;53132475]I'll try to see if the servo can hold its position based on its internal friction alone during off state. If it cant, I'll make some stepping forward/backward/side movement when the gyroscope value tips on a side. I'll still make it either way because the goal is for the leg to balance its feet if it tips forward/backward/sideways. Just an idea, still need to test[/QUOTE] just wait till u come across control loops
Isn't the definition of a servo that it has an absolute position encoder in it? Without the encoder it would just be a Stepper motor. At least that's how it works in engineering grade servos. Servos for RC cars etc might work differently but I would still check in the documentation if it's possible to extract the exact position from some Servos.
[QUOTE=B!N4RY;53132596]Then just change the pwm in small increments Eg: setpwm(50); sleep(10); setpwm(60); sleep(10); setpwm(70) rather than jumping to 70 right away from 50 You can just make the movement faster or slower by adjusting the amount of sleep between each increment I feel like you're thinking way too hard over a simple problem. There is no complicated physics or feedback system needed[/QUOTE] Initially I thought it would be slightly easy if we can return the current angle, because i dont have to store the current angle value, so I just wanted to make sure if I missed a way to do that. I read some Adafruit thingy saying that there is a potentiometet built into servos, but havent found anybody discussing about returning the angle value. But I guess I'll just do it the usual way. Thanks