I am trying to make my robot move back, turn left, and move forward upon hitting an obstacle. The link for the code is as follows.
The problem is that the robot keeps spinning when it supposed to only turn once and move forward again. Can you tell me why this might be happening and what could be a fix if there is a code issue?
I don’t see an issue with your code other than you can remove the ‘Wait Until’. The program is locked in the drive loop until a bumper is pushed so there isn’t a need to check if the bumper is pushed a second time.
The rest looks correct to me. Good call, @holbrook
The inertial sensor should be configured as part of the drivetrain rather than as a separate device, if you want to use the “turn to rotation” and “turn to heading” blocks.
So what should I use instead of a wait until?
I used an if instead of a wait until and a turn left instead of the rotate and it worked thanks for the help.
You don’t need that line. The program will stay in the while (not bumper) loop until it hits a bumper. Then it will continue on and run the turn maneuver. Once it does the turn it will resume the for 3 times outer loop.
wait until is redundant.
To be perfectly clear, the
wait until bumper pressed is completely unnecessary, as @Hudsonville_Robotics said:
Your code says
while not bumper pressed:
// do whatever
// it exits the loop when a bumper IS pressed
wait until bumper pressed
/* it does not exit the loop until a bumper is pressed,
so afterward you don't need to wait until a bumper is pressed;
it already will be and you know that for certain.