rgbd
rgbd_to_shm.cpp
Go to the documentation of this file.
1 #include <ros/console.h>
2 #include <ros/duration.h>
3 #include <ros/init.h>
4 #include <ros/master.h>
5 #include <ros/names.h>
6 #include <ros/node_handle.h>
7 #include <ros/rate.h>
8 #include <ros/time.h>
9 
10 #include "rgbd/client_rgbd.h"
11 #include "rgbd/image.h"
12 #include "rgbd/server_shm.h"
13 #include "rgbd/types.h"
14 #include "rgbd/utility.h"
15 
16 #include <std_msgs/String.h>
17 
18 #include <functional>
19 #include <memory>
20 #include <thread>
21 
22 
23 class Node
24 {
25 public:
26  Node() : rate_(30), server_name_(ros::names::resolve("rgbd")), host_name_(rgbd::get_hostname())
27  {
28  ros::NodeHandle nh_private("~");
29  nh_private.getParam("rate", rate_);
30 
33  }
34 
35  virtual ~Node()
36  {
37  nh_.shutdown();
40  }
41 
42  int run()
43  {
44  rgbd::ImagePtr image_ptr;
45 
46  ros::WallTime last_master_check = ros::WallTime::now();
47 
48  ros::Rate r(rate_);
49  while (ros::ok())
50  {
51  if (ros::WallTime::now() >= last_master_check + ros::WallDuration(1))
52  {
53  last_master_check = ros::WallTime::now();
54  if (!ros::master::check())
55  {
56  ROS_FATAL("Lost connection to master");
57  return 1;
58  }
59  }
60  image_ptr = client_.nextImage();
61  if (image_ptr)
62  {
65  server_.send(*image_ptr);
66  }
67  r.sleep();
68  }
69 
70  return 0;
71  }
72 
73 private:
74  ros::NodeHandle nh_;
75 
78 
79  double rate_;
80 
83 
85 };
86 
87 
88 // ----------------------------------------------------------------------------------------
89 
90 int main(int argc, char **argv)
91 {
92  ros::init(argc, argv, "rgbd_to_shm");
93 
94  Node node;
95 
96  return node.run();
97 }
Node::~Node
virtual ~Node()
Definition: rgbd_to_shm.cpp:35
Node::nh_
ros::NodeHandle nh_
Definition: rgbd_to_shm.cpp:74
rgbd::ClientRGBD::nextImage
bool nextImage(Image &image)
Get a new Image. If no new image has been received since the last call, no image will be written and ...
Definition: client_rgbd.cpp:44
std::string
std::shared_ptr
types.h
functional
rgbd::get_hostname
std::string get_hostname()
Get the hostname of the current machine.
Definition: utility.cpp:13
Node::run
int run()
Definition: rgbd_to_shm.cpp:42
Node::server_name_
const std::string server_name_
Definition: rgbd_to_shm.cpp:81
utility.h
Node::rate_
double rate_
Definition: rgbd_to_shm.cpp:79
rgbd::pubHostnameThreadFunc
void pubHostnameThreadFunc(ros::NodeHandle &nh, const std::string server_name, const std::string hostname, const float frequency)
Definition: server_shm.cpp:154
client_rgbd.h
thread
rgbd
Definition: client.h:24
Node::host_name_
const std::string host_name_
Definition: rgbd_to_shm.cpp:82
rgbd::ServerSHM::send
void send(const Image &image)
send Write a new image to the shared memory
Definition: server_shm.cpp:48
rgbd::ClientRGBD::initialize
bool initialize(const std::string &server_name)
Initialize the client.
Definition: client_rgbd.cpp:22
image.h
rgbd::ClientRGBD
Client which subscribes to RGBD topic.
Definition: client_rgbd.h:22
memory
rgbd::ServerSHM::initialize
void initialize(const std::string &name)
initialize Initialize shared memory server
Definition: server_shm.cpp:40
main
int main(int argc, char **argv)
Definition: rgbd_to_shm.cpp:90
Node
Definition: rgbd_to_shm.cpp:23
Node::server_
rgbd::ServerSHM server_
Definition: rgbd_to_shm.cpp:77
Node::Node
Node()
Definition: rgbd_to_shm.cpp:26
Node::client_
rgbd::ClientRGBD client_
Definition: rgbd_to_shm.cpp:76
std::unique_ptr< std::thread >
rgbd::ServerSHM
Server which uses shared memory, this only works for clients on the same machine.
Definition: server_shm.h:22
server_shm.h
std::ref
T ref(T... args)
Node::pub_hostname_thread_ptr_
std::unique_ptr< std::thread > pub_hostname_thread_ptr_
Definition: rgbd_to_shm.cpp:84