Author Topic: SoftwareServo.h and 4 continuous rotation servos are hell-bent on destroying me!  (Read 7990 times)

0 Members and 1 Guest are viewing this topic.

Offline blackheartTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 1
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!
I'm out of ideas!

Offline hazzer123

  • Supreme Robot
  • *****
  • Posts: 460
  • Helpful? 3
You are saying that the servos don't change direction if you apply 180 and then 0?
Imperial College Robotics Society
www.icrobotics.co.uk

Offline blackheartTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 1
No. I am saying that no matter what I do, the rover does not go left.
« Last Edit: April 28, 2009, 02:04:30 PM by blackheart »
I'm out of ideas!

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
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.
Check out the uBotino robot controller!

Offline blackheartTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 1
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!
« Last Edit: April 29, 2009, 03:02:33 AM by blackheart »
I'm out of ideas!

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
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.
Check out the uBotino robot controller!

Offline blackheartTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 1
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?
« Last Edit: April 29, 2009, 02:43:05 PM by blackheart »
I'm out of ideas!

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
Gel-cells are too heavy, your robot will have a hard time turning.
Check out the uBotino robot controller!

Offline blackheartTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 1
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.





I'm out of ideas!

Offline blackheartTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 1
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...

I'm out of ideas!

Offline hazzer123

  • Supreme Robot
  • *****
  • Posts: 460
  • Helpful? 3
Hmmm... have you tried the order:  forward, left back, right?
Imperial College Robotics Society
www.icrobotics.co.uk

Offline blackheartTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 1
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?
I'm out of ideas!

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
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.
Check out the uBotino robot controller!

Offline blackheartTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 1
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.
I'm out of ideas!

Offline blackheartTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 1
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.

« Last Edit: May 04, 2009, 07:56:18 AM by blackheart »
I'm out of ideas!

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
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.
Check out the uBotino robot controller!

Offline blackheartTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 1
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?
I'm out of ideas!

Offline blackheartTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 1
Nobody? No help at all?

I'm out of ideas!

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
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...
Check out the uBotino robot controller!

Offline blackheartTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 1
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?
I'm out of ideas!

Offline Ro-Bot-X

  • Contest Winner
  • Supreme Robot
  • ****
  • Posts: 1,431
  • Helpful? 25
  • Store: RoBotXDesigns.ca
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;
}
« Last Edit: May 07, 2009, 06:43:39 AM by Ro-Bot-X »
Check out the uBotino robot controller!

Offline blackheartTopic starter

  • Full Member
  • ***
  • Posts: 111
  • Helpful? 1
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



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


Any help?
I'm out of ideas!

 


Get Your Ad Here