To state the obvious, it would be pretty unsuccessful for TurtleBot to deliver the Keurig to someone and then have it start driving off while the original person is still brewing coffee.

To fix this, we’ll make sure TurtleBot waits for the original person to tell it that they are finished before it can drive away. Luckily the Kobuki base comes with three programmable buttons: B0,B1 and B2.

B0 Button

We’ll use B0 as the “TurtleBot, I’m finished making coffee… do what you will” button. This leads us to the next challenge: How do we monitor when the buttons are pressed?

Monitoring Button Events

On TurtleBot open a terminal and run:

roslaunch turtlebot_bringup minimal.launch

On the workstation run:

cd ~/helloworld
python kobuki_buttons.py

Now try pressing B0.

Kobuki Button Events

Let’s have a look at the code.

gedit kobuki_buttons.py

You can also view it on GitHub if you prefer.

CREDIT: This script was inspired by Yujin Robot’s test_events.py script.

Interestingly enough, the code is almost identical to the battery monitoring scripts. You simply subscribe to the button event thread and the callback function is called every time an event occurs.