Society of Robots - Robot Forum
Electronics => Electronics => Topic started by: meme167 on April 23, 2009, 08:29:09 PM
-
Please help!!!!...=(
im building my first arduino using three servos:
Two servos used as my wheels which can be connected to one pin on arduino board
The other servo is connected to a Srf 05 utrasonic rangefinder sensor
Now my question is:
How do i program this robot to scan the room for walls and also drive front and back using Arduino all together?
thanks!!
-
Well what have you achieved so far?
Did you manage to get the robot moving yet? Did you manage to get the scanning sensor detecting walls (without running the code for robot movement)?
You should break your problem up into more manageable pieces because (1) it's the best way to make a robot (2) Posting in forums is easier... You're unlikely to find a fellow roboteer who is going to spend time doing the project for you in 1 post. Try what you can, ask us for help with the things you don't understand and you will learn much more ;)
Good luck!
-
So far i have achieve moving the robot with the following code i found online:
/*
* Arduino Controlled Servo Robot (SERB) - Test Program
* For more details visit: http://www.oomlout.com/serb (http://www.oomlout.com/serb)
*
* Behaviour: A simple test program which causes the SERB
* to turn randomly either left or right for a
* random time period between 0.1 and 1 second.
* The SERB will then drive forward for a random
* time period between 1 and 2 seconds. Finally
* pausing for 2 seconds before starting again.
*
* Wiring: Right Servo Signal - pin 9
* Left Servo Signal - pin 10
*
* License: This work is licenced under the Creative Commons
* Attribution-Share Alike 3.0 Unported License. To
* view a copy of this licence, visit
* http://creativecommons.org/licenses/by-sa/3.0/ (http://creativecommons.org/licenses/by-sa/3.0/)
* or send a letter to Creative Commons, 171 Second
* Street, Suite 300, San Francisco, California 94105,
* USA.
*
*/
//--------------------------------------------------------------------------
// START OF ARDUINO CONTROLLED SERVO ROBOT (SERB) PREAMBLE
#include <Servo.h>
#define LEFTSERVOPIN 10
#define RIGHTSERVOPIN 9
Servo leftServo;
Servo rightServo;
int speed = 100; //sets the speed of the robot (both servos)
//a percentage between 0 and 100
// END OF ARDUINO CONTROLLED SERVO ROBOT (SERB) PREAMBLE
//--------------------------------------------------------------------------
/*
* sets pins to appropriate states and attaches servos. Then pauses
* for 1 second before the program starts
*/
void setup()
{
serbSetup(); //sets the state of all neccesary
//pins and adds servos to your sketch
randomSeed(analogRead(0)); //sets the random number seed with
//something mildly random
delay(1000);
}
/*
* turns the robot either left or right (randomly) for a period between
* 0.1 and 1 second. Before going forward for a random time period
* between 1 and 4 seconds. Before pausing for two seconds then starting
* again.
*/
void loop()
{
turnRandom(100,1000); //Turns randomly left or right for a
//randomtime period between .1 second
//and one second
goForwardRandom(1000,2000); //Goes forward for a random time period
//between
//1 and 2 seconds
goStop(); //Stops the robot
delay(2000); //pauses for 2 seconds (whilst stopped)
}
/*
* turns the robot randomly left or right for a random time period between
* minTime (milliseconds) and maxTime (milliseconds)
*/
void turnRandom(int minTime, int maxTime){
int choice = random(2); //Random number to decide
//between left (1) and right (0)
int turnTime = random(minTime,maxTime); //Random number for the pause
//time
if(choice == 1){ goLeft();} //If random number = 1 then turn
//left
else {goRight();} //If random number = 0 then turn
//right
delay(turnTime); //delay for random time
}
/*
* goes forward for a random time period between minTime (milliseconds)
* and maxTime (milliseconds)
*/
void goForwardRandom(int minTime, int maxTime){
int forwardTime = random(minTime,maxTime); //determine a random time to
//go forward
goForward(); //sets the SERB forward
delay(forwardTime); //delays for random time period
}
//------------------------------------------------------------------------
//START OF ARDUINO CONTROLLED SERVO ROBOT (SERB) ROUTINES
/*
* sets up your arduino to address your SERB using the included routines
*/
void serbSetup(){
setSpeed(speed);
pinMode(LEFTSERVOPIN, OUTPUT); //sets the left servo signal pin
//to output
pinMode(RIGHTSERVOPIN, OUTPUT); //sets the right servo signal pin
//to output
leftServo.attach(LEFTSERVOPIN); //attaches left servo
rightServo.attach(RIGHTSERVOPIN); //attaches right servo
goStop();
}
/*
* sets the speed of the robot between 0-(stopped) and 100-(full speed)
* NOTE: speed will not change the current speed you must change speed
* then call one of the go methods before changes occur.
*/
void setSpeed(int newSpeed){
if(newSpeed >= 100) {newSpeed = 100;} //if speed is greater than 100
//make it 100
if(newSpeed <= 0) {newSpeed = 0;} //if speed is less than 0 make
//it 0
speed = newSpeed * 0.9; //scales the speed to be
//between 0 and 90
}
/*
* sends the robot forwards
*/
void goForward(){
leftServo.write(90 + speed);
rightServo.write(90 - speed);
}
/*
* sends the robot backwards
*/
void goBackward(){
leftServo.write(90 - speed);
rightServo.write(90 + speed);
}
/*
* sends the robot right
*/
void goRight(){
leftServo.write(90 + speed);
rightServo.write(90 + speed);
}
/*
* sends the robot left
*/
void goLeft(){
leftServo.write(90 - speed);
rightServo.write(90 - speed);
}
/*
* stops the robot
*/
void goStop(){
leftServo.write(90);
rightServo.write(90);
}
//END OF ARDUINO CONTROLLED SERVO ROBOT (SERB) ROUTINES
//---------------------------------------------------------------------------
I also got my sensor to detect walls seperately but when i add both codes together i get an error...
So far my robot just drives and makes right turns...
can anyone help me with adding a code to this one that will allow my sensors to detect walls. and when it detects the wall it can turn a different direction..im sooo lost !!!
Would the code for the $50 dollar work if i upload it using arduino software?
-
hmm i dont be leave so i be leave the 50$ robot uses C++ or something like that try modified the server example from the sketch book..
// Sweep
// by BARRAGAN <http://barraganstudio.com>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
but our you using modified servos or what?
if so you can use this thing me and my firend found that allows you to control more than 2 servos on the arduino with no shield.
http://www.arduino.cc/playground/uploads/Main/ServoTimer2.zip (http://www.arduino.cc/playground/uploads/Main/ServoTimer2.zip)
place it in the arduino015 folder (Or what ever you have) and under hardware then library's.
Although you need to use timing for this library but that's not a big problem
ONE MORE THING!~
Me and my friend our building something similar!
using 3 servos and a ping)) ultrasonic range finder but also a PS3 controller for another mode!
MORE INFO CAN BE FOUND HERE!
http://www.societyofrobots.com/member_tutorials/node/224 (http://www.societyofrobots.com/member_tutorials/node/224)