slow servo movement program

Hi

I am new to Arduino, and this is my first post here on the forum.
I built a small pan camera mount for a GoPro camera, which I want to use to shoot timelapse videos.
The camera can be programmed to shoot a picture every few seconds, all I want to do is to use the Arduino to move the camera with a servo very slow in a horizontal movement, to get a nice pan effect.

I use the “sweep” program from the example list, and just changed the delay.
The problem I have now is, that the servo waits for the delay which is set to pass, before it starts to do the first movement.
After that everything is fine …

How can I change the program to get the servo to start immediately to move, after the Arduino gets powered on?

Thank you for any help

Felix

forgot;
the program looks as follows:

void loop() 
{ 
  
  for(pos = 180; pos>=1; pos-=1)     
  {                                
    myservo.write(pos);              
    delay(20);                      
  } 
  for(pos = 0; pos < 180; pos += 1) 
  {                                 
    myservo.write(pos);              
    delay(8000);                      
  } 
}

The first for loop ends with the servo positioned at 0. The second for loop starts with positioning the servo at 0, and waiting 8 seconds to move it one degree.

Start the second loop at 1, not 0, to get the first move without waiting.

By the way, the servo position is not terribly accurate, and the actual start and end values may not be 0 and 180. You need to verify the limits of travel, especially when moving the camera, before committing to the limits you have.

@Flenders: Are you finding the movement smooth enough for your purposes or does the camera jerk from degree to degree?

@PaulS: what do i do if i need pointing accuracy? Do people put encoders on servo setups?

what do i do if i need pointing accuracy?

Don't use a low accuracy, cheap mechanism.

Do people put encoders on servo setups?

Servos already have position sensing capabilities. They are just not very accurate. Think about what a servo is really meant to control. Throttle, steering, flaps, etc. on RC vehicles. The positioning does not need to be very accurate.

For accuracy, you need something designed to be accurate, like a stepper motor with a rotary encoder.

For accuracy, you need something designed to be accurate, like a stepper motor with a rotary encoder.

presumably geared down a bunch so you get many many steps per output revolution. I'll have to look for something pre-assembled like a servo.

A solution probably depends on how much $$$ is to be invested in the project. If an inexpensive servo is desired, then one could purchase one and do some experimenting. A standard servo is capable of ~.5 deg resolution when not loaded. Servo city below has some servo based cam positioning equipment.

http://www.servocity.com/

Hi

I changed the value to 1 …

#include <Servo.h> 
 
Servo myservo;  

int pos = 0;   
 
void setup() 
{ 
  myservo.attach(9); 
} 
 
void loop() 
{ 
  
  for(pos = 180; pos>=1; pos-=1)     
  {                                
    myservo.write(pos);              
    delay(20);                      
  } 
  for(pos = 1; pos < 180; pos += 1) 
  {                                 
    myservo.write(pos);              
    delay(8000);                      
  } 
}

it drives now from whatever position it is in during start into “0” (like it should),
but then still waits until it starts to do the first movements …

@bill2009: yes, the movement of the servo is smooth enough. The camera is mounted with the GoPro holder directly on top of the servo, I don’t experience any unwanted movements.

it drives now from whatever position it is in during start into "0" (like it should), but then still waits until it starts to do the first movements

Maybe your servo can't resolve between zero and one "degree". You should do some experiments to find out where the servo starts to move. Maybe some simple debug prints?

Below is some servo test code you can use to determine the actual mechanical limits of your servo, which can differ from the general 0-180 positions.

// zoomkat 10-4-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// for IDE 0019 and later
// Powering a servo from the arduino usually DOES NOT WORK.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(2000); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-test-21"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(1);  
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    } 
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int n;
    char carray[6]; //converting string to number
    readString.toCharArray(carray, sizeof(carray));
    n = atoi(carray); 
    myservo.writeMicroseconds(n); // for microseconds
    //myservo.write(n); //for degees 0-180
    readString="";
  } 
}

zoomkat:
Below is some servo test code you can use to determine the actual mechanical limits of your servo, which can differ from the general 0-180 positions.

// zoomkat 10-4-10 serial servo test

// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// for IDE 0019 and later
// Powering a servo from the arduino usually DOES NOT WORK.

String readString;
#include <Servo.h>
Servo myservo;  // create servo object to control a servo

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(2000); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control
  Serial.println(“servo-test-21”); // so I can keep track of what is loaded
}

void loop() {

while (Serial.available()) {
    delay(1); 
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    }
  }

if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string
    int n;
    char carray[6]; //converting string to number
    readString.toCharArray(carray, sizeof(carray));
    n = atoi(carray);
    myservo.writeMicroseconds(n); // for microseconds
    //myservo.write(n); //for degees 0-180
    readString="";
  }
}

Is it safe to command the servo beyond its limits? I thought I had wrecked one by doing that.

Is it safe to command the servo beyond its limits? I thought I had wrecked one by doing that.

Well you can certainly stress it as there is a hard travel stop built into the gear train that determine the ends of travel, so having the motor reaching stall current up against a stop is not good for their health. However if not done continuously, but rather to just quickly test and determine what the exact two microsecond values are for full travel on a specific servo, it's kind of the only way to do it.

Lefty

Is it safe to command the servo beyond its limits? I thought I had wrecked one by doing that.

I think the smaller servos can strip their gears fairly easily. The servo usually vibrates and will get warm when it is against the hard stop, so close attention to the servo is needed when locating the stops.

zoomkat:

Is it safe to command the servo beyond its limits? I thought I had wrecked one by doing that.

I think the smaller servos can strip their gears fairly easily. The servo usually vibrates and will get warm when it is against the hard stop, so close attention to the servo is needed when locating the stops.

Yes, that is what I was trying to imply. It's too bad that most the servo manufactures fail to publish a few important specifications for their servos such as travel stop pulse values, maximum stall current draw and thus make working with their servos harder then it needs to be, and leaves the user with having to find these specifications empirically.

Lefty

It's too bad that most the servo manufactures fail to publish a few important specifications for their servos such as travel stop pulse values, maximum stall current draw and thus make working with their servos harder then it needs to be, and leaves the user with having to find these specifications empirically.

High end servos usually have better specs than the cheap servos. For a $10 servo I doubt the parts quality would allow very accurate specs. If somebody really needs to know specific specs of a cheap servo, it is very easy to purchase one an measure the various parameters.

zoomkat:

Is it safe to command the servo beyond its limits? I thought I had wrecked one by doing that.

I think the smaller servos can strip their gears fairly easily. The servo usually vibrates and will get warm when it is against the hard stop, so close attention to the servo is needed when locating the stops.

ah, thank you - my 1st servo was a little tiny guy and i wrecked it before i knew any better.

Yes, that is what I was trying to imply. It’s too bad that most the servo manufactures fail to publish a few important specifications for their servos such as travel stop pulse values, maximum stall current draw and thus make working with their servos harder then it needs to be, and leaves the user with having to find these specifications empirically.
Lefty

yes, I find that frustrating. I actually called hi-tec to ask about the limits of one servo and whether I could damage it by overrunning them. The tech seemed to know the product but he seemed surprisingly cavalier about the whole thing - i guess in normal RC use you only use 90 degrees of travel so that’s all people care about.

I see on the servo-city site that they sell specific servos as either 90, 180, or continuous.

I see on the servo-city site that they sell specific servos as either 90, 180, or continuous.

Just be cautious of those 'continous rotation' servos. The modifications performed on them make them no longer a servo (they morph into an Ex-servo) but rather it becomes a variable speed bidirectional geared motor. You lose all ablity to have it stop at a specific location.

Lefty

zoomkat: Below is some servo test code you can use to determine the actual mechanical limits of your servo, which can differ from the general 0-180 positions.

// zoomkat 10-4-10 serial servo test

belated thanks for the servo test code, i found it quite handy. the servos seem3 sort of foolishly non-standard and badly documented.

belated thanks for the servo test code, i found it quite handy. the servos seem3 sort of foolishly non-standard and badly documented.

Yes, but when you can get the small ones for $2 and larger ones for $5, one can make exceptions to the documentation quality.