Permalink
Browse files

Initial commit for TurtleBot button control

  • Loading branch information...
1 parent 2967c94 commit fe1ce0a8fa1f09c27319a24a8a0ff6df17c33546 linda committed Jun 29, 2012
@@ -0,0 +1,5 @@
+
+bin/
+build/
+msg_gen/
+src/
@@ -0,0 +1,30 @@
+cmake_minimum_required(VERSION 2.4.6)
+include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
+
+# Set the build type. Options are:
+# Coverage : w/ debug symbols, w/o optimization, w/ code-coverage
+# Debug : w/ debug symbols, w/o optimization
+# Release : w/o debug symbols, w/ optimization
+# RelWithDebInfo : w/ debug symbols, w/ optimization
+# MinSizeRel : w/o debug symbols, w/ optimization, stripped binaries
+#set(ROS_BUILD_TYPE RelWithDebInfo)
+
+rosbuild_init()
+
+#set the default path for built executables to the "bin" directory
+set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
+#set the default path for built libraries to the "lib" directory
+set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
+
+#uncomment if you have defined messages
+rosbuild_genmsg()
+#uncomment if you have defined services
+rosbuild_gensrv()
+
+#common commands for building c++ executables and libraries
+#rosbuild_add_library(${PROJECT_NAME} src/example.cpp)
+#target_link_libraries(${PROJECT_NAME} another_library)
+#rosbuild_add_boost_directories()
+#rosbuild_link_boost(${PROJECT_NAME} thread)
+#rosbuild_add_executable(example examples/example.cpp)
+#target_link_libraries(example ${PROJECT_NAME})
@@ -0,0 +1 @@
+include $(shell rospack find mk)/cmake.mk
@@ -0,0 +1,10 @@
+There is a 30 second delay before the correct messages are sent.
+
+Add the header file for Button.msg to Arduino libraries:
+rosrun rosserial_client make_library.py PATH_TO_ARDUINO_LIBRARY turtlebot_button
+
+To run:
+
+1) Upload buttons_turtlebot.ino onto an Arduino.
+2) Run the rosserial client that forwards the message to the rest of ROS:
+ rosrun rosserial_python serial_node.py USB_PORT
@@ -0,0 +1,88 @@
+#include <ros.h>
+#include <vector>
+#include <turtlebot_button_op/Buttons.h>
+
+ros::NodeHandle nh;
+
+turtlebot_button_op::Buttons button_msg;
+ros::Publisher pub_button("buttons", &button_msg);
+
+const int num_buttons = 5;
+
+int button0 = 8;
+int button1 = 9;
+int button2 = 10;
+int button3 = 11;
+int button4 = 12;
+
+bool last_button_state[num_buttons];
+int last_debounce_time[num_buttons];
+int debounce_delay = 50;
+bool published = true;
+bool updated = false;
+
+int i;
+
+void setup() {
+ nh.initNode();
+
+ pinMode(button0, INPUT);
+ pinMode(button1, INPUT);
+ pinMode(button2, INPUT);
+ pinMode(button3, INPUT);
+ pinMode(button4, INPUT);
+
+ // Allocate space for button states
+ button_msg.button_state_length = num_buttons;
+ button_msg.button_state = (bool *) malloc(sizeof(bool) * num_buttons);
+
+ // Get initial button state
+ for (i = 0; i < num_buttons; i++) {
+ // Buttons are normally low.
+ last_button_state[i] = digitalRead(button0+i);
+ last_debounce_time[i] = 0;
+
+ button_msg.button_state[i] = last_button_state[i];
+ }
+
+ nh.advertise(pub_button);
+}
+
+void loop() {
+ int reading[num_buttons];
+
+ for (i = 0; i < num_buttons; i++) {
+ reading[i] = digitalRead(button0+i);
+ }
+
+
+ for (i = 0; i < num_buttons; i++) {
+ if (reading[i] != last_button_state[i]) {
+ last_debounce_time[i] = millis();
+ published = false;
+ updated = true;
+ }
+ }
+
+ for (i = 0; i < num_buttons; i++) {
+ // Store stable button values
+ if (!published && (millis() - last_debounce_time[i]) > debounce_delay) {
+ button_msg.button_state[i] = reading[i];
+ }
+ }
+
+ // Publish updated button message
+ if (updated && !published) {
+ pub_button.publish(&button_msg);
+ published = true;
+ }
+
+ // Update last button state
+ for (i = 0; i < num_buttons; i++) {
+ last_button_state[i] = reading[i];
+ }
+
+ updated = false;
+
+ nh.spinOnce();
+}
@@ -0,0 +1,26 @@
+/**
+\mainpage
+\htmlinclude manifest.html
+
+\b turtlebot_button is ...
+
+<!--
+Provide an overview of your package.
+-->
+
+
+\section codeapi Code API
+
+<!--
+Provide links to specific auto-generated API documentation within your
+package that is of particular interest to a reader. Doxygen will
+document pretty much every part of your code, so do your best here to
+point the reader to the actual API.
+
+If your codebase is fairly large or has different sets of APIs, you
+should use the doxygen 'group' tag to keep these APIs together. For
+example, the roscpp documentation has 'libros' group.
+-->
+
+
+*/
@@ -0,0 +1,18 @@
+<package>
+ <description brief="turtlebot_button">
+
+ turtlebot_button
+
+ </description>
+ <author>linda</author>
+ <license>BSD</license>
+ <review status="unreviewed" notes=""/>
+ <url>http://ros.org/wiki/turtlebot_button</url>
+ <depend package="rosserial_arduino"/>
+ <depend package="rosserial_client"/>
+ <depend package="rosserial_msgs"/>
+ <depend package="rosserial_python"/>
+
+</package>
+
+
@@ -0,0 +1,2 @@
+
+bool[] button_state

0 comments on commit fe1ce0a

Please sign in to comment.