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'
}
}
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
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.
It is the most obvious looking at all 3 examples, which is why I like it
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);
}
}
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
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