Driving based on range?

Hello -

I’ve written a quick snippet for Autonomous which should drive the robot at 0.65 until the rangefinder reads somewhere less than a given number. In this example, I’ve entered an arbitrary value of 60.

I’ve placed the drive within a loop, running every 20ms. Once the rangefinder reads a value less than 60, it is set to stop the While loop.

My question is do I need to feed the motors a value of 0 after the While loop is stopped, or don’t I? See the attached image.

Thanks, Dom

To answer the direct question, no. You do not need to worry about feeding motors more than one zero. The safety will kick in and set them to zero as well, but there is no harm and no need.

But. I looked at your code, and it doesn’t do what you describe.

The loop that reads the ultrasound will not exit until the value from it is greater than 39.75 units – not sure what the units are. Then it will start the motors at .65 and will no longer read the ultrasonic. I suspect that the initial state of the motors is zero, so the robot may not move at all.

Remember that data doesn’t leave a loop via a wire until the loop finishes, and if you want two loops to run in parallel, you can’t have wires between them.

I attached a picture of some code for comparison that looks at the ultrasonic and sets the motors to either 0.65 or 0.0, and stops the loop when the limit is reached. The sequence says that the other stuff starts only after the loop is complete.

Greg McKaskle

Screen Shot 2012-03-03 at 5.02.41 PM.png

Screen Shot 2012-03-03 at 5.02.41 PM.png

Take two. I changed things up a bit, and added a timed stop in case the rangefinder doesn’t work as well as expected. It quits the loop after 10 seconds.

Much better. I notice you put in a delay, where I forgot to. Good for you.

Your bottom logic where you turn Booleans into numbers and add them will work, but you may want to look into the Boolean logic palette. OR is equivalent to what you’ve written and is the more traditional way of doing this. Again, yours works, I’m just suggesting ways to make it more professional.

Now to test it.
Greg McKaskle

Man, I’ve been searching for that OR function for 8 weeks now, and it’s been answered in a passing suggestion! Thanks!

I’m going to see if I can’t hook up our second cRIO to some hardware and test it this coming Monday, but if not, I’ll have to test it in the pit at WPI. No big deal.

Thanks for your help.