Hi again,
The BRAT with a PixyCam is coming along nicely. It tracks and goes to certain objects now and avoids walls with a Sharp IR sensor. Now what I’m trying to do is when it gets to certain objects have it go into a “resting” position (legs bent). I wrote the code for the group move and included it in the loop. It does the movement when it’s supposed to, but immediately goes back to straight legs. How would I write the code to stay in the resting position until an input changes?
We don’t have details on your actual code but state machine would probably be the way to go.
void loop(void)
{
// Some code here to select actual mode
mode = getRobotModeFucntion();
switch(mode)
{
case MODE_FORWARD:
//move forward sequence
break;
case MODE_BACKWARD:
//move backward sequence
break;
case MODE_RESTING:
// Rest sequence
break;
// Other possible modes
default:
break;
}
}
Thanks, I had read a little about that (case, break, etc) but wasn’t sure if it would help or not. I’ll try to read up more on it tonight and give it a try.
Ok, quick update. You were right about the state machine. I tried using multiple ideas with a state machine, some of them got the robot to hold it’s position. However, all of them screwed up the rest of the code so the robot wouldn’t function properly. My most current code was using a simple state machine <SM.h> from the arduino playground files. I’ll keep working on it.
Happy to know things are moving forward. The trick about using stage machines is not blocking the code inside a state ( with whiles and other…) so that you keep running all your code required outside.