RMOAR - On construction
Hello to everyone this is my first robot here in LMR but i haven't finished it yet .
I call RMOAR because its letter is one of its functions it means : Remote Monitored Obstacle Avoidance Robot
Its basic function was to avoid every obstacle in his way but then i decided to remake in order to follow objects with a certain
color and in his way to the object he will also avoid any obstacle.
And i have some photos of it in its current state and some from the first states of it.
I wrote some code but i dont think that its goin to work and i need some help in order to improve it.
(UPDATE: 21/2/11)Here is the new code I made:
#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
int V1,V2,D1,D2;
int sensorPin1 = 5;
int sensorPin2 = 4;
int servoL = 9;
int servoR = 10;
int servoScn = 11;
int ledPin = 13;
int sensorValue1 = 0;
int sensorValue2 = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(sensorPin1,INPUT);
pinMode(sensorPin2,INPUT);
pinMode(servoL,OUTPUT);
pinMode(servoR,OUTPUT);
pinMode(servoScn,OUTPUT);
servo1.attach(servoL);
servo2.attach(servoR);
servo3.attach(servoScn);
Serial.begin(9600);
}
void loop() {
Schfobj();
while(Schfobj() == 0){
moveForward(100);
if(Schfobj() != 0){
continue;
}
}
if(Schfobj() == 1){
moveRight(170,2500);
}
if(Schfobj() == 2){
moveLeft(170,2500);
}
if(Schfobj() == 3){
moveBackward(170,2500);
}
}
int Schfobj() {
for(int i = 0; i < 180; i = i + 1){
V1 = analogRead(sensorPin1);
V2 = analogRead(sensorPin2);
D1 = (6787 / (V1 - 3)) - 4;
D2 = (6787 / (V2 - 3)) - 4;
servo3.write(i);
delay(50);
Serial.print("Distance 1 : " + D1);
Serial.println(" Distance 2 : " + D2);
if(i <= 90 && (D1 < 15 || D2 < 15)){
return 1;
}
else if(i >= 180 && (D1 < 15 || D2 < 15)){
return 2;
}
else if( i == 90 && (D1 < 15 || D2 < 15)){
return 3;
}
else {
return 0;
}
}
}
void moveLeft(int Speed , int Delay){
servo1.write(Speed - 91);
delay(Delay);
servo2.write(Speed);
delay(Delay);
}
void moveRight(int Speed,int Delay){
servo1.write(Speed);
delay(Delay);
servo2.write(Speed - 91);
delay(Delay);
}
void moveForwardd(int Speed,int Delay){
servo1.write(Speed);
delay(Delay);
servo2.write(Speed);
delay(Delay);
}
void moveBackward(int Speed,int Delay){
servo1.write(Speed - 91);
delay(Delay);
servo2.write(Speed - 91);
delay(Delay);
}
void moveForward(int Speed){
servo1.write(Speed);
servo2.write(Speed);
}
It passes the Compile but if anyone can test it for logical mistakes it could be helpfull.
It will follow objects with certain colors and in its way to the object it will avoid any obstacle and it is also remote monitored by a pc (it will have and rc mode)
- Actuators / output devices: 2 x Parallax (Futaba) Continuous Rotation Servo and one standard 180 degrees servo.
- Control method: autonomously controlled by onboard microcontroller and digital wireless connection from Windows System with xbee modules(900mhz)
- CPU: It uses an atmega 328 on an arduino duemilanove.
- Operating system: windows XP
- Power source: 7.2 volt 1800 mAh Ni-cd
- Programming language: Wiring(some kind of c and c++ for microcontrollers)
- Sensors / input devices: It uses 2 x Sharp GP2Y0A02YK0F and one ColorPal from Parallax .
- Target environment: indoor flat surfaces