Pages: [1]   Go Down
Author Topic: arduino mega + 2x SM-s4303R Servos problem  (Read 2615 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all,
       I am trying to develop a simple spider robot as mentioned in the post http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1294651977. I have an arduino mega 2560 and two  SM-S4303R Servos 360 degree rotation servos. I want the servos to move 90 degrees forward (i.e. to 180 degrees) and 90 degrees back (i.e 0 degrees). I have adjusted and tested the neutral for both servos it 90. My problem is the servos move correctly for about 5 to 8 iterations over the loop but then just start moving in one direction and not going opposite (to move back).I am testing the code by powering the servos through the arduino 5V supply. My test code is as follows. As per the documentation of the servos they require 0.16 secs at 5V (actully 4.8V) to turn 60 degrees so my delay calculations are (0.16/60) * 1000 * 90 = 240 (mil seconds).

Code:
#include <Servo.h>

#define SF 180
#define SN 90
#define SB 0

Servo rightLeg;
Servo leftLeg;
unsigned long SDLY;
 
void setup()
{
  Serial.begin(9600);
  SDLY = (SF-SN) * ((0.16/60)*1000);
  rightLeg.attach(10);
  leftLeg.attach(3);
  //Center Serovos to Normal
  rightLeg.write(SN);
  leftLeg.write(SN);
}
 
 
void loop()
{
  moveFront();
  moveRight();
  moveLeft();
  delay(SDLY);
}

void moveFront(){
  rightLeg.write(SN);
  leftLeg.write(SN);
  delay(SDLY);
  Serial.println("Right leg Forward");
  rightLeg.write(SF);
  Serial.println("Left leg Forward");
  leftLeg.write(SF);
  delay(SDLY);
  rightLeg.write(SN);
  leftLeg.write(SN);
  delay(SDLY);
  Serial.println("Right leg Back");
  rightLeg.write(SB);
  Serial.println("Left leg Back");
  leftLeg.write(SB);
  delay(SDLY);
  rightLeg.write(SN);
  leftLeg.write(SN);
  delay(SDLY);
  Serial.println("Done Foward Movement");
}

void moveLeft(){
  Serial.println("Moving Left");
  rightLeg.write(SN);
  delay(SDLY);
  Serial.println("Left leg Forward");
  rightLeg.write(SF);
  delay(SDLY);
  rightLeg.write(SN);
  delay(SDLY);
  Serial.println("Left leg Back");
  rightLeg.write(SB);
  delay(SDLY);
  rightLeg.write(SN);
  delay(SDLY);
}

void moveRight(){
  Serial.println("Moving Right");
  leftLeg.write(SN);
  delay(SDLY);
  Serial.println("Right leg Forward");
  leftLeg.write(SF);
  delay(SDLY);
  leftLeg.write(SN);
  delay(SDLY);
  Serial.println("Right leg Back");
  leftLeg.write(SB);
  delay(SDLY);
  leftLeg.write(SN);
  delay(SDLY);
}

Any help would be highly appreciated. Thanks in advance.
Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 331
Posts: 16464
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your servo is a modified servo (http://www.pololu.com/catalog/product/1248) and the modification results in it becoming a bidirectional variable speed motor, it really is no longer a servo, even though you control it with the servo library. It's best called a continous rotating servo not a 360 degree servo.

 Because of the modification you can no longer control where the servo will stop, just that you can make it stop. After a few control moves you will find that your modified servo will have no idea where it is in it's rotation. This modification is designed to use the servo as a direct drive wheel for moving about.

So there is a possiblity that this modified servo will not do what you want it to do. Can you explain what the servo is suppost to do in your project and maybe we can figure out something.

Lefty
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi i would like the servos to move the legs of the spider back and forth please see image link. In stationary mode the servos are at 90 degrees. When the spider moves one leg goes forward (180 from 90) and one leg goes backward (0 from 90) to create motion.

http://postimage.org/image/j7crzmjo/

Thanks
Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 331
Posts: 16464
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi i would like the servos to move the legs of the spider back and forth please see image link. In stationary mode the servos are at 90 degrees. When the spider moves one leg goes forward (180 from 90) and one leg goes backward (0 from 90) to create motion.

http://postimage.org/image/j7crzmjo/

Thanks

Then you have the wrong servos for that job. Your servos have been modified for continous rotation and because of that they are not now using their internal pot as a position feedback sensor and will not perform as you want. The ones you have are designed to continously rotate at a desired speed, in either direction, or stopped.

Your application requires standard unmodified servos.

Lefty

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much for your support and help. I guess I'll have to order new servos. I'll do that today. I am looking for a light weight project (0.25 kg approx) initially. When i get that working i would like to upgrade it to a new idea that would be around 2 kg (with all the battery , camera and other components). I would like to buy servos that can support that king of load in the future could you kindly recommend some.

Thanks for the urgent reply.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just had an idea, would it be possible to make the servo run in one  direction (for 240 mili sec required to move 90 degrees at 5 V) than halt it for some time and then move it in the other direction (for 240 mili secs again). This should produce the same results int theory respective of the degrees of rotation. Is this correct ?
Logged

Left Coast, CA (USA)
Online Online
Brattain Member
*****
Karma: 331
Posts: 16464
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just had an idea, would it be possible to make the servo run in one  direction (for 240 mili sec required to move 90 degrees at 5 V) than halt it for some time and then move it in the other direction (for 240 mili secs again). This should produce the same results int theory respective of the degrees of rotation. Is this correct ?

In theory it would. However you will find in time that the servo wheel will gradually drift it's orentation and you will not be able to keep the stop positions fixed to absolute positions.

Servo are available in all sizes, torque values, speeds, etc. Just stay away from servos that say modified or continuous rotation. Google has plenty of links to servo vendors.  http://www.hobbypartz.com/servos.html



Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the help. I just ordered two Micro Servo (SM-2309B) and two Micro Servo (SM-2309B). I'll try these.
Logged

Pages: [1]   Go Up
Jump to: