- Thu Dec 30, 2010 3:26 pm
#116368
Selenaut,
Several, but I'll start with a firm suggestion that you define a few drive functions so my brain doesn't hurt so much and I can follow what you're doing. For example:
I also suggest you move the division by 10 inside the heading function. That will shorten the code a bit and reduce the risk that you'll forget to do the division. Note that moving the division inside will change the data type of what the function returns. You can avoid that by rounding or truncating the quotient inside the heading function. (It seems unlikely that tenths of a degree are relevant at this point.)
It's not clear to me what you were trying to do with the multiple turns and how they are supposed to differ from each other. If you've prepared a flow chart or some other description of what you're trying to do, please share it.
Also, you do not appear to have addressed compass wraparound for all of your turns.
Good Luck,
Eric
[/color]
Several, but I'll start with a firm suggestion that you define a few drive functions so my brain doesn't hurt so much and I can follow what you're doing. For example:
Code: Select all
Then, replace each of the blocks of digitalWrite commands with a call to the appropriate drive function. That will make the code much shorter and much easier to read. (When you get around to learning about PWM speed control, you can change each drive function to take a speed argument.)void botForward () {
digitalWrite(3, HIGH); //And these
digitalWrite(5, LOW); //four are to
digitalWrite(6, LOW); //get them to
digitalWrite(9, HIGH); //go forward.
}
void botStop () {
digitalWrite(3, LOW); //stop both motors
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(9, LOW);
}
void botRight () {
digitalWrite(3, HIGH); //turns right
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(9, LOW);
}
I also suggest you move the division by 10 inside the heading function. That will shorten the code a bit and reduce the risk that you'll forget to do the division. Note that moving the division inside will change the data type of what the function returns. You can avoid that by rounding or truncating the quotient inside the heading function. (It seems unlikely that tenths of a degree are relevant at this point.)
It's not clear to me what you were trying to do with the multiple turns and how they are supposed to differ from each other. If you've prepared a flow chart or some other description of what you're trying to do, please share it.
Also, you do not appear to have addressed compass wraparound for all of your turns.
Good Luck,
Eric
[/color]