Shop OBEX P1 Docs P2 Docs Learn Events
Speed control of standard servo with BlocklyProp? — Parallax Forums

Speed control of standard servo with BlocklyProp?

I'm trying to familiarize myself with Blockly enough that I can help a group of students with it, so I used it last night to make a quick program for the ActivityBot roaming with a PING))) on a front servo bracket.

I can't seem to find a block that will allow me to control the speed that the standard servo sweeps the PING sensor back and forth. I can of course put a pause at the end of each arc, but that does nothing to slow the actual sweep movement in between 0 and 180 degrees. I'd like to slow it down a little so it gets a more accurate signal return.
Is there any way to implement speed control of a servo in Blockly? Or would I have to slow it down by decreasing the voltage to the servo?
Thanks!

Comments

  • JonnyMacJonnyMac Posts: 9,102
    edited 2017-10-25 22:24
    Looking "under the hood," the servo library has a function called servo_setramp() which allows you to specify the number of microseconds change per 20ms servo refresh window. This seems to be implemented in the CR Servo set ramp block. I am on the road and do not have a servo with me to try.

    Don't reduce the voltage to your servo. Speed control has to do with pulses sent to it.
  • DrPopDrPop Posts: 227
    edited 2017-10-27 06:02
    Hi Jon, thanks for taking the time to answer while on the road! Editing this to let you know it works. Not perfectly, but well enough for what I wanted it to do. It introduces an interesting quirk where the servo doesn't want to go through the full sweep from the first specified angle to the second one, but just pivots back and forth a few degrees slowly. However, I was able to play with the pauses at each end and by reducing the angle of sweep a bit, it works fairly well.
  • DrPop, I'm going to ask Matt to monitor this thread. Servo control should be the easiest thing in Blockly - maybe the block doesn't self-describe itself or the documentation isn't clear. I'm not sure, but we'll give this a look and make sure it's a functional, self-documenting block.

    Ken Gracey
  • DrPop wrote: »
    Hi Jon, thanks for taking the time to answer while on the road! Editing this to let you know it works. Not perfectly, but well enough for what I wanted it to do. It introduces an interesting quirk where the servo doesn't want to go through the full sweep from the first specified angle to the second one, but just pivots back and forth a few degrees slowly. However, I was able to play with the pauses at each end and by reducing the angle of sweep a bit, it works fairly well.

    You have to allow the servo to reach the commanded angle before sending a command to go to a new angle. That will depend on the ramp function and the distance to be traveled to each angle. You might be able to determine this with math or even have the program figure it out, but trial and error can work as long as you realize the slower you make the motion, the longer the pause is required before the next angle command.

    When using ping)) to measure distances to objects in a sweep (in a SimpleIDE program), I eventually chose to rotate the servo a couple of degrees, pause enough to let it get there, take a ping reading, (maybe I added another pause to make sure i accounted for the ping time delay -- not sure now) then rotate a couple more degrees, etc. One advantage was I was able to clearly correlate the angle with the distance measurement. If you try to collect ping data while the servo is rotating there will be some error.

    Tom
  • That explains the results perfectly. My original code didn't allow a long enough pause for the servo to reach X angle before telling it to travel to Y angle, so when I increased the pause times, it worked better. I'll have to fine tune it now that I know what's actually going on, and maybe play with stopping the motion altogether like you did at certain points if that works better.
    The standard servo speed as it is in the PING))) bracket kit seems a little fast to get an accurate reading as the bot is cruising around.
  • I'm pretty sure that it is possible to get smooth appearing motion using the rotate a little/pause/read ping/rotate... method. (Its been a while since I had done that.)

    Tom
  • DrPopDrPop Posts: 227
    edited 2017-10-28 21:08
    Thanks to all for the suggestions. The CR servo set ramp works great on the standard servo now that I have the correct pause times. A ramp speed of about 20 appears like slowed continuous motion with a 500 millisecond pause.
    I'm not sure if it's possible, but you might mention somewhere in the Servo help part of BlocklyProp that the CR Servo set ramp block works with a standard servo as well. (Unless that was already obvious to everyone but me.) If I had read that or known before hand, I might not have needed to waste everyone's time with this thread. ;)

    If anyone wants to share with their students, the simple navigating with slowed servo mounted Ping))) code is public here:
    http://blockly.parallax.com/blockly/projectlink?id=3606&key=833dd3bc-1381-4bcf-9385-1b05f9d042de
Sign In or Register to comment.