GroveCollision.cpp
Go to the documentation of this file.
00001 /*
00002  * rosserial Collission Sensor Example
00003  *
00004  * This tutorial demonstrates the usage of the
00005  * Seeedstudio Collision Grove module
00006  * http://www.seeedstudio.com/wiki/Grove_-_Collision_Sensor
00007  *
00008  * Source Code Based on:
00009  * https://developer.mbed.org/components/Grove-Collision-Sensor/
00010  */
00011 
00012 #include "mbed.h"
00013 #include <ros.h>
00014 #include <std_msgs/Bool.h>
00015 
00016 ros::NodeHandle  nh;
00017 
00018 std_msgs::Bool collision_msg;
00019 ros::Publisher pub_collision("collision", &collision_msg);
00020 
00021 
00022 Timer t;
00023 #ifdef TARGET_LPC1768
00024 DigitalIn sig1(p9);
00025 #elif defined(TARGET_KL25Z) || defined(TARGET_NUCLEO_F401RE)
00026 DigitalIn sig1(D6);
00027 #else
00028 #error "You need to specify a pin for the sensor"
00029 #endif
00030 
00031 int main()
00032 {
00033   t.start();
00034 
00035   nh.initNode();
00036   nh.advertise(pub_collision);
00037 
00038   long publisher_timer = 0;
00039 
00040   while (1)
00041   {
00042 
00043     if (t.read_ms() > publisher_timer)
00044     {
00045       collision_msg.data = !sig1;
00046       pub_collision.publish(&collision_msg);
00047       publisher_timer = t.read_ms() + 1000;
00048     }
00049     nh.spinOnce();
00050   }
00051 }
00052 


rosserial_mbed
Author(s): Gary Servin
autogenerated on Sat Oct 7 2017 03:08:46