11-20-2011 11:21 AM
Hello All.
I am using state machines to control a robot. The robot detects mines. There are two modes. One mode is when it is searching for mines and the other is when it detects a mine. When it is in the first mode (that is searching for a mine) i have programmed it to follow a square trajectory. when it detects the mine the state machine changes to the other mode because of a difference in sensor reading. Then it follows a swerve around routine to avoid the mine.
My problem is that when it has swerved around the state turns back to the first one and it starts from the beginning ( that is it starts the square trajectory from the beginning) i want it to start from the same point where the state was changed so that more or less the same trajectory is mantained.
11-20-2011 11:53 AM
Hi Asad,
Use a shift register to pass the robot's current position between states. Initialize the shift register with the beginning position, so that when you enter the initial "search" state, you are starting at the beginning. Then write the current position to the shift register when you change states. Now, when you re-enter your "search" state after swerving around the mine, the starting position will be the robot's position after swerving around the mine.
Is that close to what you want? If you want to start from where the robot was previous to swerving around the mine (which seems pointless since the robot would just have to swerve around the mine again, but maybe I'm missing something), wire the shift register straight through the "swerve" state. Now the starting position when you re-enter the "search" state will be the same position as it was when you left the "search" state.
Hope that helps,
Diane
11-20-2011 11:57 AM
Asad,
You need to find a means of recording the position of the robot at the time it changes modes. The best way to do this may depend on how your program is structured. With a state machine, the easiest way might be a shift register. If you have separate state machines for the two modes, are they in different subVIs? For that case a queue or Action Engine might be appropriate.
Lynn
11-20-2011 12:12 PM
Thank you Diane and Lynn.
Diane what you said would be the obvious choice if i was using motor angles to calculate the distance i have to run. I am using Motor run block sets. that make the robot move a specific distance. then a combination of different blocks completes the square trajectory. I am refering to the NXT motor blocksets. so there are two states. the swerve around routine is working fine. However in the search mode. i have lets say three blocks. one makes the robot go 1.5 meter straight. then another block steers it. then it again moves 1.5 meter. Now when my mine is in between these 1.5 meter runs. i want it to start from the same point where it swtiched states. and then move onto the next two block. or atleast move to the next two blocks rather than start from beginning. i was wondering if there is some sort of flag that can be used to tell that this where the states were switched and when the flow comes back it starts from that flag rather than from beginning.
11-20-2011 12:22 PM - edited 11-20-2011 12:23 PM
I actually did cover that question in my answer. Read the second paragraph again. To illustrate, here is a very simplified example:
The last position of the robot will be written to the shift register before the state change.
The value of the last robot position will remain unchanged in the "swerve" state, so that when the code returns to "search", the starting position is the same as where it left off.
Does that clarify?
Diane