Ramp up'/Soft start from power up

I am using the ‘VarSpeedServo’ library, which is fantastic and I believe was contributed by ‘Korman’.

My question; is there a way to soft start the servos, i,e, get them to move to their start position from power up without jumping at full speed?

Can it be done through the Arduino or can it be done with electronics?

#include <VarSpeedServo.h>

const int mainPin1 = 3;
const int mainPin2 = 5;
const int mainPin3 = 10;
const int mainPin4 = 11;
const int ServoMin = 850; // Minimum pulse width for servos in ms.
const int ServoMax = 2100; // Maximum pulse width for servos in ms.

int buttonPin = 13;
int buttonState = 1;

VarSpeedServo ServoHighHandRotate;
VarSpeedServo ServoHighHandTip;
VarSpeedServo ServoLowHandRotate;
VarSpeedServo ServoLowHandTip;

//*****************************************************************

void setup() {

pinMode(buttonPin, INPUT);
ServoHighHandRotate.attach (mainPin1, ServoMin, ServoMax);
ServoHighHandTip.attach (mainPin2, ServoMin, ServoMax);
ServoLowHandRotate.attach (mainPin3, ServoMin, ServoMax);
ServoLowHandTip.attach (mainPin4, ServoMin, ServoMax);
}

//*****************************************************************

//Left Hand (High Hand) rotate clockwise (180)
//Left Hand (High Hand) rotate anti-clockwise (0)
//Left Hand (High Hand) tip forwards (180)
//Left Hand (High Hand) tip backwards (0)

//Right Hand (High Hand) rotate clockwise (180)
//Right Hand (High Hand) rotate anti-clockwise (0)
//Right Hand (High Hand) tip forwards (0)
//Right Hand (High Hand) tip backwards (180)

//*****************************************************************

void loop() {

//buttonState = digitalRead(buttonPin);
//if (buttonState == HIGH)
{
ServoHighHandRotate.slowmove (90, 20); //All Hands move to centre
ServoHighHandTip.slowmove (90, 20); //All Hands move to centre
ServoLowHandRotate.slowmove (90, 20); //All Hands move to centre
ServoLowHandTip.slowmove (90, 20); //All Hands move to centre
delay(4000);

{
ServoHighHandRotate.slowmove (180, 20); //Left hand Rotate clockwise
ServoLowHandRotate.slowmove (180, 20); //Right hand Rotate clockwise
delay(3000);

{
ServoHighHandTip.slowmove (0, 20); //Left hand Tip backward
ServoLowHandTip.slowmove (180, 20); //Right hand Tip backward
delay(1500);

{
ServoHighHandTip.slowmove (180, 20); //Left hand Tip forward
ServoLowHandTip.slowmove (0, 20); //Right hand Tip forward
delay(2500);

{
ServoHighHandTip.slowmove (90, 20); //Left hand backward to centre
ServoLowHandTip.slowmove (90, 20); //Right hand backward to centre
delay(1500);

{
ServoHighHandRotate.slowmove (0, 20); //Left hand Rotate anti-clockwise
ServoLowHandRotate.slowmove (0, 20); //Right hand Rotate anti-clockwise
delay(5000);

{
ServoHighHandRotate.slowmove (90, 20); //Left hand Rotate clockwise to centre
ServoLowHandRotate.slowmove (90, 20); //Right hand Rotate clockwise to centre
delay(3000);

{
ServoHighHandTip.slowmove (0, 20); //Left hand Tip backward
ServoLowHandTip.slowmove (180, 20); //Right hand Tip backward
delay(1500);

{
ServoHighHandTip.slowmove (180, 20); //Left hand Tip forward
ServoLowHandTip.slowmove (0, 20); //Right hand Tip forward
delay(2500);

{
ServoHighHandTip.slowmove (90, 20); //Left hand Tip backward to centre
ServoLowHandTip.slowmove (90, 20); //Right hand Tip backward to centre
delay(1500);

//--------Start of Combined Movements--------------------

{
ServoHighHandRotate.slowmove (180, 20); //Left hand Rotates clockwise
ServoLowHandRotate.slowmove (0, 20); //Right hand Rotates anti-clockwise
delay(3000);

{
ServoHighHandRotate.slowmove (0, 20); //Left hand Rotates anti-clockwise
ServoLowHandRotate.slowmove (180, 20); //Right hand Rotates clockwise
delay(1500);

{
ServoHighHandTip.slowmove (0, 20); //Left hand Tip backward
ServoLowHandTip.slowmove (180, 20); //Right hand Tip backward
delay(1500);

{
ServoHighHandTip.slowmove (180, 20); //Left hand Tip forward
ServoLowHandTip.slowmove (0, 20); //Right hand Tip forward
delay(2500);

{
ServoHighHandTip.slowmove (90, 20); //Left hand Tip backward to centre
ServoLowHandTip.slowmove (90, 20); //Right hand Tip backward to centre
delay(1500);

{
ServoHighHandRotate.slowmove (180, 20); //Left Hand Rotate clockwise
ServoLowHandRotate.slowmove (0, 20); //Right Hand Rotate anti-clockwise
delay(1000);

{
ServoHighHandTip.slowmove (0, 20); //Left hand Tip backward
ServoLowHandTip.slowmove (180, 20); //Right hand Tip backward
delay(1500);

{
ServoHighHandTip.slowmove (180, 20); //Left hand Tip forward
ServoLowHandTip.slowmove (0, 20); //Right hand Tip forward
delay(2500);

{
ServoHighHandTip.slowmove (90, 20); //Left hand Tip backward to centree
ServoLowHandTip.slowmove (90, 20); //Right hand Tip backward to centre
delay(1500);
{
ServoHighHandRotate.slowmove (90, 20); //Left Hand Rotate anti-clockwise to centre
ServoLowHandRotate.slowmove (90, 20); //Right Hand Rotate clockwise to centre
delay(1000);

}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}

Whoa, what's with all the {}s?

is there a way to soft start the servos, i,e, get them to move to their start position from power up without jumping at full speed?

Put some code in setup() that loops and moved the servos slowly to their positions.


Rob

For some reason I thought the {} were needed, but obviously not!

I'm a real beginner at all this as you can tell.

I'll try using code from the 'sweep' sketch example I found in the library. Would that, or something like it, be the way to go?

My question; is there a way to soft start the servos, i,e, get them to move to their start position from power up without jumping at full speed?

Not without additional hardware: when you attach the servos, they will immediately try to move at full speed to whatever position you're telling them to go to. You can vary this by setting the position before the attach, but the problem is that you likely don't know what position the servos are in when you power up. You can remedy this with encoders or as a workaround, you can always set the servo positions to known values on shutdown.

The adding code to the setup part of the sketch didn't work and I figured that it may need more hardware. Many thanks for the advice

The adding code to the setup part of the sketch didn't work

But what code did you add?

Wildbill is right though, you don't know the position when power is applied so any ramping scheme may still cause a sudden initial movement.


Rob

I tried a variation of what I already had and also something similar to the sweep command from the library. Both worked at the setup point but at 'power on' there was still a jump.

I guess I need something that will dial up the power to the servos or use an encoder. I think I'll leave it this time and look into it at a later date.

Thanks for the advice