Integration of multiple sensors with ROS Serial

Dependencies:   mbed

Committer:
zillkhan
Date:
Sat Oct 23 06:48:13 2021 +0000
Revision:
0:d409714cebbf
Adding Sharp IR

Who changed what in which revision?

UserRevisionLine numberNew contents of line
zillkhan 0:d409714cebbf 1 #include <ros.h>
zillkhan 0:d409714cebbf 2 #include <std_msgs/Float32.h>
zillkhan 0:d409714cebbf 3 #include <std_msgs/String.h>
zillkhan 0:d409714cebbf 4 #include "SHARPIR.h"
zillkhan 0:d409714cebbf 5
zillkhan 0:d409714cebbf 6
zillkhan 0:d409714cebbf 7 ros::NodeHandle nh;
zillkhan 0:d409714cebbf 8
zillkhan 0:d409714cebbf 9 std_msgs::Float32 data;
zillkhan 0:d409714cebbf 10 ros::Publisher sharpir("sharpir", &data);
zillkhan 0:d409714cebbf 11
zillkhan 0:d409714cebbf 12 SHARPIR Sensor(A0);
zillkhan 0:d409714cebbf 13
zillkhan 0:d409714cebbf 14
zillkhan 0:d409714cebbf 15 int main() {
zillkhan 0:d409714cebbf 16 float DistanceCM;
zillkhan 0:d409714cebbf 17
zillkhan 0:d409714cebbf 18 nh.initNode();
zillkhan 0:d409714cebbf 19 nh.advertise(sharpir);
zillkhan 0:d409714cebbf 20
zillkhan 0:d409714cebbf 21 while (1) { //creates an eternal loop
zillkhan 0:d409714cebbf 22
zillkhan 0:d409714cebbf 23 DistanceCM=Sensor.cm();
zillkhan 0:d409714cebbf 24 //sprintf (buffer, "%f", DistanceCM);
zillkhan 0:d409714cebbf 25
zillkhan 0:d409714cebbf 26 data.data = DistanceCM;
zillkhan 0:d409714cebbf 27 sharpir.publish( &data );
zillkhan 0:d409714cebbf 28
zillkhan 0:d409714cebbf 29 nh.spinOnce();
zillkhan 0:d409714cebbf 30 wait_ms(1000);
zillkhan 0:d409714cebbf 31 }
zillkhan 0:d409714cebbf 32 }