SparkFun Inventor's Kit for RedBot Programming Issue

Hello. I am new to arduino. I got the bot to work (driving forward using encoders, using the bump sensors, etc…) but I cannot get them to work together. I want the following outcome: once I press the button, the bot will drive straight (encoders) and will use the bump sensors. It might just be a simple fix. I tried using some code that the site provided. Here is my current code…

CODE: https://pastebin.com/9h6sjcHF

Please let me know if you need any more info. Thank you in advance.

What’s the issue? Are you getting errors? Can you provide video of what you’re robot is performing?

With my current code, the bot starts driving (once the button is pressed) and the encoders are working (if 1 wheel is getting more rotations, it slows it down). I cannot figure out how to make the bump sensors work with the encoders. I have also tried using just the bump sensors, and it also works. I’m just having trouble getting the encoders and bump sensors to both work.

So I gather that you’re not getting compilation errors. Are the bump triggers not triggering while the bot moves?

I’m assuming so. I think I have to add the bump sensors into driveForward(), but not sure.

CODE: https://pastebin.com/9h6sjcHF

So there are a few things that may need to be fixed in your code:

  • Why are your drive functions listed inside your loop() function? I would suggest listing them outside of the loop.

  • The IF loop that tests the bumpers isn’t nested in your while loop (where all your drive commands are). The program will enter the while loop and perform the listed actions until the false condition is met. Then it’ll pop out and enter the if loop if the bumpers trigger the low state.

  • I would use the hookup guide example as a good starting point to compare your code to. https://learn.sparkfun.com/tutorials/ge … 88#example