Go Down

Topic: servo codes (Read 568 times) previous topic - next topic

asre

my project is to build a mobile robot that move forward in certain distance..i using 2 modified servo motor (from 180deg to 360 deg rotation).. i want it move in certain distance..let say in 10meter..i have working code for rotating the servo but it rotate in time (means when we set it rotate 5sec, it will rotate then stop). my problem is how i modified the code so it looping the 5 sec rotating into distance? ( let say in 2 sec, the mobile robot move in 1meter)

#include <Servo.h>

Servo servoLeft;          // Define left servo
Servo servoRight;         // Define right servo

void setup() {
  servoLeft.attach(10);  // Set left servo to digital pin 10
  servoRight.attach(9);  // Set right servo to digital pin 9

}

void loop() {            // Loop through motion tests
  forward();             // Example: move forward
  delay(2000);           //
  stopRobot();
}

// Motion routines for forward, reverse, turns, and stop
void forward()
{
  servoLeft.write(0);
  servoRight.write(90);
}
void stopRobot() {
  servoLeft.detach();
  servoRight.detach();

MarkT

[ don't forget to post code in code-tags - this is explained in the "How to use this forum - please read." thread ]

Can you explain more clearly:

1) What exactly you want the robot to do
2) What your existing code is actually doing (and why its a problem).
[ I won't respond to messages, use the forum please ]

asre


[ don't forget to post code in code-tags - this is explained in the "How to use this forum - please read." thread ]

Can you explain more clearly:

1) What exactly you want the robot to do
2) What your existing code is actually doing (and why its a problem).


1) my robot move forward in certain distance set by user...lets say user set to move forward 400 meter.
2) here is my code
Code: [Select]
#include <Servo.h>

Servo servoLeft;          // Define left servo
Servo servoRight;         // Define right servo

void setup() {
  servoLeft.attach(10);  // Set left servo to digital pin 10
  servoRight.attach(9);  // Set right servo to digital pin 9
}

void loop() {            // Loop through motion tests
  forward();             // Example: move forward
  delay(2000);           // Wait 2000 milliseconds (2 seconds)
  stopRobot();
  delay(2000);
}

// Motion routines for forward and stop
void forward() {
  servoLeft.write(0);
  servoRight.write(180);
}
void stopRobot() {
  servoLeft.write(90);
  servoRight.write(90);
}


this code will rotate the servo (means move forward) in 2 sec..my project need to move the robot in 400meter. i dont know how far the robot move in 2sec..so if i fix the time..for example. in 2 sec, the robot move forward for 2meter. please someone modified the code so the robot move for 400meter (other distance also can)... =(

joe mcd

You cannot measure distance by time alone.  The servo rotation speed can vary depending on load.  The normal practice uses wheel encoders to directly measure wheel rotations.

After 400 meters even wheel rotation may lose accuracy due to slippage.  Is this robot moving out of doors?  Is the 400M a linear distance or simply back & forth in a small area?  If a linear distance outdoors, most people would add a GPS unit.

Joe

asre


You cannot measure distance by time alone.  The servo rotation speed can vary depending on load.  The normal practice uses wheel encoders to directly measure wheel rotations.

After 400 meters even wheel rotation may lose accuracy due to slippage.  Is this robot moving out of doors?  Is the 400M a linear distance or simply back & forth in a small area?  If a linear distance outdoors, most people would add a GPS unit.

Joe



no..it just move forward in certain distance. i give example 400meter forward..the codes i given is the both servo rotate in time..i want modified, but it in distance..and i dont know how..so i hope master in arduino can help me...:(

joe mcd

Quote
no..it just move forward in certain distance. i give example 400meter forward..the codes i given is the both servo rotate in time..i want modified, but it in distance..and i dont know how..


Simply measure the time required to travel 1 meter, T1.  Obviously  T400 = T1 * 400.  Thus we delay by delay(T1*400).  But this math is very idealized. 

I am still puzzled by the application.  What is the robot doing?.  Where is it going?  Terrain?

Joe

http://arduino.cc/forum/index.php/topic,163812.0.html ?
www.bajdi.com

Go Up