Go Down

Topic: Slowing down servos. How to write it into the program. (Read 1 time) previous topic - next topic

briggsy

Jan 30, 2013, 12:19 pm Last Edit: Jan 30, 2013, 12:23 pm by briggsy Reason: 1
Hi everyone,
                  I am very new to all of this and have been tinkering extensively for several days working on a program to change the position of a servo between 0, 45 and 90 degrees by using a digital input. No input = 0 degrees, a HIGH input on digital pin 3 moves the servo to 45 degress and a HIGH input on digital pin 4 moves the servo to 90 degrees. What I am now having trouble programming is how to slow the movement of the servo down. What I am trying to emulate is a old style of railway signal used in NSW Australia for many years known as an upper quadrant signal. See photo  http://www.flickr.com/photos/robertstrains/5767145547/ . They are driven off a motor that moves realatively slowly i nreal life and that is what I am trying to emulate. I have been using the sweep sketch in the examples as a reference but have come up trumps after reading all the posts forums and books I have acess to and searching you tube. There is obviously something I am missing. If you need to see the sketch I am happy to post it. But the notes are incomplete at this stage.

Thanks in advance,
Briggsy

AWOL

Write small angular increments to the Servo, with a delay between the writes.
Bonus marks for not using "delay()".

If you post your code, we can help you with it.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

briggsy

Here is the sketch.
Code: [Select]
//Upper Quadrant servo sketch 1
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
               
int yellowState;
int greenState;
   
// constants won't change. They're used here to
// set pin numbers:

const int yellowPin = 3;
const int greenPin = 4;

void setup()
{
 
// initialize the trigger pins as an input:
   
pinMode(yellowPin, INPUT);
pinMode(greenPin, INPUT);
myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop(){
// read the state of the trigger value:
yellowState = digitalRead(yellowPin);
greenState = digitalRead(greenPin);

  // check if either of the triggers are HIGH
  // if it is, the relavant State is HIGH:
                     
if (yellowState == HIGH) 
                                   
    myservo.write(45);     //sends servo to 45 degrees         
   
if (greenState == HIGH)

   myservo.write(90);      //sends servo to 90 degrees
   
if ((yellowState == LOW) && (greenState == LOW))
   myservo.write(0);



Thanks for taking the time to have a look. I worked out how to play with the delay in the sweep example but I could never get it to work in my sketch.

Briggsy

AWOL

As written, your servo will move as quickly as it can from one position to the next.
If, instead of a simple "servo.write (90);" you did something like (and I'm going to lose marks for this)
Code: [Select]
for (int angle = 0; angle < 90; angle+=10) {
  servo.write (angle);
  delay (50);
, your sweep will take longer.

Play with it, change the values, particularly the start, end and increment values (you don't want to go back to zero if you're already at 45 and moving to 90)
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

briggsy

AWOL,
         Thanks for the help but that has not appeared to have worked. I have tinkered gto the best of my knowledge. I there a way to just slow down the PWM change to the servo so that all of it's movements are slowed to the same rate? It just waved the servo about like a crazy thing.

Briggsy

Go Up