Pages: [1]   Go Down
Author Topic: servo  (Read 705 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi all.. im asre and i new in arduino..i have problem with my servo..i using 2 modified continuous servo (my project is built a mobile robot)  and i want it move in certain location (let say in 5meter). can anybody help me with a code how i move my mobile robot? please...
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34151
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Continuous servos do not do position any more so all you can do is to turn on the motor for a fixed ammount of time. Calibrate the time to give you the distance you want.
Logged

0
Offline Offline
Tesla Member
***
Karma: 143
Posts: 9593
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Simple test code for two servos.

Code:
// zoomkat 12-13-11 serial servo (2) test
// for writeMicroseconds, use a value like 1500
// for IDE 1.0
// Powering a servo from the arduino usually DOES NOT WORK.
// two servo setup with two servo commands
// send eight character string like 15001500 or 14501550
// use serial monitor to test

#include <Servo.h>
String readString, servo1, servo2;
Servo myservo1;  // create servo object to control a servo
Servo myservo2;

void setup() {
  Serial.begin(9600);
  myservo1.attach(6);  //the pin for the servo control
  myservo2.attach(7);
  Serial.println("two-servo-test-1.0"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(3);  //delay to allow buffer to fill
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    }
  }

  if (readString.length() >0) {
      Serial.println(readString); //see what was received
      
      // expect a string like 07002100 containing the two servo positions      
      servo1 = readString.substring(0, 4); //get the first four characters
      servo2 = readString.substring(4, 8); //get the next four characters
      
      Serial.println(servo1);  //print to serial monitor to see parsed results
      Serial.println(servo2);

      int n1 = servo1.toInt();
      int n2 = servo2.toInt();

      Serial.println("the numbers are :");
      Serial.println(n1);  //print to serial monitor to see number results
      Serial.println(n2);
            
      myservo1.writeMicroseconds(n1); //set servo position
      myservo2.writeMicroseconds(n2);
    readString="";
    servo1="";
    servo2="";
  }
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

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

Continuous servos do not do position any more so all you can do is to turn on the motor for a fixed ammount of time. Calibrate the time to give you the distance you want.

hmm...let say in 2sec. the mobile robot can move 3meter..can u help me how to put in codes? its not about time..its more to distance... my friend say do in looping code..but i still new in codes..can help?
Logged

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

Simple test code for two servos.

Code:
// zoomkat 12-13-11 serial servo (2) test
// for writeMicroseconds, use a value like 1500
// for IDE 1.0
// Powering a servo from the arduino usually DOES NOT WORK.
// two servo setup with two servo commands
// send eight character string like 15001500 or 14501550
// use serial monitor to test

#include <Servo.h>
String readString, servo1, servo2;
Servo myservo1;  // create servo object to control a servo
Servo myservo2;

void setup() {
  Serial.begin(9600);
  myservo1.attach(6);  //the pin for the servo control
  myservo2.attach(7);
  Serial.println("two-servo-test-1.0"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(3);  //delay to allow buffer to fill
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    }
  }

  if (readString.length() >0) {
      Serial.println(readString); //see what was received
      
      // expect a string like 07002100 containing the two servo positions      
      servo1 = readString.substring(0, 4); //get the first four characters
      servo2 = readString.substring(4, 8); //get the next four characters
      
      Serial.println(servo1);  //print to serial monitor to see parsed results
      Serial.println(servo2);

      int n1 = servo1.toInt();
      int n2 = servo2.toInt();

      Serial.println("the numbers are :");
      Serial.println(n1);  //print to serial monitor to see number results
      Serial.println(n2);
            
      myservo1.writeMicroseconds(n1); //set servo position
      myservo2.writeMicroseconds(n2);
    readString="";
    servo1="";
    servo2="";
  }
}


can it move forwrd in certain location?
Logged

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

 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();
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34151
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
( let say in 2 sec, the mobile robot move in 1meter)
It't kindergarden maths.
2 seconds for 1 meter = 1 / 2 = 0.5 meters per second
So for 10 meters it will take 10 / 0.5 = 20 seconds
Logged

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

Quote
( let say in 2 sec, the mobile robot move in 1meter)
It't kindergarden maths.
2 seconds for 1 meter = 1 / 2 = 0.5 meters per second
So for 10 meters it will take 10 / 0.5 = 20 seconds

thank you sir..but if u given distance..how to calculate time travel? let say given distance = 400m... help me...
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34151
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The same as the last line of my post
Distance 400 meters at a speed of 0.5 meters / second
Is 400 / 0.5 = 800 seconds.
Logged

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

The same as the last line of my post
Distance 400 meters at a speed of 0.5 meters / second
Is 400 / 0.5 = 800 seconds.

thank you sir..smiley
Logged

Pages: [1]   Go Up
Jump to: