0

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

RowanP
  • 869
  • 6
  • 21
user61616
  • 1
  • 1

1 Answers1

2

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.

Peter Paul Kiefer
  • 1,893
  • 9
  • 11