Skip to content

Instantly share code, notes, and snippets.

@wjwwood
Last active February 14, 2021 13:44
Show Gist options
  • Select an option

  • Save wjwwood/b67d07a171f89faa8939 to your computer and use it in GitHub Desktop.

Select an option

Save wjwwood/b67d07a171f89faa8939 to your computer and use it in GitHub Desktop.
Example C++ Subscription, use `c++ -I/opt/ros/hydro/include -L/opt/ros/hydro/lib -lroscpp -lroscpp_serialization -lrosconsole my_node.cpp -o my_node`
#include <vector>
#include "ros/ros.h"
#include "geometry_msgs/PoseStamped.h"
std::vector<geometry_msgs::PoseStamped::ConstPtr> poses;
void handle_poses(const geometry_msgs::PoseStamped::ConstPtr& msg)
{
ROS_INFO_STREAM("Received pose: " << msg);
// Use the msg object here to access the pose elements,
// like msg->pose.pose.position.x
poses.push_back(msg);
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "my_node");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("/monocular_pose_estimator/estimated_pose",
1000, handle_poses);
ros::spin();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment