Control speed of a Parallax Feedback 360 Motor

QUESTION: When using a Parallax Feedback 360 servo with the appropriate control library ("FeedBackServo.h") Is the speed of the servo also adjustable?

PROBLEM: When I use the servo, it goes from "OFF" to 100% of it's rotational speed instantaneously. I'm trying to have the speed gradually increase upon starting, and also gradually decreasing in speed when it's coming to the end.

I've looked through the library but didn't find anything useful. However, I did note that the library also makes use of the "Servo.h" library - which I've previously used to control the speed of a different type of servo. Unfortunately, I don't know how to accomplish what I need using the two libraries. Would it be possible to combine these two sketches?

(Working sketch to control the Parallax Feedback 360 servo)

    #include <Wire.h>
    #include "FeedBackServo.h"

    #define FEEDBACK_PIN 2  //Servo1 - Define feedback signal pin (Yellow wire)
    #define SERVO_PIN 3  //Servo1 - Define control pin (White wire)

    FeedBackServo Servo1 = FeedBackServo(FEEDBACK_PIN);  //Servo1 - Set feedback signal pin number

    int Cycle = 0;  //Keeps count of which cycle its on


    void setup()
    {
      Serial.begin(115200);  //Baud rate

      Servo1.setServoControl(SERVO_PIN);  //Set servo control pin number
      Servo1.setKp(1.0);
    }

    void loop()
    {
      if (Cycle <= 9)
      {
        Serial.print("Cycle #");  //Print the cycle count to the serial monitor
        Serial.println(Cycle);

        //SERVO1 START POSITION
        Servo1.rotate(220, 3);  //Change "220" to whatever degree angle you want your starting angle to be. Change the "3" to how close you want the motor's angle to get before it stops. For example, (220, 3) = Starting angle is +-3 degrees of 220.

    Serial.print("Forward Angle: ");  //Serial print the angle that the motor stopped at after going forward
    Serial.println(Servo1.Angle());

    delay(5000);

    //SERVO1 END POSITION
    Servo1.rotate(325, 3);

    Serial.print("Backward Angle: ");  //Serial print the angle that the motor stopped at after going backward
    Serial.println(Servo1.Angle());
    Serial.println();

    delay(5000);

    Cycle = Cycle + 1;
  }
}

        Serial.print("Forward Angle: ");
        Serial.println(Servo1.Angle());

        delay(5000);

        //SERVO1 END POSITION
        Servo1.rotate(325, 3);

        Serial.print("Backward Angle: ");
        Serial.println(Servo1.Angle());
        Serial.println();

        delay(5000);

        Cycle = Cycle + 1;
      }
    }

(Working sketch to gradually increase/decrease the speed of a 180 degree servo)

    #include <Servo.h>

    Servo myservo;

    int pos = 0;


    //---------------


    void setup()
    {
      Serial.begin(115200);
      myservo.attach(9);
      myservo.write(0);
      delay(1000);
    }


    //---------------


    void loop()
    {
      delay(1000);
     
      for (pos = 0; pos <= 180; pos += 1)
      {
        myservo.write(pos);              // tell servo to go to position in variable 'pos'
      }

      delay (1000);

      for (pos = 180; pos >= 0; pos -= 1)
      {
        myservo.write(pos);              // tell servo to go to position in variable 'pos'
      }
    }
Servo1.rotate(325, 3);

What do these 2 parameters do ?

Sorry, I forgot to comment those lines...

"325" = the degree or angle in which the servo stops at.
"3" = +- 3 degrees or angle tolerance. For example; Servo1, stop at angle 325, +-3 degrees.

To move the servo slowly increase the target angle each time you call the function and wait a while before calling it again

Despite what you say that is not what the example code for the normal Servo library that you posted actually does because it does not wait between servo steps

1 Like

That's the problem, sir.
I understand what you're saying and it completely makes sense, I'm just at a loss as to how I can actually increase the value "220" that is formatted "(220, 3)". I know how to increase a regular value if it was just "220". Going to Google for a while... Thank you.

Take a look at this portion of the code that you posted

      for (pos = 0; pos <= 180; pos += 1)
      {
        myservo.write(pos);              // tell servo to go to position in variable 'pos'
      }

Note the use of the pos variable to provide a variable value to the write() function. Use that and perhaps 3 in the call to the rotate() function

1 Like

Haha, I literally just came across the same kind of solution on Google.

Going to try and implement it now and I'll report back.
Thank you!

pos++;
pos += 1;
pos = pos + 1;

All do the same thing

1 Like

pos = pos + 1;
I didn't know this one. That's new for me. Cool. I'll have to remember that one.

Really ?
That seems the most obvious one to me

It is the most obvious looking at all 3 examples, which is why I like it :slight_smile:

This sketch is working now - ish. It controls the Servo speed, but now it's jittery. (Start, stop, start, stop, looped very fast)
Going to keep playing around with it to see if I can get it to smooth out a bit more.

#include <Wire.h>
#include "FeedBackServo.h"

#define FEEDBACK_PIN 2  //Servo1 - Define feedback signal pin (Yellow wire)
#define SERVO_PIN 3  //Servo1 - Define control pin (White wire)

FeedBackServo Servo1 = FeedBackServo(FEEDBACK_PIN);  //Servo1 - Set feedback signal pin number

int Angle = 220;


void setup()
{
  Serial.begin(115200);

  Servo1.setServoControl(SERVO_PIN);  //Set servo control pin number
  Servo1.setKp(1.0);
}

void loop()
{
  for (Angle = 220; Angle <= 320; Angle++)
  {
    Servo1.rotate(Angle);
  }
}

Did you forget to wait a while between each servo movement and what about the second parameter to the rotate() function ?

It's almost like you know what you're doing @UKHeliBob :wink: You can see my rookie mistakes a mile away lol
Thank you, sir.

#include <Wire.h>
#include "FeedBackServo.h"

#define FEEDBACK_PIN 2 //Servo1 - Define feedback signal pin (Yellow wire)
#define SERVO_PIN 3 //Servo1 - Define control pin (White wire)

FeedBackServo Servo1 = FeedBackServo(FEEDBACK_PIN); //Servo1 - Set feedback signal pin number

int Angle = 220;

void setup()
{
Serial.begin(115200);

Servo1.setServoControl(SERVO_PIN); //Set servo control pin number
Servo1.setKp(1.0);
Servo1.rotate(220, 3);
}

void loop()
{
for (Angle = 220; Angle <= 320; Angle += 20)
{
Servo1.rotate(Angle, 3);
}
delay(250);
}

Auto Format the code in the IDE and post it here in code tags as recommended and it looks like this

#include <Wire.h>
#include "FeedBackServo.h"

#define FEEDBACK_PIN 2 //Servo1 - Define feedback signal pin (Yellow wire)
#define SERVO_PIN 3 //Servo1 - Define control pin (White wire)

FeedBackServo Servo1 = FeedBackServo(FEEDBACK_PIN); //Servo1 - Set feedback signal pin number

int Angle = 220;

void setup()
{
  Serial.begin(115200);
  Servo1.setServoControl(SERVO_PIN); //Set servo control pin number
  Servo1.setKp(1.0);
  Servo1.rotate(220, 3);
}

void loop()
{
  for (Angle = 220; Angle <= 320; Angle += 20)
  {
    Servo1.rotate(Angle, 3);
  }
  delay(250);
}

Where is the wait between servo moves ?
Why is Wire library #included ?

Didn't you say to wait a while in between each servo movement?
Was there a better way to accomplish this?

The Wire.h library is in there because I forgot to delete it. I was using it for the rest of the code which didn't pertain to the Servo1 movement. I wanted to omit any unnecessary parts as to not confuse the people trying to help me. My mistake.

I did, but the way that you have written it the servo moves from 220 to 320 (100 moves) then waits. You might just as well move to 320 directly and not bother with the for loop

What I had in mind is to move a small amount then wait a short time, move a small amount then wait a short time, and so on until you reach the final angle.

The topic title says that you want to control the speed of the servo but your code does not do that

for (Angle = 220; Angle <= 320; Angle += 20)

Doesn't the "Angle += 20" increase the angle by +20 every time through the loop until it reaches 320?

Oh wait, are you saying that by adding the delay (250) the servo is still accelerating from 0-100 but now just in many steps instead of one?

Yes it does, but the servo moves at full speed between each angle that you send to it so is moving at full speed all of the time. As an experiment put delay(50); after each call to rotate() and notice the difference

Damn.
You're correct @UKHeliBob.