HCSR04 with ROS
Dependencies: Pulse mbed ros_lib_kinetic
Revision 0:e70ca69c6311, committed 2017-07-12
- Comitter:
- wupinxian
- Date:
- Wed Jul 12 02:23:53 2017 +0000
- Commit message:
- ROS_HCSR04;
Changed in this revision
diff -r 000000000000 -r e70ca69c6311 Pulse.lib --- /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
diff -r 000000000000 -r e70ca69c6311 main.cpp --- /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
diff -r 000000000000 -r e70ca69c6311 mbed.bld --- /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
diff -r 000000000000 -r e70ca69c6311 ros_lib_kinetic.lib --- /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