First Commit message

This commit is contained in:
caroline
2022-04-14 16:59:20 +02:00
commit 23719e5a76
4 changed files with 394 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
#include "ros/ros.h"
#include "std_msgs/String.h"
#include "std_msgs/Bool.h"
#include "std_msgs/Float32.h"
#include <sstream>
#include <math.h>
#include <pcl/filters/passthrough.h>
#include <pcl/conversions.h>
#include <pcl_conversions/pcl_conversions.h>
#include <sensor_msgs/PointCloud2.h>
#include <visualization_msgs/Marker.h>
/*
TBD: get to know typedef such as stringstream
*/
// define publisher
ros::Publisher pub;
ros::Publisher visual;
typedef pcl::PointXYZRGB PointT;
void cloud_cb (const sensor_msgs::PointCloud2ConstPtr& cloud_msg){
// create pointer to Point Cloud in pcl
pcl::PointCloud<PointT>::Ptr cloud(new pcl::PointCloud<PointT>);
// convert ROS message data to point cloud in pcl
pcl::fromROSMsg(*cloud_msg, *cloud);
// convert to ROS data type
sensor_msgs::PointCloud2 output;
pcl::toROSMsg(*cloud, output);
pub.publish(output);
}
int main(int argc, char **argv){
// specify node name and initialize ROS
ros::init(argc, argv, "image_processing");
// first/last node handle does the initialization of node/cleanup of used resources by node
ros::NodeHandle n;
// create subscriber to receive point cloud
ros::Subscriber sub = n.subscribe<sensor_msgs::PointCloud2>("/zed/zed_node/point_cloud/cloud_registered", 1, cloud_cb);
// create publisher for output processed point cloud
pub = n.advertise<sensor_msgs::PointCloud2>("processed_cloud", 1);
// create publisher for visualising marker
visual = n.advertise<visualization_msgs::Marker> ("marker", 1);
ros::spin();
}
+52
View File
@@ -0,0 +1,52 @@
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>
/*
TBD: get to know typedef such as stringstream
*/
void chatterCallback(const std_msgs::String::ConstPtr& msg){
ROS_INFO("I heard: [%s]", msg->data.c_str());
}
int main(int argc, char **argv){
// specify node name
ros::init(argc, argv, "talker");
ros::init(argc, argv, "listener");
// first/last node handle does the initialization of node/cleanup of used resources by node
ros::NodeHandle n;
// create publisher
// publishes message of type std_msgs/String on topic chatter with given cue size
// NodeHandle::advertise() returns ros::Publisher object containing publish method & unadvertise when going out of scope
ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);
ros::Subscriber sub = n.subscribe("chatter", 1000, chatterCallback);
// ros::rate object specifies frequency to loop at
// keeps track of how long it has been since last Rate::sleep() call & sleeps for correct amount of time
ros::Rate loop_rate(10);
int count = 0;
while (ros::ok()){
std_msgs::String msg;
std::stringstream ss;
ss << "hello world " << count;
msg.data = ss.str();
ROS_INFO("%s", msg.data.c_str()); // replacement for printf/cout
chatter_pub.publish(msg);
ros::spinOnce(); // added to make sure that all callbackfunctions get called
loop_rate.sleep(); // use ros::rate object to sleep for remaining time to hit publish rate
++count;
}
//broascasting message to anyone who is connected
return 0;
}