Acceleration and deceleration to control servo speed

Hi I’m making robotic arm using MG958 & MG995 servo’s these are high torque servo’s & controlling those servo manually using joystick to set servos position.

The Problem is when I move Joystick suppose at analog 800 then servo move at 120degree but the servo moves very quickly like instantaneous movement. I increase the delay time but this only changes the initial starting time of servo.

I want that my servo to accelerate at starting then run at constant speed then slow’s down at final position
Its robotic arm project so hope you understand my problem

How do I control servo’s smoothly or How do I make my speed curve smooth?

#include <VarSpeedServo.h>

//Joystick controlled robot
VarSpeedServo myServo1; 
VarSpeedServo myServo2; 
VarSpeedServo myServo3; 
VarSpeedServo myServo4; 
VarSpeedServo myServo5; 

int servo1 = 3;
int servo2 = 5;
int servo3 = 7;
int servo4 = 9;
int servo5 = 11;
int joyX = 0;
int joyY = 1;
int button1Pin = 2;
int press1 = 90;
int JoySlack = 25; // Dead spot size
int center = 519; // Reading when joystick centered


void setup() {
  Serial.begin(9600);
  myServo1.attach(servo1);
  myServo2.attach(servo2);
  myServo3.attach(servo3);
  myServo4.attach(servo4);
  myServo5.attach(servo5);
  pinMode(button1Pin, INPUT);
  digitalWrite(2, HIGH);
}

void loop() {
  Serial.print("X-axis: ");
  Serial.print(analogRead(joyX));
  Serial.print(" | ");
  Serial.print("Y-axis: ");
  Serial.print(analogRead(joyY));
  Serial.println(" | ");
  delay(200);
  press1 = digitalRead(button1Pin);
    if (press1 == LOW)
    {
      myServo5.write(0);
    }
    else {
      myServo5.write(180);
    }
  
  int valX = analogRead(joyX);
  int valY = analogRead(joyY);
  if ((abs(valX - center) > JoySlack) || (abs(valY - center) > JoySlack))
  {
    valX = map(valX, 50, 1023, 0, 180);
    valY = map(valY, 50, 1023, 0, 180);

    myServo1.write(valX);
    myServo2.write(valX);
    myServo3.write(valY);
    myServo4.write(valY);
  }
  else
  {
    myServo1.write(90);
    myServo2.write(90);
    myServo3.write(90);
    myServo4.write(90);
  }
  delay(500);
}

You have to move the servo in small
Amounts with a short delay between each movement towards your target position

I thought that the whole point of the VarSpeedServo library was that you could add a second parameter to the servo.write() to control the speed of the servo.

Do the library examples not show this ?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.