Hello, recently had some time to jump back on my robot project.
Currently I have code written using my ping sensors for object avoidance (also another code I can load using a webcam to follow an object of certain color). Although as of now I've removed the cheap webcam and I'm starting to use my Kinect (on head of robot).
My code, as of right now, is very disorganized and also have seperate code to do different things..
I thought I'd write down a kind of code structure I was thinking about trying, along with a few questions.
*No complete or compiling code atm...just some functons as well as trying the best way to implement them into one program (hope this is OK).
Also, for the moment won't bother/focus on data recieved from the Kinect here. Using the webcam, Roborealm and the help of Paul a while back I've managed to get data from the PC to the Arduino and think I have that covered..
Giving a recap of what is going on, or what I'd like to aim for:
-Gather the incoming data from 4 ping sensors. In front of the bot there are 3 sensors: 1 center aiming straight forward and 2 on either side facing outward. Also 1 ping sensor in the rear facing straight backwards.
-depending on the current distance of the center and 2 outer ping sensors; speed up, slow down and turn motors in a direction where there are no obstructions. When turning, turn toward the direction of the greatest ping distance value, etc...
-Use an increase and decrease speed function for the motors (so starting from neutral or a fast speed to stop isn't so hard on the motors).
I may add something I may have forgotten while posting this.
I've been looking into different statements/methods of doing this.
Using the while some condition is happening, keep doing something else(along with the break statement). If there is a change in a value(s) do another thing...
This will probably end up being a long while, if mess of code.
Another is using the switch statement using different cases (depending on certain values...i.e ping distances).
Here are some of the functions I thought about using inside the code:
moveForward();
moveBackward();
moveLeft();
moveRight();
motorsStop();
decreaseSpeed();
increaseSpeed();
pingRange(); //distance data from ping sensor calculations
kinectData(); //maybe get to this a bit later.
Q1: Is this a good way to use decrease and increase speed as separate functions or should I incorporate them into each movement function (forward, backward, left, etc...)?
Q2: Reading back in my C++ book. It states there are 3 forms of function calls which I'm still trying to wrap my head around:
void blink1(){
}
The above is where blink1 has no parameter and no return value. So 'parameter' would be some range of values? *ok, parameter could be a variable?
Also, no return value? If this function is placed/called in the main loop, doesn't this function calculate some value and injects it into the main loop?
void blink2(int count){
}
Above states that blink2 takes a single parameter but does not return a value.
So the variable int count is the parameter and is calculated within the void blink2(int count) function?
*Ok, just thought of something on returning a value... It doesn't return a value to void blink2(int count) or it's own function?
int blink3(int period){
}
The above is the 3rd form.
Any help understanding the forms of the above functions a little better would be much appreciated.
I know I had a few more questions from my notes. I'll try and add them to this post asap.
t