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

4
  • It is unclear what exactly you are trying to achieve. You never change pos1 or pos2, thus the speed doesn't change. Try doing pos1++; instead of pos1 + 1
    – chrisl
    Dec 14, 2019 at 16:45
  • @chrisl Hello, same behavior with pos1++, but I'm trying rotate motor slower, example above shows exist code, which runs servos with given speed
    – user61616
    Dec 14, 2019 at 16:52
  • If you use the above code with a continuous rotation servo, the servo will first rotate in one direction, getting slower (1.3 seconds duration), then changing rotation direction (as the value goes through 90), then getting faster for 1.3s and then keeping this speed, until pos1 and pos2 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
    – chrisl
    Dec 14, 2019 at 21:15
  • @chrisl I see movement of both motors always in one direction without changing direction as required, but too fast, code above is default for device. My goal is to make movement in one direction, but with a slower speed, same way as it is done, except for the behavior that you described, although I did not checked it for 136h
    – user61616
    Dec 15, 2019 at 4:20

1 Answer 1

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.

1
  • 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 answer
    – user61616
    Dec 15, 2019 at 4:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.