Note: This tutorial assumes that you have completed the previous tutorials: Creating Packages.
(!) Please ask about problems and questions regarding this tutorial on Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Using the Buttons

Description: This tutorial shows how to access the state of the buttons on Mini Maxwell

Tutorial Level: BEGINNER

Next Tutorial: Moving the Base


There are two buttons on Mini Maxwell, which are easily accessible through ROS.

Under the Hood

This section describes what is happening at a low-level, feel free to skip past it.

Both buttons are connected through the ArbotiX2, as digital inputs. Due to the way they are wired, the buttons are at 5V when unpressed, and pressing the button changes the level to 0V. The ArbotiX uses 8-bit values to encode the voltages, which means that 0V = 0, and 5V = 255 (the largest value which can be stored in an unsigned 8-bit data type).

The Topics

The buttons broadcast on two topics:


You can see the output using the rostopic tool:

$ rostopic echo /arbotix/green_button
  seq: 59
    secs: 1307850081
    nsecs: 213567018
  frame_id: ''
value: 255
direction: 0
  seq: 60
    secs: 1307850081
    nsecs: 296992063
  frame_id: ''
value: 0
direction: 0

Each topic is output at approximately 5 hz. A value of 0 means that the button is pressed, while 255 means it is not. The direction will always be 0 (an input).

Reading the Button State in Python

We will now create a simple program to read the state of the buttons. You should create a package called 'button_test' using roscreate-pkg, be sure to add a dependency on the 'arbotix_msgs' which contains the message definition we will need for reading the buttons. Alternatively, you can find this code in the mini_max_tutorials package.

Then open the file '' in the editor of your choice, and enter the following:

Could not fetch external code from '': HTTP Error 404: Not Found

Mark the file executable:

chmod +x

And then run it:

rosrun button_test

You should then see a message posted that the button is pressed whenever you press it!

Wiki: mini_max/Tutorials/Using the Buttons (last edited 2011-10-18 19:44:03 by MichaelFerguson)