rgbd
ros_to_rgbd.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_ros.h"
11 #include "rgbd/image.h"
12 #include "rgbd/server.h"
13 #include "rgbd/types.h"
14 
15 // ----------------------------------------------------------------------------------------
16 
17 int main(int argc, char **argv) {
18  ros::init(argc, argv, "ros_to_rgbd");
19 
20  ros::NodeHandle nh_private("~");
21 
22  float rate = 30;
23  nh_private.getParam("rate", rate);
24 
25  // ----- READ RGB STORAGE TYPE
26 
27  rgbd::RGBStorageType rgb_type;
28 
29  std::string rgb_type_str = "lossless";
30  nh_private.getParam("rgb_storage", rgb_type_str);
31  if (rgb_type_str == "none")
32  rgb_type = rgbd::RGB_STORAGE_NONE;
33  else if (rgb_type_str == "lossless")
34  rgb_type = rgbd::RGB_STORAGE_LOSSLESS;
35  else if (rgb_type_str == "jpg")
36  rgb_type = rgbd::RGB_STORAGE_JPG;
37  else
38  {
39  ROS_ERROR("Unknown 'rgb_storage' type: should be 'none', 'lossless', or 'jpg'.");
40  return 1;
41  }
42 
43  // ----- READ DEPTH STORAGE TYPE
44 
45  rgbd::DepthStorageType depth_type;
46 
47  std::string depth_type_str = "lossless";
48  nh_private.getParam("depth_storage", depth_type_str);
49  if (depth_type_str == "none")
50  depth_type = rgbd::DEPTH_STORAGE_NONE;
51  else if (depth_type_str == "lossless")
52  depth_type = rgbd::DEPTH_STORAGE_LOSSLESS;
53  else if (depth_type_str == "png")
54  depth_type = rgbd::DEPTH_STORAGE_PNG;
55  else
56  {
57  ROS_ERROR("Unknown 'depth_storage' type: should be 'none', 'lossless', or 'png'.");
58  return 1;
59  }
60 
61  // ------------------------------
62 
63  rgbd::ClientROS client;
64  rgbd::Server server;
65 
66  client.initialize("rgb_image", "depth_image", "cam_info");
67  server.initialize(ros::names::resolve("rgbd"), rgb_type, depth_type);
68 
69  rgbd::ImagePtr image_ptr;
70 
71  ros::WallTime last_master_check = ros::WallTime::now();
72 
73  ros::Rate r(rate);
74  while (ros::ok())
75  {
76  if (ros::WallTime::now() >= last_master_check + ros::WallDuration(1))
77  {
78  last_master_check = ros::WallTime::now();
79  if (!ros::master::check())
80  {
81  ROS_FATAL("Lost connection to master");
82  return 1;
83  }
84  }
85  image_ptr = client.nextImage();
86  if (image_ptr)
87  server.send(*image_ptr);
88  r.sleep();
89  }
90 
91  return 0;
92 }
rgbd::Server
Server which provides interfaces of ServerRGBD and ServerSHM.
Definition: server.h:21
std::string
std::shared_ptr
rgbd::Server::send
void send(const Image &image, bool threaded=false)
send Write a new image to all interfaces
Definition: server.cpp:38
types.h
rgbd::ClientROS::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_ros.cpp:43
rgbd::DepthStorageType
DepthStorageType
Definition: image.h:36
rgbd::RGB_STORAGE_JPG
@ RGB_STORAGE_JPG
Definition: image.h:33
rgbd::Server::initialize
void initialize(const std::string &name, RGBStorageType rgb_type=RGB_STORAGE_LOSSLESS, DepthStorageType depth_type=DEPTH_STORAGE_LOSSLESS, const float service_freq=10)
initialize initialize server
Definition: server.cpp:29
rgbd::RGBStorageType
RGBStorageType
Definition: image.h:29
rgbd::DEPTH_STORAGE_NONE
@ DEPTH_STORAGE_NONE
Definition: image.h:38
image.h
rgbd::DEPTH_STORAGE_PNG
@ DEPTH_STORAGE_PNG
Definition: image.h:40
rgbd::RGB_STORAGE_LOSSLESS
@ RGB_STORAGE_LOSSLESS
Definition: image.h:32
client_ros.h
rgbd::DEPTH_STORAGE_LOSSLESS
@ DEPTH_STORAGE_LOSSLESS
Definition: image.h:39
main
int main(int argc, char **argv)
Definition: ros_to_rgbd.cpp:17
rgbd::ClientROS
Client which subscribes to regular ROS image topics.
Definition: client_ros.h:31
rgbd::RGB_STORAGE_NONE
@ RGB_STORAGE_NONE
Definition: image.h:31
server.h
rgbd::ClientROS::initialize
bool initialize(const std::string &rgb_image_topic, const std::string &depth_image_topic, const std::string &cam_info_topic)
Initialize the subscriber.
Definition: client_ros.cpp:29