I know I could be going about this all wrong but I'm trying to make and antonymous rover and its not working great, I need some ideas on how to make the code a little more efficient. I have be programming in vb.net for years but I am new to c++.
That's definitely not great in the photo. It's all blurry! (Do you have daylight where you are? Put it near a window and get a better photo that way.)
void loop() {
currentMillis = millis();
DoPing();
if (turning == false){
scan();
}
if (turning == false){
drive();
}
}
How does turning become false? If it somehow accidentally gets set to true, then this does not drive and does not scan. DoPing() doesn't seem to be updating that variable.
You have not told us what the code actually does and what you would like it to do.
"It's not working great" suggests to me that it is generally doing ALL that it is supposed to do, but not as well as you would like. What improvement in behaviour do you want ?
All variables associated with millis() are best defined as unsigned long. You have some of them as long which can have negative values that may confuse things.
making a autonomous rover, right now im working on obstacle avoidance. turning right or left if it needs to avoid something. also kind of curious is my code is well written or if its sloppy .etc
johnbrodowski:
making a autonomous rover, right now im working on obstacle avoidance. turning right or left if it needs to avoid something. also kind of curious is my code is well written or if its sloppy .etc
Your code looks reasonable - but the real test is whether it does what you want. And you have not told us, nor have you told us what you would like it to do better.
Please edit your original post to remove all the irrelevant (and confusing) bold text.
Ok basically i just want to get it to turn left or right if it cant go straight. its doing what I want to an extent its just not doing it well.
in the end my goal it to have it roam around on its own. ie turn until it can go forward, remember and retrace a path stuff like that, but for now I'm just trying to get it to do the basics
johnbrodowski:
Ok basically i just want to get it to turn left or right if it cant go straight. its doing what I want to an extent its just not doing it well.
Computer programming, and especially debugging, requires much more specific information than "doing what I want to an extent its just not doing it well"
If you can't explain the problem I can't help with a solution.
Well currently the main issue I am having is getting it to turn the right way when it approaches an object. Sometimes it turns towards an obstacle and other times it turns away.
johnbrodowski:
Well currently the main issue I am having is getting it to turn the right way when it approaches an object. Sometimes it turns towards an obstacle and other times it turns away.
And you've got proof that that behaviour is related to the speed and efficiency of the code?
no not exactly but when i turn it on and set it free the servo for the sonar tends to stop and the stepper will do the same thing and they kind of do it at the same time. It's buggy