Society of Robots - Robot Forum

Software => Software => Topic started by: blackheart on April 21, 2009, 05:18:31 PM

Title: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on April 21, 2009, 05:18:31 PM
Hey! Working on my arduino rover bot, rv-1, I realised that my 4 HSR-1422CR servos and the SoftwareServo.h library are playing some kind of psychological warfare on me. It goes forward and it also goes backwards! It goes right but no matter what I do, I can't get it to go left using all 4 servos.

Here is the code.

Code: [Select]
#include <SoftwareServo.h>

SoftwareServo s1, s2, s3, s4, sa, sb;
int pin_s1, pin_s2, pin_s3, pin_s4, pin_sa, pin_sb;
int pin_ir1, pin_ir2, pin_ir3;
float read_cm(byte pin) {
int tmp;

tmp = analogRead(pin);
if (tmp < 3)
return -1; // invalid value

return (6787.0 /((float)tmp - 3.0)) - 4.0;
}

void drive_forward(void) {
  for(int i = 0; i < 5000; i++) {
  s1.write(180);
  s2.write(180);
  s3.write(0);
  s4.write(0);
  SoftwareServo::refresh();
  }
}

void drive_backwards(void) {
  for(int i = 0; i < 5000; i++) {
  s1.write(0);
  s2.write(0);
  s3.write(180);
  s4.write(180);
  SoftwareServo::refresh();
  }
}

void drive_left(void) {
  for(int i = 0; i < 5000; i++) {
  s1.write(180);
  s2.write(180);
  s3.write(180);
  s4.write(180);
  SoftwareServo::refresh();
  }
 
}

void drive_right(void) {
  for(int i = 0; i < 5000; i++) {
  s1.write(0);
  s2.write(0);
  s3.write(0);
  s4.write(0);
  SoftwareServo::refresh();
  }
}

void setup() {
  pin_s1 = 2;
  pin_s2 = 4;
  pin_s3 = 6;
  pin_s4 = 8;
  pin_sa = 10;
  pin_sb = 12;
  pin_ir1 = 0;
  pin_ir2 = 2;
  pin_ir3 = 4;
  s1.attach(pin_s1);
  s2.attach(pin_s2);
  s3.attach(pin_s3);
  s4.attach(pin_s4);
  sa.attach(pin_sa);
  sb.attach(pin_sb);
  digitalWrite(13, HIGH);
}

void loop() {
  drive_forward();
  drive_backwards();
  drive_left();
  drive_right();
}



When I turn on the bot, it goes forward, then it goes backwards, then it goes right. No matter what I do, I can't get it to go left. All 4 servos are working. Nothing's wrong with them. It bugs me because it only has a problem with the left side. if I call drive_left() by itself, it still goes right.


Please help.



Thank You!
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Dscrimager on April 21, 2009, 09:08:05 PM
If I remember correctly that means that the centering is not correct on one or more servo? I.e. the pot needs to be centered.
Do they all stop when you send a centering pulse? I had something like this once,..

Doug
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: SmAsH on April 21, 2009, 09:47:39 PM
for most servos (unmodified), if you send a 1.5ms pulse it will center 1.0ms pulse it will turn left and 2.0ms pulse will turn right.
@blackheart, are you sure you modified them properly? and have you tried switching the servos around. ie, taking the ight servo and placing it on the left side of the bot and visa versa..?
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on April 22, 2009, 01:34:14 AM
The servos are already modified by Hitec! I don't need to center them. I don't need any precise control on the position of the servos.

My problem is that the rover goes forward, goes backwards, goes right, but it doesn't go left. What am I doing wrong? It seems like everything is alright in the code, but if I call drive_left() or drive_right(), it still goes right and the functions are different!


Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Ro-Bot-X on April 22, 2009, 05:03:34 AM
Try using 1-179 instead of 0-180 as the range of speeds. Or make a function that will count down from 90 to 0 and see if the motors are going left. I think the 0 value is making them somehow jump to the other extreme and rotate in the oposite direction.
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Razor Concepts on April 22, 2009, 06:08:25 AM
I checked the softwareservo source code and if you enter in values under 0 or over 180 it just limits it to 0 and 180.
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on April 22, 2009, 06:21:06 AM
Ok, I could try that, but what I don't understand is the fact that it works with 0 and 180 when turning right, but it doesn't when turning left! How can you explain that?

And how can you explain the fact that it can go forward and backwards?
[img=http://img14.imageshack.us/img14/4082/robotlayout.th.jpg] (http://img14.imageshack.us/my.php?image=robotlayout.jpg)
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Razor Concepts on April 22, 2009, 10:20:41 AM
Move one servo at a time and see how it moves with values 0 and 180. It's just debugging, trying to find what each servo is actually doing.
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on April 23, 2009, 03:32:34 AM
Please understand that each servo works the normal way individually. 0 and 180 as values work ok for max. speed in both directions. All servos work ok.

Here is the servo layout

S3               S1



S4               S2




Code: [Select]
void drive_forward(void) {
  for(int i = 0; i < 5000; i++) {
  s1.write(180);
  s2.write(180);
  s3.write(0);
  s4.write(0);
  SoftwareServo::refresh();
  }
}
This part works flawlessly. The rover moves forward. So does the reverse function...which makes the rover go backwards. I just exchange the values of s1, s2, s3, s4

Code: [Select]
void drive_backwards(void) {
  for(int i = 0; i < 5000; i++) {
  s1.write(0);
  s2.write(0);
  s3.write(180);
  s4.write(180);
  SoftwareServo::refresh();
  }
}


The only trouble I have is with getting the rover to go left. Meaning I have to move s1 and s2 in one direction, and s3 and s4 in the other direction. Considering the fact that they are placed opposite of each other, giving them all the same value would result in different direction for s1-2 and s3-4.

If I write 0 to all of them, the rover should go and goes right. All fine until now.

If I write 180 to all of the 4 servos, the rover should go left, BUT IT KEEPS GOING RIGHT, same as 0 to all of them.

That's what I don't understand. It goes forward, backwards and right, but it doesn't go left.
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Ro-Bot-X on April 23, 2009, 06:17:40 AM
I had the surprise of seeing one servo going from full right to full left when I was sending commands to increase servo position step by step and the position reached 180. This is why I told you to try the range 1-179 instead of 0-180. Try it. Sometimes when all servos are on at the same time the software gets confused (probably a bug) and it throws the position out of range and resets it to 0.

Also I have noticed that you are issuing SoftwareServo::Refresh() too often, it takes the micro just a few cycles to go through the for loop and the refresh command shouldnt be issued faster than a few ms or problems could arrise. Add a delay(5) or so after the refresh command and shorten the number of times it goes through the for loop from 5000 to something like 500 and see what happens.
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on April 24, 2009, 03:19:27 AM
I did exactly what you told me to... I added delay(5) after Servo::refresh(); and I changed the loop count to 500, instead of 5000. It works just the same. Forward, backwards and right, but still no left. It's driving me mad. I would rather have them all not working, because it would be easy to debug. WTF?


I am out of ideas!
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Ro-Bot-X on April 24, 2009, 06:04:09 AM
Try this:

Code: [Select]
void step(void) {
  for(int i = 0; i <= 180; i++) {
  s1.write(i);
  s2.write(i);
  s3.write(i);
  s4.write(i);
  delay(20);
  SoftwareServo::refresh();
  }
}
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying
Post by: blackheart on April 24, 2009, 07:33:21 AM
I already did try that, someone told me to. Every servo works with it. It goes one direction up to a point and then it changes directions. Still no luck with the rover.


I tried something else today. Taking turns with only 2 servos while blocking the others, but it's not efficient and it doesn't work well. I want to make it turn with all 4 servos. I also tried giving different values to the 4 servos, for example, 179, 178, 177, 176, and still no luck. If it goes forward, and it goes backwards, I thought it had a problem when all servos had the same value, so I changed it, but still no luck, as mentioned.


Do you think I should try controlling the servos the normal way, without SoftwareServo.h functions? Would that allow me to control 4 servos, or only 2 on pins 9 and 10?


Thank You very much!
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Ro-Bot-X on April 24, 2009, 07:07:22 PM
Yes, you can use a Y cable to connect 2 servos in paralel to a single microcontroler pin. I would have done that in the first place instead of issuing 4 servo commands. Now you may want to go with the normal Servo library and use the range 0-180 or go with the ServoTimeTimer1 library to use real microseconds to fine tune the servo speeds. It all depends how accurate you need to be around the center (stop) point. I had to use microseconds because the servos were not perfectly centered and were slightly turning no matter where I set the stop point. Both libraries are SetAndForget type, that means the servo will be on at the specified speed until you tell it to stop. No Servo::Refresh command is necessary anymore.
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on April 25, 2009, 12:25:36 AM
I don't want high accuracy. So I can still use the SoftwareServo.h library I guess(I am lazy, and this one is very easy for me). Wait, Y-cable? How come I didn't think of that? Thank you! A million times, thank you!

P.S. I told you I am lazy, so can I use the Y-cable just for the Signal(yellow) wire? The servos are already powered in parallel powered IN PARALLEL., that is OK, right?


Thank You!
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: SmAsH on April 25, 2009, 01:33:39 AM
yes, i suppose you can just use the y-harness for the signal, by parallel do you mean like from an external source?
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on April 25, 2009, 03:12:47 AM
Yes, from an external source.

Here is the layout.

+      -



S1+   S1-

S2+   S2-

S3+   S3-

S4+   S4-
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Ro-Bot-X on April 25, 2009, 05:25:36 AM
You can tie in paralel the signal wire for the both servos on the left side and for both servos on the right side. Connect left side to pin 9 and right side on pin 10. Use Servo library (uses Timer1 to generate the PWM signal) for these 2 servos and SoftwareServo library for others.
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on April 25, 2009, 06:01:06 AM
Wait. I already did tie them together(the signal wire) and it works...but not to the left... I guess I will use pins 9 and 10 and use Servo library for these 4(actually 2) servos and SoftwareServo for the other 2 servos(non-modified) for sharp ir's.

Why and how do I use timer1? Can't I just do s1.write(180); and then delay(15);
?

Thank You! I will try this. Hope it works!
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying
Post by: blackheart on April 25, 2009, 09:33:30 AM
sorry for double-posting. I couldn't modify the previous post again. I tried using the servo library, but still no luck, Works forwards, works backwards, works right, but doesn't work left. I really don't know what else to try. I can't explain why it does that.

Also, even if I don't put anything in the loop() function and I leave it blank, the servos still spin and the rover goes to the right. I think pins 9 and 10 are related to each other.

What else can I do?






UPDATE

Nothing? I am out of ideas. I tried anything. Should I try controlling the servos the normal way? without servo lib, or is that too difficult?
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying
Post by: blackheart on April 27, 2009, 08:11:08 AM
Nobody knows what can be wrong? Now, it's like having 2 servos only, because the signal wire servo1 and servo2 are tied together and connected to a single digital pin(7) and the signal wires from servo3 and servo4 are also tied together and connected to digital pin(8). So even though it's like having only 2 servos, I am still having problems.  I am going to say I have only 2 servos. Servo right(s1) and servo left(s2).

S2       S1


If I give s1 a value of 180 and I give s2 a value of 0, the rover(robot) moves forwards and I am happy with that.
If I give s1 a value of 0 and I give s2 a value of 180, the rover(robot) moves backwards and I am also very happy with that.
Now, here comes trouble.
If I give s1 a value of 180 and I give s2 the same value of 180, instead of going left, the rover goes right.
If I give s1 a value of 0 and I give s2 the same value of 0, the rover goes right.

Just to mention, both s1 and s2 work in both directions when they are controlled individually.

My question is why? When I had each servo hooked up individually, I thought the uC had a problem controlling 4 servos or something like this.


The purpose of this post is to update the thread and to give people more information in order to help me solve this problem.


Should I do the same for the power wires? Tie them together? For the power wires, I could tie them all 4 together(of course, separating positive from negative). Would that be ok?
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: hazzer123 on April 27, 2009, 08:51:59 AM
I just assembled a model of your robot... 4 servos attached to 2,4,6 and 8. I ran the code and it seemed fine.

Check you have the latest version of softwareservo?

Oh and you don't need to write to the servo each time in the loop. You should write to it once, then unless you want to change it, don't write to it again. Just keep refreshing it. Like this -

Code: [Select]
void drive_left(void) {
  s1.write(180);
  s2.write(180);
  s3.write(180);
  s4.write(180);
  for(int i = 0; i < 100; i++) {
    delay(10); //Delay 10ms
    SoftwareServo::refresh();
  }
 
}


Other than that, try using different ports for your servo, maybe 3,5,7,9 or sth. Switch servos around. Print out information over serial to your arduino console and see what is happening. Use an oscilloscope. Refresh your whole project directory and code. Check that you aren't actually compiling and programming the bot with old code. Switch the function calls around - fwd, back, right, left instead. Reinstall the arduino software. Try another arduino. Try it from a friends computer.

Just try everything you can think of, and get used to these kinds of problem, they are frustratingly common in my experience :P
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on April 27, 2009, 11:48:50 AM
Thank You! I didn't solve the problem yet, but I thought I would post this.

Robot layout! Top View

S3        S1
 |           |
 |           |
 |           |
S4        S2

S1 is connected to S2 and S3 to S4, so it's like having 2 servos(I repeat this for the 10th time, sorry);


Here is the code that is uploaded right now on the Arduino. I have the same problem still

This code is still in its beta stage.
Code: [Select]
#include <SoftwareServo.h>
SoftwareServo sp1, sp2, sa, sb;
int pin_sp1, pin_sp2, pin_sa, pin_sb;
int pin_ir1, pin_ir2, pin_ir3;
float read_cm(byte pin) {
int tmp;

tmp = analogRead(pin);
if (tmp < 3)
return -1; // invalid value

return (6787.0 /((float)tmp - 3.0)) - 4.0;
}

void fwd(void) {
  sp1.write(180);
  sp2.write(0);
  for(int i = 0; i < 100; i++) {
  SoftwareServo::refresh();
  delay(15);
  }
}

void back(void) {
  sp1.write(0);
  sp2.write(180);
  for(int i = 0; i < 100; i++) {
  SoftwareServo::refresh();
  delay(15);
  }
}
 
void left(void) {
  sp1.write(180);
  sp2.write(180);
  for(int i = 0; i < 100; i++) {
  SoftwareServo::refresh();
  delay(15);
  }
}

void right(void) {
  sp1.write(0);
  sp2.write(0);
  for(int i = 0; i < 100; i++) {
  SoftwareServo::refresh();
  delay(15);
  }
}

void setup() {
  pin_sp1 = 3;
  pin_sp2 = 6;
  pin_sa = 10;
  pin_sb = 4;
  pin_ir1 = 0;
  pin_ir2 = 2;
  pin_ir3 = 4;
  sp1.attach(pin_sp1);
  sp2.attach(pin_sp2);
  digitalWrite(13, HIGH);
}

void loop() {
    fwd();
    back(); 
    left();
    right();
}



I will try updating SoftwareServo.h and I will also try to upload the program from another PC...maybe a windows PC.


If you still have the robot assembled, please try it with this code.

S1(meaning s1 and s2) on pin 3 and S2(meaning s3 and s4) on pin 6.

Thank You very much!
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: hazzer123 on April 27, 2009, 01:22:52 PM
Hmmm it works fine on my setup...

I can't recommend anything else... Its STRANGE!

Here, i've attached my SoftwareServo as a zip. Try that out
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on April 27, 2009, 02:58:03 PM
Stil, no luck! I used your SoftwareServo library, but it still doesn't work. I just don't get it! It is very weird. Could you please post some pictures, information, etc of your setup? I want to see what you did and compare.

Thank you. I am really out of ideas
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: hazzer123 on April 27, 2009, 04:35:51 PM
Hmm ok here is my setup. Im not sure it will help...

There is a shield i made on top of the arduino. Don't worry, the connections are definitely the way you described!
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Ro-Bot-X on April 27, 2009, 07:31:10 PM
I am not sure this is going to help you or not, I just want to show you a different approach using ServoTimeTimer1 library. The following functions are used on my MiniEric robot. After receiving a command (Forward, Reverse, Left, Right) the functions will be called and the servos will accelerate to the top speed that was previously set. When a Stop command is received, the servos will be decelerated to a complete stop.

Code: [Select]
#include <ServoTimeTimer1.h>

#define RmotorPin 9     // digital pin  9, PWM pin
#define LmotorPin 10    // digital pin 10, PWM pin

ServoTimeTimer1 Lmotor;
ServoTimeTimer1 Rmotor;

byte Speed = 200;
byte TurnSpeed = 50;
byte Acc = 10;
byte direction = 1;

void setup() {
  Lmotor.attach(LmotorPin);
  Rmotor.attach(RmotorPin);
  Lmotor.write(1315); // rev 1015 - 1315 - 1615 fwd
  Rmotor.write(1330); // rev 1030 - 1330 - 1630 fwd

}

void loop(){
  //get the commands here...
}


void Stop(){
  switch (direction) {
    case 0:                           // direction = reverse
      for (int s=0; s <= Speed; s=s+Acc) {
        Lmotor.write(1315-Speed+s);   // rev 1015 - 1315 - 1615 fwd
        Rmotor.write(1330-Speed+s);   // rev 1030 - 1330 - 1630 fwd 
        delay(20);
      }
      break;
    case 1:                           // direction = forward
      for (int s=0; s<=Speed; s=s+Acc) {
        Lmotor.write(1315+Speed-s);   // rev 1015 - 1315 - 1615 fwd
        Rmotor.write(1330+Speed-s);   // rev 1030 - 1330 - 1630 fwd 
        delay(20);
      }
    break;
    case 2:                               // direction = left
      for (int s=0; s<=TurnSpeed; s=s+Acc) {
        Lmotor.write(1315+TurnSpeed-s);   // rev 1015 - 1315 - 1615 fwd
        Rmotor.write(1330-TurnSpeed+s);   // rev 1030 - 1330 - 1630 fwd 
        delay(20);
      }
      break;
    case 3:                               // direction = right
      for (int s=0; s<=TurnSpeed; s=s+Acc) {
        Lmotor.write(1315-TurnSpeed+s);   // rev 1015 - 1315 - 1615 fwd
        Rmotor.write(1330+TurnSpeed-s);   // rev 1030 - 1330 - 1630 fwd 
        delay(20);
      }
      break;
  }
}

void Forward(){
  direction = 1;
  for (int f=0; f<=Speed; f=f+Acc) {
    Lmotor.write(1315+f); // rev 1015 - 1315 - 1615 fwd
    Rmotor.write(1330+f); // rev 1030 - 1330 - 1630 fwd 
    delay(20);
  }
}

void Reverse(){
  direction = 0;
  for (int r=0; r<=Speed; r=r+Acc) {
    Lmotor.write(1315-r); // rev 1015 - 1315 - 1615 fwd
    Rmotor.write(1330-r); // rev 1030 - 1330 - 1630 fwd 
    delay(20);
  }
}

void TurnLeft(){
  direction = 2;
  for (int L=0; L<=Speed; L=L+Acc) {
    Lmotor.write(1315+L); // rev 1015 - 1315 - 1615 fwd
    Rmotor.write(1330-L); // rev 1030 - 1330 - 1630 fwd 
    delay(20);
  }
}

void TurnRight(){
  direction = 3;
  for (int R=0; R<=Speed; R=R+Acc) {
    Lmotor.write(1315-R); // rev 1015 - 1315 - 1615 fwd
    Rmotor.write(1330+R); // rev 1030 - 1330 - 1630 fwd 
    delay(20);
  }
}
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying
Post by: blackheart on April 28, 2009, 12:57:11 AM
Although I don't understand much of your code, maybe it will help. 2 servos work for me too. but when I have 4(even though they are tied as 2) they stop working correctly.

I will try using your code and I will see.


Thank You!


UPDATE
It doesn't even compile. I downloaded a version of Servotimetimer1 from arduino.cc, but it has lots of bugs.

Could  you please upload your ver. of the lib?



I have a 6V NI-CD 620mAh battery powering the servos with a voltage regulator(because when it's fully charged, it goes up to 7V) . Could it be because of the battery? Is 620mAh not enough for 4 servos?

Thank you!
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying
Post by: blackheart on April 28, 2009, 09:49:31 AM
No result. Could it be because of the low current the 6V Ni-CD supplies(620mAh)? What can I do regarding the Servotimetimer.h library? It has some errors!

UPDATE

One more piece of information that can maybe help. I have s1 on pin 3 and s2 on pin6. If I reverse the connections(s1 on 6 and s2 on 3) the functions fwd and back are reversed, meaning fwd is going backwards and back is going forwards. BUT, the functions left and right stay the same. Meaning the rover keeps going only right. I thought it was gonna go only left with the pins reversed, but it still goes only  right. I think it is a hardware problem. WHAT DO YOU THINK?
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: hazzer123 on April 28, 2009, 11:51:11 AM
Wow something is seriously wrong there...

It seems your robot has developed a understanding of direction and prefers right :P Hmmm I cant help again sorry.

But if you do find your problem (i suspect you will and you will kick yourself.... i have done it many many times) then definitely post it here! I'm so intrigued by this!
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on April 28, 2009, 12:09:19 PM
Wow, should I get this patented? I can't explain it. Wait. While typing this, I realized I can explain it. It acts the same way when both servos have the same value. Whether it's 0 and 0 or 180 and 180, it acts the same, so now I know why it goes right even if I switch the pins around.

But why it keeps going right, IDK!
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: hazzer123 on April 28, 2009, 12:14:28 PM
You are saying that the servos don't change direction if you apply 180 and then 0?
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying
Post by: blackheart on April 28, 2009, 02:01:33 PM
No. I am saying that no matter what I do, the rover does not go left.
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Ro-Bot-X on April 28, 2009, 08:00:25 PM
Try to hold the robot in your hand and see if the servos rotate in the correct directions when the wheels don't touch the ground. It may be a layout problem, since it is a 4wd.
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying
Post by: blackheart on April 28, 2009, 11:39:44 PM
I explained already. It works forwards, backwards. But when I try to get it to go left, it keeps going right. Theoretically, it is a 4WD, technically, it's a 2WD.

The servos do move correctly. Do they need more current when they all have the same value or something? SHould I get a 6V gell-cell, 3A for all 4 of my servos? I currently have a 6 NI-CaD  with 620 mAh!
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Ro-Bot-X on April 29, 2009, 05:50:58 AM
Quote
The servos do move correctly. Do they need more current when they all have the same value or something? SHould I get a 6V gell-cell, 3A for all 4 of my servos? I currently have a 6 NI-CaD  with 620 mAh!

If the servos move correctly when the wheels are not touching the ground, but do not do that when you put it down to actually move, the problem is not in the software. You are using Roboduino, right? The battery is too small to give you the right power for 4 servos when they need to overcome the friction to slide sideways when turning left or right. The servos are probably not aligned correctly, that is why the robot favours turning right instead of turning left. Consider that each servo draws at least an amp when turning. Because the battery is so small, it can't deliver the right aperage and the voltage drops too much. On Roboduino, the power goes through a diode before getting to the servos and to the voltage regulator, take that out and replace it with a thick wire, but only if you use the 6V battery. If you use a 7.2V or greater, you don't need to. And get at least a 1000mAh NiMH or NiCd battery, not a gel-cell. Try at Radioshack, they might have it with charger on sale.
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying
Post by: blackheart on April 29, 2009, 11:42:37 AM
I am using an arduino. You know, I thought of that being the problem(not enough current), voltage drops and the servos turn to default    direction. The rover doesn't favor right, it only goes right.

I will try a battery with around 3000 mAh. I can get small gel-cells(6V) supplying 3AH with their chargers for around $30(on sale. I don't have RadioShack in this country). Why not use "gel-cell" batteries? They don't have any 6V NiMH or NiCD with more than 200mAh.

The wheels never move correctly when the rover is commanded to go left(not even if I hold it up...).

Both S1 and S2 are spinning as if the value was 0 for all of them even though left means 180 for s1 and s2 also in my case.

UPDATE

The arduino is powered from a 9V rechargeable battery supplying 200mAh.


What's the problem with gel-cells?
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Ro-Bot-X on April 30, 2009, 05:20:44 AM
Gel-cells are too heavy, your robot will have a hard time turning.
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying
Post by: blackheart on April 30, 2009, 05:28:53 AM
No, they are very small and very light and have the exact specs I need. It is not longer than the arduino and not thicker than a servo. It's very light also and it gives me exactly what I need. 6V and 3000mAh.





Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying
Post by: blackheart on May 01, 2009, 02:42:14 AM
Here is a video of it not working the way I want to. It's code is

fwd();
back();
left();
right();

But it acts like this:

fwd();
back();
right();
right();

I am now using a 4A 6V gel-cell, but still no luck.


I think I am gonna try controlling the servos without any library.






RV-1 Autonomous rover using an Arduino... (http://www.youtube.com/watch?v=iO8YuwSEJwQ#lq-lq2-hq-vhq)
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: hazzer123 on May 01, 2009, 02:59:50 AM
Hmmm... have you tried the order:  forward, left back, right?
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on May 01, 2009, 03:42:07 AM
No matter what order I try, when 2 servos have the same values, it goes crazy and only spins right. I don't understand anything anymore.

I tried taking turns with only one side, and it would work, but I still have a problem.

sp1.write(180); it does go left.

sp2.write(0); it Would go right, but it goes forward because sp1 is still 180. How can I reset sp1 so it doesn't spin at all and the other way around?
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Ro-Bot-X on May 01, 2009, 05:56:47 AM
To make a servo not spin at all you can issue a write(90) or detach the servo. You may need to adjust write(90) until the servo does not spin, depending on the servo type you have. On my robot, the center is not 90 but 82. If you detach the servo, the library will not send any more pulses to that servo. To use the servo again, you simply atach it back.
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on May 01, 2009, 12:48:18 PM
Well, I could write 86(in my case) to stop s2 from moving and write 180 to s1 which would make the rover go left...but if I write to both of them, then it goes crazy and starts turning write as always. So I have to detach it and reattach it in both functions left/write.
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying
Post by: blackheart on May 04, 2009, 07:54:28 AM
I never got around fixing the problem, but I did find a way around it. Steering with only one pair of servos(one servo) while the other servo is not rotating. It does sometimes make the other one spin, but it's ok. I will post the code when I am done.


I do have another problem now. I want the micro servo on which the IR rangefinder is attaached to go to 45, then 95, then 145.

If I write 45, delay, then write 95, delay and write 145 delay and then refresh, it doesn't work. I tried it in a loop.

for(int i = 45; i <= 145; i+= 45) {
sa.write(i);
SoftwareServo::refresh();
delay(15);
}


but it still doesn't work.


Any help with this?

I know I should have finished it a long time, but I am also very busy with some programming contests for school and final exams which are killing me!


I know you can literally brake a standard servo.


But is there any way to brake a continuous rotation servo? Detaching it makes it stop, but you can still move it very easily with your hand.

Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Ro-Bot-X on May 04, 2009, 09:24:37 PM
Send to the servo the stop pulse. Unfortunatelly, because there is no feedback from the pot ( it doesn't move along with the servo spline) the electronics can't work to hold that position. The only way to make the continuaous rotation servo brake is to use encoders and eighter a dedicated microcontroller or have a function that will command the motor from the servo to move if the position changes.
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on May 05, 2009, 03:50:10 AM
Nevermind that. I am now focusing on developing the scanning system.

Here is what I got so far:

Code: [Select]
int scan() {
int i;
float val_s, val_r, val_l;
for(i = 0; i < 50; i++) {
    sa.write(95);  //CENTER
    SoftwareServo::refresh();
    delay(15);
}

for(i = 0; i < 50; i++) {
    sa.write(145);  //RIGHT
    SoftwareServo::refresh();
    delay(15);
}

for(i = 0; i < 50; i++) {
    sa.write(45);  //LEFT
    SoftwareServo::refresh();
    delay(15);
}

}

This works and moves the scanner servo in the 3 positions I want to scan.
Now the scanning. Should I place the read(); function I already wrote(it gets a value from the IR Rf's and returns the distance)  in between the for loops or where? If I place it within the loops, it will read many times, wasting battery and uC resources. If I place it in between the loops, it will go on after a loop is done, but will the servo remain in the same position until the next loop goes on?
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on May 06, 2009, 06:24:49 AM
Nobody? No help at all?

Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Ro-Bot-X on May 06, 2009, 06:39:12 AM
You should do:

- servo go left
- servo refresh
- wait a little so the servo has time to get to the position
- take a few readings
- average the readings
- transform to distance

- servo go forward
- servo refresh
- wait a little so the servo has time to get to the position
- take a few readings
- average the readings
- transform to distance

same thing for right...
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: blackheart on May 07, 2009, 03:10:12 AM
here is the code...so far...

Code: [Select]
#include <SoftwareServo.h>
SoftwareServo sp1, sp2, sa, sb;
int pin_sp1, pin_sp2, pin_sa, pin_sb;
byte pin_ir1, pin_ir2, pin_ir3;
float read_cm(byte pin) {
int tmp;

tmp = analogRead(pin);
if (tmp < 3)
return -1; // invalid value

return (6787.0 /((float)tmp - 3.0)) - 4.0;
}

void fwd(void) {
  if(!(sp1.attached()))
      sp1.attach(pin_sp1);
  if(!(sp2.attached()))
      sp2.attach(pin_sp2);
  sp1.write(180);
  sp2.write(0);
  for(int i = 0; i < 100; i++) {
  SoftwareServo::refresh();
  delay(15);
  }
}

void back(void) {
  if(!(sp1.attached()))
      sp1.attach(pin_sp1);
  if(!(sp2.attached()))
      sp2.attach(pin_sp2); 
  sp1.write(0);
  sp2.write(180);
  for(int i = 0; i < 100; i++) {
  SoftwareServo::refresh();
  delay(15);
  }
}
 
void left(void) {
  sp2.detach();
  if(!(sp1.attached()))
      sp1.attach(pin_sp1);
  sp1.write(180);
  for(int i = 0; i < 100; i++) {
  SoftwareServo::refresh();
  delay(15);
  }
}

void right(void) {
  sp1.detach();
  if(!(sp2.attached()))
      sp2.attach(pin_sp2);
  sp2.write(0);
  for(int i = 0; i < 100; i++) {
  SoftwareServo::refresh();
  delay(15);
  }
}

void center() {
  sa.write(95);
  SoftwareServo::refresh();
}

int scan() {
  int i;
  float val_s, val_r, val_l;
  val_s = val_r = val_l = 0;
  sa.write(95);
  for(i = 0; i < 20; i++) {
    SoftwareServo::refresh();
    delay(50);
    val_s += read_cm(pin_ir1); 
  }
  val_s /= 20;
  sa.write(145);
  for(i = 0; i < 20; i++) {
    SoftwareServo::refresh();
    delay(50);   
    val_l += read_cm(pin_ir1);   
  }
  val_l /= 20;
  sa.write(45);
  for(i = 0; i < 20; i++) {
    SoftwareServo::refresh();
    delay(50);
    val_r += read_cm(pin_ir1);   
  }
  val_r /= 20;
  if(val_r > val_l)
    right();
  else
    left();
}
void setup() {
  pin_sp1 = 3;
  pin_sp2 = 6;
  pin_sa = 4;
  pin_sb = 10;
  pin_ir1 = 0;
  pin_ir2 = 2;
  pin_ir3 = 4;
  sp1.attach(pin_sp1);
  sp2.attach(pin_sp2);
  sa.attach(pin_sa);
  sb.attach(pin_sb);
  digitalWrite(13, HIGH);
  Serial.begin(9600);
}
void loop() {
scan();
}

I am ging to work on it today an post the final code soon.


P.S. I just got a new idea, I have 3 Ir RF's. SHould I use the 2 servos on the front so it can have 2 degrees for the sensor, up/down && left/right and just place the 2 sensors on the back of the rover with no servo?
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!
Post by: Ro-Bot-X on May 07, 2009, 06:40:48 AM
Try this one instead:

Code: [Select]
int scan() {
  int val_s, val_r, val_l;
  val_s = val_r = val_l = 0;

  sa.write(95);
    servo_delay();
    val_s = read_sensor();

  sa.write(145);
    servo_delay();
    val_l = read_sensor();

  sa.write(45);
    servo_delay();
    val_r = read_sensor();

  if(val_r > val_l)
    right();
  else
    left();
}

void servo_delay() {
    for (int t=0; t<=10; t++){
      SoftwareServo::refresh();
      delay(20);
    }
}

int read_sensor() {
  float tmp = 0;
  for (int i=0; i<=20; i++){
    tmp += analog.read(pin_ir1);
  }
  tmp /= 20;
  tmp = (6787.0 /((float)tmp - 3.0)) - 4.0;
  return tmp;
}
Title: Re: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying
Post by: blackheart on May 09, 2009, 03:48:54 AM
Finally, I finished the rover, and I would like to say Thanks to every member that helped me solve the numerous problems I encountered. I will post the source code tonight, when I get home. It works pretty well with one sensor attached on 2 micro servos that give it "4 degrees of freedom".

Here is a new video...sorry for the extremely bad quality. I don't have a camera for now...the old one broke and I used my samsung omnia which really sucks.

RV-1 Autonomous Rover Robot using an Arduino (http://www.youtube.com/watch?v=VKwT-6E99xA#lq-lq2-hq-vhq)


I am "debating" over what to start next...the autonomous helicopter, or a humanoid...


Any help?