HCSR04 with ROS

Dependencies:   Pulse mbed ros_lib_kinetic

Files at this revision

API Documentation at this revision

Comitter:
wupinxian
Date:
Wed Jul 12 02:23:53 2017 +0000
Commit message:
ROS_HCSR04;

Changed in this revision

Pulse.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
ros_lib_kinetic.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Pulse.lib	Wed Jul 12 02:23:53 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/NickRyder/code/Pulse/#fb79a4637a64
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jul 12 02:23:53 2017 +0000
@@ -0,0 +1,48 @@
+/*
+ * rosserial Publisher Example
+ * Prints "hello world!"
+ */
+
+#include"mbed.h"
+#include"Pulse.h"
+#include"stdio.h"
+#include <ros.h>
+#include <std_msgs/String.h>
+
+
+ros::NodeHandle  nh;
+
+std_msgs::String str_msg;
+ros::Publisher chatter("chatter", &str_msg);
+
+char hello[20] = "How a fucking day!";
+//HCSR04 sonar(PB_0,PB_1) ;
+//PA_6 ->trig PA_7->echo
+PulseInOut trig(PB_1);
+PulseInOut echo(PB_0);
+float hc_distance(void)
+ {
+   long count=0;
+   float distance=0;
+     trig.write_us(1,10);
+      count=echo.read_high_us();
+      distance= float(count*0.017);
+      return distance;
+  }
+
+
+float dist=0.0;
+int main() {
+    nh.initNode();
+    nh.advertise(chatter);
+    while (1) {
+       
+        dist =  hc_distance();
+        sprintf(hello,"%f \n",dist);
+         str_msg.data = hello;
+        chatter.publish( &str_msg );
+         nh.spinOnce();
+        wait_ms(1000);
+        
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jul 12 02:23:53 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/64910690c574
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ros_lib_kinetic.lib	Wed Jul 12 02:23:53 2017 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/garyservin/code/ros_lib_kinetic/#a849bf78d77f