Pages: [1]   Go Down
Author Topic: Servo ease in/ease out  (Read 1906 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone,

I'm totally new to microcontroller/physical computing stuff, but I like to say that the resources in arduino community help me a lot to catch up with my level 1 mathematic & coding skill.

I use servo library here to build a kind of automatic video pan&tilt for video camera, which I plan to apply later for my video art project.

The problem is the fast movement of the servo and the sudden stop somehow make camera shaking. So I was wondering is there any resource about ease in/ease out library to make servo slowly move then slowly stop.

Actually I did a bit of research and found this site, which look really useful, specially 'Simple cosine equation does ease in and ease out'
http://this.is/torfi/robotblog/index.php?getInfo=1&projectID=34

however, my programming skill is not good enough to realise it.

Can anyone give me a guide on how to apply this concept into coding?
Or is it possible to make a kind of ease in/out as a kind of function in a servo library somehow?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First thing that came in my mind was that you could move servos in small steps and put some delay between the steps?
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The subject of smooth motion control came up in this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1199497432
You may want to follow up with the poster, roypardi, I think he has been looking closely at ways smoothing mechanical movement.
« Last Edit: January 07, 2008, 01:28:07 pm by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

well...
here is my level 1 coding skill attempt, its work. but I'm sure it must be a better way, so I share here incase someone want to improve or fix it, make library, add more complex interpolation for instance smiley-razz

#include <Servo.h>  
  
Servo myservo;
float timeAngle;
float timeAngleadjust;
float moveAngle;            
int oldposition;
float servocon;
float sfactor;


// servo_smoothmove by witpim. 2007

void smoothmove(int cposition) {
  int anglediff = abs(cposition-oldposition);
  sfactor = servocon/anglediff;
  for (timeAngle=0.000; timeAngle<=1;) {
    timeAngle = timeAngle+sfactor;
    timeAngleadjust = (1.0/2.0) - (1.0/2.0*cos(timeAngle*PI));  //coming from here http://this.is/torfi/robotblog/index.php?getInfo=1&projectID=34
    moveAngle = (anglediff*timeAngleadjust);
    int calangle;
    if (oldposition > cposition) {
      calangle =  oldposition - (int)moveAngle;
    }
    if (oldposition < cposition) {
      calangle =  oldposition + (int)moveAngle ;
    }
    
    myservo.write(calangle);
    myservo.refresh();
  }
  oldposition = cposition;
}


void setup() {
    Serial.begin(19200);
    servocon = 0.05;   // servo factor, the higher the faster
    myservo.attach(2);  // attaches a servo connected to pin 2
}
void loop() {
  smoothmove(60);
  smoothmove(120);
  smoothmove(180);
  smoothmove(0);
  smoothmove(0);
  smoothmove(180);
  smoothmove(0);
  smoothmove(60);
  smoothmove(120);
  smoothmove(180);
  smoothmove(0);
}


Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't think that code is implementing the algorithm in the link you posted. I  may be wrong, but it looks like you are calculating small movement steps by a values that vary by the cosines of all angles between 0 and 1 radian. I think what is wanted is to calculate the movement of each step by the cosine of the current angle. I think the fragment below  is closer but its off the top of my head, I have not compiled or run it so probably needs some work but I hope it gets you closer.

It's a fragment, you need to add the macros for converting radians to degrees and back again. It also needs the logic to cope with decreasing angles.  

Code:
#define FRAME_RATE          20    // milliseconds per frame
#define SERVO_SPEED        100   // this the time in ms to move 60 degrees
           // adjust this for the specs of your servos

#define MAX_STEP_PER_FRAME  (60 / (SERVO_SPEED/ FRAME_RATE))  // max degrees servo can move in one frame

void smoothmove(int cposition, int oldposition) {
    int moveAngle;

    while(cposition != oldposition) {

      moveAngle = oldposition + MAX_STEP_PER_FRAME; //this is the raw uneased value
      if( moveAngle > cposition)
          moveAngle = cposition;

      // code needed using similar logic for cposition < oldposition

      oldposition += Rad2Angle( 0.5 - 0.5 * cos(Angle2Rad(moveAngle) * PI) );
      myservo.write(oldposition);
      myservos.refresh();
    }
}
« Last Edit: January 08, 2008, 08:15:37 am by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, Im new here but Ive been using the Arduino for a year or so.
...Im still a total newb

Was wondering if there had been any developments on this topic. I see the last post is a couple of years old but there is little else I can find on the net (besides the roypardi link above ) and assumed it would be a common query.
Looking for a simple way to ease a servo in and out, any suggestions would be appreciated.

Thanks
« Last Edit: August 04, 2010, 01:19:05 am by DCoy » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 36
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Did this problem ever get solved? I started playing around with Mem's code block but didn't get very far.

We're controlling a brush motor and need smooth starts and smooth stops.

(12v 100amp motor rotating the base of an art sculpture that will weight 2+ tons).

We're playing with the Servo library and it does move our 'lazy susan' table, but it  a) tries to get there as fast as possible. and b) comes to a dead stop when it does, which causes the entire sculpture to 'shake' violently. Not good!!  too much steel and weight involved for that... (we already have a 60:1 step down gear box inline)

Thus we need to very slowly start each move and very slowly stop each move to deal with the mass of the piece.

It seems like servo ramp acceleration/ramp deceleration is a common enough problem , but I've not found any sample code.
Logged

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8911
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The servo "sweep" demonstration sketch shows how to have a servo move at slower speeds by making incremental servo move spaced apart by a time delay. You could make the time delay longer as the desired position is being approached.
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Newbie
*
Karma: 0
Posts: 36
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

We're looking for something less 'linear' than the sweep demo.

We also have the problem that even with tiny moves, the 'hard' stop effect can be seen. We need something that smooths the power curve on start and stop even on the tinniest moves.

I guess we could build something with fractional degree moves and variable delays.

If we fix a move increment at say 1/8 degree, would the cosine math mentioned above be applied to the time? Another words, if we say we want to move 5 degrees in 5 seconds, would we set our writes at 1/8 degree fixed, but then varies the amount of time delayed by some sort of cosine equation ???

It's this calculation of the delay curve/profile that seems like a problem that's already been solved, but I've not found it yet.

Logged

Rural Arizona
Offline Offline
Edison Member
*
Karma: 7
Posts: 1711
Incorrigible tinkerer
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The problem is the fast movement of the servo and the sudden stop somehow make camera shaking.

Maybe not: people without experience tend to overestimate how strong and solid pan/tilt mounts are.  Even though I had some background in astronomy,  I couldn't believe the manufacturers' specs saying that mounts could only handle a payload of like a quarter their own weight.  But I could sure see it when I tried to exceed their ratings,  especially with long lenses.

Is your pan/tilt mount one you made yourself with one of those servo bracket kits?  If so,  the odds are very good that it's overloaded,  and no tinkering with algorithms will fix the problem.
Logged

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8911
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I guess we could build something with fractional degree moves and variable delays.

If you are using hobby grade servos, then it has been my experience that they are only capable of making descrete .5 deg moves at best. The arduino has the capability to send ~2000 discrete positions to the typical 180 deg rotation servo. There are new digital servos available that may better this. The question as to your pan/tilt construction and the size of the cam it is trying to move is very important. If you expect professional looking results, then you may need professional grade construction. Below are some servo based pan tilt units that might fit your needs.

http://www.servocity.com/html/pan_tilt_roll___accessories.html
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Newbie
*
Karma: 0
Posts: 36
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

We're using 1500 lb 18" industrial linear actuators and a rotational 'servo' of our own design which is a 12vDC 100 AMP motor with a 60:1 step-down gear box. (It is designed with POT feedback). The rotational one is a brush motor, so in theory, it's infinitely variable as it's just a mater of the precision of the feedback pot and the voltage we apply to the motor.

We're currently using RoboteQ AX2550 controllers, but after discussion with RoboteQ, we're upgrading to their newer controllers which is supposed to solve this problem, the HDC2400
Logged

0
Offline Offline
Tesla Member
***
Karma: 114
Posts: 8911
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
We're using 1500 lb 18" industrial linear actuators and a rotational 'servo' of our own design which is a 12vDC 100 AMP motor with a 60:1 step-down gear box. (It is designed with POT feedback). The rotational one is a brush motor, so in theory, it's infinitely variable as it's just a mater of the precision of the feedback pot and the voltage we apply to the motor.

Well, I think that may explain the lack of precision of movement. It is hard to turn a bulldozer into a ballet dancer. Below is my 2000lb 150a "big" servo project.


Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

0
Offline Offline
Newbie
*
Karma: 0
Posts: 36
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

True enough!

That said, we know the table can rotate smoothly with our set up when we use a variac to manually control the voltage going to the unit. Works like a charm, nice smooth moves, no crazy harsh stops.

We're just trying to get that type of functionality replicated from our micro processor.

Seem like the problem with a lot of RC controller is that they're not really designed to do this. Most servos are designed to make a full range motion in in fractions of a second and don't have huge loads on them... smiley

My understanding of the Servo library (which is limited) is that you tell it a position to send the servo to, but that's pretty much it. The Servo takes as long as it does go get from position A to Position B and you don't have much control over it's acceleration or deceleration profile.

It seems like a lot of the 'tricks' to ease in/ ease out are just dividing the move into smaller pieces and adding delays between them.

For example, going from 10 degree to 80 degrees might be broken up into 1 degree moves instead of just ending the command to move to 80, but you still don't have any control over the speed of each of your smallest increments.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 207
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You are right, Filmo.

The correct place to be changing the servo behaviour is within the servo.

Using the small step/delay method is clever and will get results that are good enough for many applications, but it is not the best way.

Industrial motor drives often have definable start and stop parameters for just this reason.

Regards,

Mike
Logged

Pages: [1]   Go Up
Jump to: