Saturday, February 28, 2015

Old Dog, New Trick

Now that Robie's bumper sensor is wired up, I felt I should add some code to make it functional. For the most part the control logic is the same. But now when the bump sensor activates I stop the motors from going forward until they have gone in reverse first. This prevents the wheels from spinning constantly as Robie is inevitably steered in to a wall or some other inanimate object. Additionally his eyes will turn purple. Why? Because why not. Also you ask too many questions :-P

Here's how this looks in action:

It's a bit dicey without the cover on. Unfortunately the cover is part of what holds the bumper in place. So it pops off quite easily. But I managed to at least take that video.

Here's a diff for the additional code:

As you can see there's not really much to it. I set up the pins for the bumper and the other switches (which don't really do anything yet). Then I set up 2 global variables to specify when the bumper is tripped. Why two? Because I want to ensure both motors are stopped individually. That way I know both have gone in reverse so I can reactivate the forward motion.

The main work is done in the bumper_pressed_callback function. The callback is triggered by an interrupt. So the code will continue looping until the bumper is pressed. Then the callback gets triggered and does its magic.

No comments:

Post a Comment