ros_serial for mbed updated to work with ROS Hydro. Library still needs to be debugged
Library and program still under development!
examples/Button_example.cpp@0:cb1dffdc7d05, 2015-02-15 (annotated)
- Committer:
- akashvibhute
- Date:
- Sun Feb 15 10:54:04 2015 +0000
- Revision:
- 0:cb1dffdc7d05
Error: ; "mbed::Stream::Stream(const mbed::Stream &)" (declared at <a href="#" onmousedown="mbed_doc_goto('/mbed_roshydro_test//extras/mbed_e188a91d3eaa/Stream.h', '59'); return false;">/extras/mbed_e188a91d3eaa/Stream.h:59</a>) is inaccessible in "ext
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akashvibhute | 0:cb1dffdc7d05 | 1 | //#define COMPILE_BUTTON_EXAMPLE_CODE_ROSSERIAL |
akashvibhute | 0:cb1dffdc7d05 | 2 | #ifdef COMPILE_BUTTON_EXAMPLE_CODE_ROSSERIAL |
akashvibhute | 0:cb1dffdc7d05 | 3 | |
akashvibhute | 0:cb1dffdc7d05 | 4 | /* |
akashvibhute | 0:cb1dffdc7d05 | 5 | * Button Example for Rosserial |
akashvibhute | 0:cb1dffdc7d05 | 6 | */ |
akashvibhute | 0:cb1dffdc7d05 | 7 | |
akashvibhute | 0:cb1dffdc7d05 | 8 | #include "mbed.h" |
akashvibhute | 0:cb1dffdc7d05 | 9 | #include <ros.h> |
akashvibhute | 0:cb1dffdc7d05 | 10 | #include <std_msgs/Bool.h> |
akashvibhute | 0:cb1dffdc7d05 | 11 | |
akashvibhute | 0:cb1dffdc7d05 | 12 | |
akashvibhute | 0:cb1dffdc7d05 | 13 | ros::NodeHandle nh; |
akashvibhute | 0:cb1dffdc7d05 | 14 | |
akashvibhute | 0:cb1dffdc7d05 | 15 | std_msgs::Bool pushed_msg; |
akashvibhute | 0:cb1dffdc7d05 | 16 | ros::Publisher pub_button("pushed", &pushed_msg); |
akashvibhute | 0:cb1dffdc7d05 | 17 | |
akashvibhute | 0:cb1dffdc7d05 | 18 | DigitalIn button_pin(p8); |
akashvibhute | 0:cb1dffdc7d05 | 19 | DigitalOut led_pin(LED1); |
akashvibhute | 0:cb1dffdc7d05 | 20 | |
akashvibhute | 0:cb1dffdc7d05 | 21 | bool last_reading; |
akashvibhute | 0:cb1dffdc7d05 | 22 | long last_debounce_time=0; |
akashvibhute | 0:cb1dffdc7d05 | 23 | long debounce_delay=50; |
akashvibhute | 0:cb1dffdc7d05 | 24 | bool published = true; |
akashvibhute | 0:cb1dffdc7d05 | 25 | |
akashvibhute | 0:cb1dffdc7d05 | 26 | Timer t; |
akashvibhute | 0:cb1dffdc7d05 | 27 | int main() { |
akashvibhute | 0:cb1dffdc7d05 | 28 | t.start(); |
akashvibhute | 0:cb1dffdc7d05 | 29 | nh.initNode(); |
akashvibhute | 0:cb1dffdc7d05 | 30 | nh.advertise(pub_button); |
akashvibhute | 0:cb1dffdc7d05 | 31 | |
akashvibhute | 0:cb1dffdc7d05 | 32 | //Enable the pullup resistor on the button |
akashvibhute | 0:cb1dffdc7d05 | 33 | button_pin.mode(PullUp); |
akashvibhute | 0:cb1dffdc7d05 | 34 | |
akashvibhute | 0:cb1dffdc7d05 | 35 | //The button is a normally button |
akashvibhute | 0:cb1dffdc7d05 | 36 | last_reading = ! button_pin; |
akashvibhute | 0:cb1dffdc7d05 | 37 | |
akashvibhute | 0:cb1dffdc7d05 | 38 | while (1) { |
akashvibhute | 0:cb1dffdc7d05 | 39 | bool reading = ! button_pin; |
akashvibhute | 0:cb1dffdc7d05 | 40 | |
akashvibhute | 0:cb1dffdc7d05 | 41 | if (last_reading!= reading) { |
akashvibhute | 0:cb1dffdc7d05 | 42 | last_debounce_time = t.read_ms(); |
akashvibhute | 0:cb1dffdc7d05 | 43 | published = false; |
akashvibhute | 0:cb1dffdc7d05 | 44 | } |
akashvibhute | 0:cb1dffdc7d05 | 45 | |
akashvibhute | 0:cb1dffdc7d05 | 46 | //if the button value has not changed for the debounce delay, we know its stable |
akashvibhute | 0:cb1dffdc7d05 | 47 | if ( !published && (t.read_ms() - last_debounce_time) > debounce_delay) { |
akashvibhute | 0:cb1dffdc7d05 | 48 | led_pin = reading; |
akashvibhute | 0:cb1dffdc7d05 | 49 | pushed_msg.data = reading; |
akashvibhute | 0:cb1dffdc7d05 | 50 | pub_button.publish(&pushed_msg); |
akashvibhute | 0:cb1dffdc7d05 | 51 | published = true; |
akashvibhute | 0:cb1dffdc7d05 | 52 | } |
akashvibhute | 0:cb1dffdc7d05 | 53 | |
akashvibhute | 0:cb1dffdc7d05 | 54 | last_reading = reading; |
akashvibhute | 0:cb1dffdc7d05 | 55 | |
akashvibhute | 0:cb1dffdc7d05 | 56 | nh.spinOnce(); |
akashvibhute | 0:cb1dffdc7d05 | 57 | } |
akashvibhute | 0:cb1dffdc7d05 | 58 | } |
akashvibhute | 0:cb1dffdc7d05 | 59 | #endif |