Go Down

Topic: Sweeping servo program question (Read 1 time) previous topic - next topic



I am trying to write a program that will sweep a servo from 0 to 180 degrees. This is pretty basic but I am including a webcam that Is attached to the servo. I will be using the programmer IDE since it has an arduino library to do tracking. The video will be fed into my laptop where the programmer program will do object tracking and transmit the object location in terms of degerees to rotate the servo through serial to the arduino. I am just wondering how to i tell the arduino to stop  sweeping the servo and move X degrees from the CURRENT position. This is where my problem is seeing as in the servo library you give a 0-2400 signal to rotate the servo but I want to move a certain number from the current location in the sweep motion. Thanks for any help you can give.


This is where my problem is seeing as in the servo library you give a 0-2400 signal to rotate the servo

Not an accurate assumption. The servo library has a lower limit of ~500 unless you change it.
Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   8)


I'm sorry your right I forgot that. The servo I am using requires it between 600-2300. I just don't know how to tell the arduino to move the servo from the current position. For instance

Start sweep>>>if(Serialinput >1), stop sweep, serial.read >>>>>>>> take serial.read number and add it to the current servo position.>>>> Turn servo to that position


Typically, servos respond to values from ~500 to ~2500 to define speed and direction, for continuous rotation servos, and to values from 0 to 180 for standard servos.

If you want to position a servo to a specific position, you should use the angle value, and keep track of where you told the servo to go to. When you want to go 5 degrees in the positive direction, add 5 to the current position, and write a new value to the servo.

If instead you are told the new position, just go there.

Until we know something about what Serial.read() gets, any advice is really just blowing smoke.


Well what I plan to do is sweep the servo back and forth to search for red objects. The camera is connected to the sweep servo. So when the camera sees the object it will track the object using blob detection. It will find the centroid of the object and retrieve the pixel info (x-pixel,y-pixel). Knowing the pixels, total resolution, and camera view angle it will calculate the ammount of degrees it needs to turn to center the object in the frame. So serial.read() will retrieve the 2 angles (pan and tilt but i am simplifying just to understand how to do it) being passed from the programmer code. Since, the servo is in a sweep the angles it needs to turn are degrees from the current location. I am just not sure how to have the arduino stop the sweep and do something like this

panangle = serial.read()
panservo.write(current/last angle + panangle);

Just not sure how to get the current/last command angle to make it work. So far the only thing I have thought of is to step the servo through certain angles in the sweep like this (syntax may not be right just writing an example)

val = 0;
if (serial.read()<1)
val = val +10
else if (serial.read()!<1)
panangle = serial.read()
targetangle = val+panangle;

This just seems messy and I am hoping there is a better way.

Go Up