Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
else turn robot right)else turn robot left)else move robot forward)
this should help you understand servo programming better:http://www.societyofrobots.com/robotforum/index.php?topic=2724.0and you can't have three else statements in a row Quoteelse turn robot right)else turn robot left)else move robot forward)do something like:if IR detects object turn scannerelse robot turns that direction go straight
#include <Servo.h>Servo servo1;void setup() { pinMode(9,OUTPUT); servo1.attach(9); //servo1.setMaximumPulse(2000); //servo1.setMinimumPulse(700); servo1.write(700); int v = 700; int IRreading = 0; int movemode = 0;}void loop() { IRreading = analogRead(0); if(IRreading > 500) { //is this for no object? if it is, then scan left-to-right movemode = 1; } else { //object found movemode = 2; } if(movemode == 1) { v += 100; if(v>2000){ v = 2000; } servo1.write(v); } if(movemode == 2) { //set it to do something else, I just set it to scan right-to-left v -= 100; if(v<700){ v = 700; } servo1.write(v); } Servo::refresh();}
#include <Servo.h>Servo servoleft; Servo servoright; Servo scanner;int sensor = 0;int IRread1 = 0;int IRread2 = 0;int IRread3 = 0;int IRread4 = 0;int IRread5 = 0;int moveMode = 0;int scan = 0;int object = 0;void setup() { pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(0, INPUT); servoleft.attach(9); servoleft.setMinimumPulse(1100); servoleft.setMaximumPulse(1900); servoleft.write(1500); servoright.attach(10); servoright.setMinimumPulse(1100); servoright.setMaximumPulse(1900); servoright.write(1500); scanner.attach(11); scanner.setMinimumPulse(1100); scanner.setMaximumPulse(1900); scanner.write(1500); Serial.begin(9600); Serial.println("Ready to Rock 'n' Roll baby");}void loop() { scan = 1; //scan front if(object == 0){ moveMode = 1; } else if(object == 1) { //if object front then turn left Serial.println("Object in front"); moveMode = 2; scan = 1; //scan left if(object == 1) { //if object left then turn right 2 times(that means turn around) Serial.println("Object on the left"); moveMode = 3; moveMode = 3; scan = 1; //scan right if(object == 1); { //if object right then turn right once more(that means the robot is facing the opposite direction that at the start) Serial.print("Object on the right"); moveMode = 3; } } } if (scan == 1) { scanner.write(1376); //this whole group takes 5 readings IRread1 = analogRead(0); //from front of the robot scanner.write(1438); //and if any of tose readings IRread2 = analogRead(0); //detects and object then scanner.write(1500); //the programm tells the robot IRread3 = analogRead(0); //that there is an object :) scanner.write(1562); IRread4 = analogRead(0); scanner.write(1624); IRread5 = analogRead(0); if (IRread1 > 500 || IRread2 > 500 || IRread3 > 500 || IRread4 > 500 || IRread5 > 500) { object = 1; } else (IRread1 <= 500 || IRread2 <= 500 || IRread3 <= 500 || IRread4 <= 500 || IRread5 <= 500); { object = 0; } } if(moveMode == 1) { servoleft.write(1100); //move straight servoright.write(1900); } if(moveMode == 2) { servoleft.write(1900); // turn left for 0.6 seconds servoright.write(1900); delay(600); servoleft.write(1500); servoright.write(1500); } if(moveMode == 3) { servoleft.write(1100); //turn right for 0.6 seconds servoright.write(1100); delay(600); servoleft.write(1500); servoright.write(1500); }}
if(IRreading > 500) { //is this for no object? if it is, then scan left-to-right
#include <Servo.h>Servo servoleft; Servo servoright; Servo scanner;int IRsensor = 0;int scannerpos = 0;int IRread = 0;int leftedge = 0;int scan = 0;int moveMode = 0;void setup() { pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(0, INPUT); servoleft.attach(9); servoleft.setMinimumPulse(1100); servoleft.setMaximumPulse(1900); servoleft.write(1500); servoright.attach(10); servoright.setMinimumPulse(1100); servoright.setMaximumPulse(1900); servoright.write(1500); scanner.attach(11); scanner.setMinimumPulse(1100); scanner.setMaximumPulse(1900); scanner.write(1500); Serial.begin(9600); Serial.println("Ready To Rock 'n' Roll Baby");}void loop() { if(leftedge == 1) { scanner.write(1100); moveMode = 1; } else if(leftedge == 0) { scanner.write(1900); moveMode = 2; } if(scan == 1) { IRread = analogRead(0); moveMode = 3; if(IRread > 500) { leftedge = 1; } else if(IRread <= 500) { leftedge = 0; } } if(moveMode == 1) { servoleft.write(1100); servoright.write(1900); } else if(moveMode == 2) { servoleft.write(1900); servoright.write(1900); } else if(moveMode == 3) { servoleft.write(1100); servoright.write(1900); }}
scannerpos = scanner.writeif scanner.write(1900)then scannerpos would be 1900 aswellif scannerpos > 1500(neutral position of the servo)turn robot rightif scannerpos < 1500turn robot left
Again, I am impressed with your image . . . I assume you won't mind me putting this on the sharpIR tutorial?http://www.societyofrobots.com/robotforum/index.php?topic=2573.msg21176#msg21176Oh and you should invest in a good digital cam. I regret every day that I have limited and low quality video of my earlier robots
the black ones are the detectors. it looks like 1 might be burnt.
okey ppl i received my parts today(about time huh?) and now I'm trying to put it all together...as admin told me that i can post my software questions here too, I'm going to ask you some things:how can i make the servo turn clockwise for 1 second and then counterclockwise for 1 second and then again clockwise 1 second and so on, so on??? remember I'm using arduino, so its C++(or C, i don't really know)i believe it has something to do with millis() function, but because I've never used millis() before, i don't know how to use it.then secondly. how would you recommend me to make the robot scan? like scan from front and then sides and then make a decision? or scan from front and if there is an object then scan from the sides for a way to go?or o u ppl have any better ideas for me to use?i wanted to do something like this: scan from five different directions: far left, left, front, right, far right. then make a decision where to move and then scan again.but i think that this makes the robot to stop while it is scanning, but i want it to move and scan at the same time(of course if it is even possible)i really hope you can help me with this guys.oh and keep in mind that this is still my first robot, so be patient with me thank you.
Quote from: Admin on December 15, 2007, 04:30:00 PMThe $50 Robot (with ATmega168 upgrade) uses the same microcontroller as the Arduino. Code is the same.Nope, it actually isn't. The Arduino uses an own language, based on wiring. It's a whole different environment. Many things are predefined and made very easy. However, you could program it in the ordinary language.
The $50 Robot (with ATmega168 upgrade) uses the same microcontroller as the Arduino. Code is the same.
gcc plug-in: Error: Object file not found on expected location C:\Users\user\Desktop\irobot\iRobot.elfMake sure your makefile specifies the output .elf file as iRobot.elf
my avr studio always have this error:Quotegcc plug-in: Error: Object file not found on expected location C:\Users\user\Desktop\irobot\iRobot.elfMake sure your makefile specifies the output .elf file as iRobot.elf