Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 33

Thread: Controlling servo speed with Arduino

  1. #21
    Will YOU be ready when the zombies rise? x88x's Avatar
    Join Date
    Oct 2008
    Location
    MD, USA
    Posts
    6,334

    Default Re: Controlling servo speed with Arduino

    Even only moving 70 degrees, it should take it almost 6 minutes with a 5000ms delay...hmmm. You said it slowed it down a little...where did it slow down? If the actual movement isn't happening any slower, I would wonder if it's even entering the while loop. I know my teensy has a USB console output feature, does the arduino you're using have something similar? If we could get some debugging output from it in one way shape or form that would be very helpful in pinpointing the problem. My first thought is the value of 'val'. Of there's no debug console, maybe throw together a quick morse code number library (or maybe one exists already) and have an LED blink you the value?

    Ooh, one thing I just thought of..idk what the syntax requirements are in the arduino language, but I know some other languages can get really picky about it...try this for the while loop line instead, out of curiosity.
    Code:
    while(val < OFF_POSITION){
    That we enjoy great advantages from the inventions of others, we should be glad of an opportunity to serve others by any invention of ours, and this we should do freely and generously.
    --Benjamin Franklin
    TBCS 5TB Club :: coilgun :: bench PSU :: mightyMite :: Zeus :: E15 Magna EV

  2. #22
    Resident 100HP water-cannon operator SXRguyinMA's Avatar
    Join Date
    Jun 2008
    Location
    MA
    Posts
    5,865

    Default Re: Controlling servo speed with Arduino

    just throw those spaces in there? I'll try it when I go home for lunch in a few

    oh and those mouse glides came in today. thanks!

  3. #23
    Will YOU be ready when the zombies rise? x88x's Avatar
    Join Date
    Oct 2008
    Location
    MD, USA
    Posts
    6,334

    Default Re: Controlling servo speed with Arduino

    Yup, just add spaces. Most languages don't care, but sometimes you'll run into one that's just picky (BASH is horrible with the strictness of its syntax).

    Glad to hear the glides got there fine. They're a few days later than I intended, but I could not for the life of me find my stamps...and then they ended up being in the box with the envelopes...you know, so I wouldn't lose them?
    That we enjoy great advantages from the inventions of others, we should be glad of an opportunity to serve others by any invention of ours, and this we should do freely and generously.
    --Benjamin Franklin
    TBCS 5TB Club :: coilgun :: bench PSU :: mightyMite :: Zeus :: E15 Magna EV

  4. #24
    Resident 100HP water-cannon operator SXRguyinMA's Avatar
    Join Date
    Jun 2008
    Location
    MA
    Posts
    5,865

    Default Re: Controlling servo speed with Arduino

    I've done the same, I feel your pain lol

  5. #25
    Fox Furry crenn's Avatar
    Join Date
    Apr 2005
    Location
    In the shadows behind you
    Posts
    4,067

    Default Re: Controlling servo speed with Arduino

    I'll test the code on my arduino and see how I go.
    Antec Sonata II | Pioneer DVR-212
    Good news! You can follow my website or follow me on twitter!

  6. #26
    Resident 100HP water-cannon operator SXRguyinMA's Avatar
    Join Date
    Jun 2008
    Location
    MA
    Posts
    5,865

    Default Re: Controlling servo speed with Arduino

    from Arduino forums:

    Here's the VarSpeedServo library. It's a clone of the Servo Library with one additional function slowmove which is a replacement of write with an additional speed parameter.

    Speed=0: Write is used, full speed
    Speed=1: Slowest
    Speed=255: Fastest. With the servos I have, above 127 I couldn't see any difference to write because the mechanical speed was the limiting factor.

    Everything that works with Servo works with VarSpeedServo too. Important: Don't use Servo.h and VarSpeedServo.h at the same time, it will create conflicts.

    Example:
    Code:
    #include <VarSpeedServo.h>
    VarSpeedServo myServo;
    ...
    myServo.attach (mainPin, ServoMin, ServoMax);
    ...
    myServo.slowmove (newpos, speed);
    ...


    Let me know how it works out.

    Korman
    testing it now...

  7. #27
    Resident 100HP water-cannon operator SXRguyinMA's Avatar
    Join Date
    Jun 2008
    Location
    MA
    Posts
    5,865

    Default Re: Controlling servo speed with Arduino

    alright here's the current code:
    Code:
    // Controlling a servo position using a temperature sensor
    // by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>
    // edited 5-12-2010 by Will Lyon to include base setting for servo if voltage not detected on pin 7
    // edited again 7-4-2010 by crenn to simplify the code a little
    // edited yet again 7-5-2010 by crenn to add features
    // edited again 7-21-2010 by Will Lyon - recalibrated servo positions
    // edited again 10-15-2010 by crenn - slow down servo when computer is off
    // edited again 10-15-10 by Will Lyon, with new VarSpeedServo library to slow servo movement
    // VarSpeedServo library from Korman on Arduino.cc forums
    
    #include <VarSpeedServo.h>
    
    VarSpeedServo myservo;                      // create variable speed servo object to control a servo
    
    //Constants
    const unsigned char CONTROL = 5;            // digital pin used to detect if the system is on or off
    const unsigned char TEMP_SENSOR = 0;        // analog pin used to connect the temp sensor
    const unsigned char MAX_SAMPLES = 10;       // number of temp sensor samples to average
    const unsigned char OFF_POSITION = 180;     // position of servo when no voltage is detected on pin 5
    const unsigned char LOW_POSITION = 155;     // lowest servo position for lowest temp
    const unsigned char HIGH_POSITION = 120;    // highest servo position for highest temp
    
    //Main global varibles
    char trigger = 0;                           // varible used to store the control pin value
    unsigned int val = OFF_POSITION;            // variable to read the value from the analog pin
    
    unsigned int updateAvgtemp(){
      static int history[MAX_SAMPLES]={0};
      static unsigned char lastHist=0;
      static unsigned char numHist=0;
      unsigned int temp=0;
      unsigned char counter=0;
      unsigned char arcount=0;
      history[lastHist] = analogRead(TEMP_SENSOR);
      if(numHist<MAX_SAMPLES)
        ++numHist;
      arcount=lastHist;
      ++lastHist;
      if(lastHist>=MAX_SAMPLES)
        lastHist=0;
      temp=0;
      counter=0;
      do{
        temp+=history[arcount];
        arcount--;
        if(arcount>MAX_SAMPLES)
          arcount=(MAX_SAMPLES-1);
        counter++;
      }while(counter < numHist);
      return (temp/numHist);
    }
    
    void setup()
    {
      pinMode (CONTROL, INPUT);                                // sets the control pin to input
      myservo.attach(9, HIGH_POSITION, LOW_POSITION);          // attaches the servo on pin 9 to the servo object
      digitalWrite(CONTROL, LOW);                              // ensure internal pullup resistor is disabled.
    }
    void loop()
    {
      trigger = digitalRead(CONTROL);                          // read input of pin CONTROL  and store it
      if (trigger == HIGH){	                                   // reads if pin CONTROL, if true, do this:
        val = updateAvgtemp();                                 // read the value of the temp sensor (value with range of 1024)
        val = map(val, 350, 700, LOW_POSITION, HIGH_POSITION); // scale it to use it with the servo (value between 160 and 120)
        myservo.slowmove(val, 255);                            // sets the servo position according to the scaled value
      }
      else {
        while(val<OFF_POSITION){
          val++;
          myservo.slowmove(val, 255);
          delay(100);
        }
        myservo.slowmove(OFF_POSITION, 1);         // sets servo position to 180 if above statment is false, at slowest speed
      }
      delay(125);                                  // wait 25ms for the servo to move to it's new position and also 100ms until it gets the new value
    }
    it works great, I just need to lube my hinges etc, they're a little sticky.

    I also had to change the high position to 120 from 90, otherwise it wanted to open the vents too far and actually popped the pins out of the first 2 flaps lol.

    I'll see tomorrow morning (when the room and computer have cooled off) about the general operation, but it definitely closes slower!

  8. #28
    Resident 100HP water-cannon operator SXRguyinMA's Avatar
    Join Date
    Jun 2008
    Location
    MA
    Posts
    5,865

    Default Re: Controlling servo speed with Arduino

    alright so after some recalibration (still not sure why it was needed)

    this:
    Code:
    const unsigned char OFF_POSITION = 180;     // position of servo when no voltage is detected on pin 5
    const unsigned char LOW_POSITION = 155;     // servo position for lowest temp
    const unsigned char HIGH_POSITION = 120;    // servo position for highest temp
    is now this:
    Code:
    const unsigned char OFF_POSITION = 180;     // position of servo when no voltage is detected on pin 5
    const unsigned char LOW_POSITION = 160;     // servo position for lowest temp
    const unsigned char HIGH_POSITION = 135;    // servo position for highest temp
    but originally (before the "VarSpeedServo" library) it was this:

    Code:
    const unsigned char OFF_POSITION = 180;     // position of servo when no voltage is detected on pin 5
    const unsigned char LOW_POSITION = 160;     // servo position for lowest temp
    const unsigned char HIGH_POSITION = 90;     // servo position for highest temp

  9. #29
    Fox Furry crenn's Avatar
    Join Date
    Apr 2005
    Location
    In the shadows behind you
    Posts
    4,067

    Default Re: Controlling servo speed with Arduino

    Because you're changing the length of the pulses.

    Change:
    Code:
    myservo.attach(9, HIGH_POSITION, LOW_POSITION);
    to this:
    Code:
    myservo.attach(9);
    Antec Sonata II | Pioneer DVR-212
    Good news! You can follow my website or follow me on twitter!

  10. #30
    baaah. billygoat333's Avatar
    Join Date
    Aug 2007
    Location
    Idaho
    Posts
    3,331

    Default Re: Controlling servo speed with Arduino

    I can has new video?
    Quote Originally Posted by Omega
    ber is id elicous
    Centurion 5 Mod <<--- ON HOLD FOR THE WINTER

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •