It is very simple device, 2 continuous servos FS5113R, rotates continuously in one direction. Here is device original content, which is this servo shield it looks like russian, and here is library, I have added to Arduino IDE, also I have original code, which runs this device, given below.
I'm trying to figure out, what can I do with speed, to run it slower, I've tried change delay(15); number to 1000, but it moves with same speed. I've tried increment variable in while (z < 2) loop
and pass it with interval, but speed is same:
#include <Wire.h>
#include <Multiservo.h>
#define SERVO_COUNT 2
Multiservo servo[SERVO_COUNT];
int pos1 = 0;
int pos2 = 0;
int z = 1;
void setup(void)
{
Wire.begin();
for (int i = 0; i < SERVO_COUNT; ++i)
{
servo[i].attach(i);
servo[i].write(0);
}
}
void loop(void)
{
while (z < 2){
pos1 + 1;
pos2 + 1;
servo[1].write(pos1);
servo[2].write(pos2);
delay(15);
}
}
Any advice, guide or example would be useful
1 Answer 1
The speed of your servo is controlled by the pulswidth of a square wave signal. According to the datascheet of the servo the motor stops on a pulsewith of about 1500 μSec (+- 5 μSec).
From 1500 to 900 μSec the motor turns clock wise. And it getting faster with decreasing pulsewidth.
From 1500 to 2100 μSec the motor turns counter clock wise. And it getting faster with increasing pulsewidth.
Next we have to check whether your shield and the library can handle that values and which value you have to give to the servo[i].write(?)
function. I can read cyrillic but I do not understand russian good enough to read the f. manual. So I have to look into the code on GitHub (https://github.com/amperka/Multiservo/blob/master/library/Multiservo ).
Et voila:
Multiservo::attach(int pin, int minPulse, int maxPulse)
You can define the min and max pulseWidth, that's great. Let's do it:
#include <Multiservo.h>
#define SERVO_COUNT 2
Multiservo servo[SERVO_COUNT];
// speed is 0 ( full speed CW )
int speed = 0;
void setup(void)
{
for (int i = 0; i < SERVO_COUNT; ++i)
{
servo[i].attach( i, 900, 2100);
// 900 - 2100 is mapped from 0 to 180
// so 90 is the middle where the motor stopps
// 180 the motor runs as fast as possible CCW
// 0 the motor runs as fast as possible CW
servo[i].write( speed );
}
}
void loop(void)
{
// Here I halt the program if the motor stops.
// If you use a lower value than 89 you can halt the program
// at the corresponding speed. If you use a higher value instead of 89
// the motor starts rotating counter clockwise.
// Do not use a value greater then 179 or less than 1.
if ( ++speed > 89 ) speed = 90;
servo[1].write( speed );
servo[2].write( speed );
delay(25);
}
Ah, of cause I have not hte hardware, so I can not test the program. Use it as an example.
-
Hello, thank you for your answer. As I've said I want change code for this device to make move both servos always in one direction with slower speed, but now I'm not able to check your example, because seems like this shield is damaged, besides, I don't understand russian either, so I've to change this device very soon and check upload with your code, then I will comment about result to mark you answeruser61616– user616162019年12月15日 04:27:19 +00:00Commented Dec 15, 2019 at 4:27
pos1
orpos2
, thus the speed doesn't change. Try doingpos1++;
instead ofpos1 + 1
pos1
andpos2
overflow. This would take 136h. Is this, what you are seeing? Since the servo cannot change direction very fast, that movement wouldn't be very strong, maybe just a long twitch at the start of the program