Pages: [1]   Go Down
Author Topic: Servo Library error causing robot to imitate a dog chasing it's tail.  (Read 363 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For my robot I am using both servo library and the virtual wire library. I was trying to figure out a way to use both and I downloaded servotimer2. I downloaded it and tried to play with the same numbers I use for the normal servo library. I even used something to help convert pwm to degrees so it would work. I played with my servos and had to center them to make them run correctly, but after that I figured out an error that was occuring; my robot just did a continuous circle. With the servo timer2 library I used the same degrees I used in the normal library. Anything I can do to fix this because I have to use the virtualwire library and some library that helps me move the servos.

Here is the servotimer2 code that causes the dog chasing it's tail in a circle.
Code:
#include <ServoTimer2.h>  // the servo library

// defined the pins for the servos
#define leftWpin  10
#define rightWpin 12
const int MIN_PULSE = 544;     // the shortest pulse sent to a servo (0 degrees)
const int MAX_PULSE = 2400;     // the longest pulse sent to a servo  (180 degrees)

int degreesToUS(int degrees)
{
  return (map,degrees, 0,180, MIN_PULSE, MAX_PULSE);
}


ServoTimer2 leftWheel;    // declare variables for up to eight servos
ServoTimer2 rightWheel;


void setup() {
  leftWheel.attach(rightWpin);     // attach a pin to the servos and they will start pulsing
  rightWheel.attach(leftWpin);

  leftWheel.write(degreesToUS(50));
  rightWheel.write(degreesToUS(130));
  delay(950);

  rightWheel.detach();
  leftWheel.detach();

}

void loop()
{

}
The normal servo library that makes the robot go straight.
Code:
#include <Servo.h>                           // Include servo library
 
Servo servoRight;                            // Declare right servo
 Servo servoLeft;
void setup()                                 // Built in initialization block
{
  servoRight.attach(12);                     // Attach right signal to pin 12
servoLeft.attach(10);
  servoLeft.write(50);   // Left wheel clockwise
 servoRight.write(130);  // Right wheel counterclockwise
}
void loop()                                  // Main loop auto-repeats

}
Please any help with be much appreciated.
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the degreesToUS function should be:
Code:
int degreesToUS(int degrees)
{
  return (map(degrees, 0,180, MIN_PULSE, MAX_PULSE));
}

although ServoTimer2 will not be as accurate as the Srvo library, I did a quick test using a logic analyzer and measured the output timing of ServoTimer2 to be within 1 % of the servo library. This will degrade if other interrupts are occurring frequently (as may be the case with VirtualWire), but I am surprised the test sketch posted does not work for you.

Can you post a link to the location where you downloaded the version of ServoTimer2 that you are using.


p.s. - the title of this tread may cause unnecessary concern for people using the Servo library, you may want to rephrase the problem statement as we don't yet know what is the cause of the behavior you are seeing, but its nothing to do with the Servo library and my not be due to an error in ServoTimer2.
Michael
« Last Edit: January 22, 2014, 03:37:44 am by mem » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 36
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://forum.arduino.cc/index.php/topic,21975.0.html
The original post you posted the library is where I got it. I had some errors and found a forum post the OP had the same errors and he posted the code containing the fixed errors and I haven't received an error(when compiling) since I used that code.
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6250
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://forum.arduino.cc/index.php/topic,21975.0.html
The original post you posted the library is where I got it. I had some errors and found a forum post the OP had the same errors and he posted the code containing the fixed errors and I haven't received an error(when compiling) since I used that code.


If the code you are using is from another post,  let me have a link to that code. I would like to have a look at the exact same code you are running.

Logged

Pages: [1]   Go Up
Jump to: