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?
Thanks,
Sid
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
2 Likes
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.
5 Likes
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.
The wait until
is redundant.
3 Likes
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.
*/
1 Like