2
#include "camera_synchronizer.h"
3
#include <tf/transform_broadcaster.h>
6
namespace camera_synchronizer{
8
CameraSynchronizer::CameraSynchronizer()
9
: n_tilde("~"), timestamp(0.0), publish_rate(0.0)
12
std::string searched_param;
15
//Set publish frequency for sync images
18
n_tilde.param("frequency",frequency,15.0);
19
publish_rate = Rate(frequency);
22
//Set publishers and subscribers
23
n_tilde.searchParam("left_async",searched_param);
24
n_tilde.param(searched_param,path,std::string());
26
left_sub = node.subscribe(path,10, &CameraSynchronizer::callback_left, this);
28
n_tilde.searchParam("right_async",searched_param);
29
n_tilde.param(searched_param,path,std::string());
31
right_sub = node.subscribe(path,10, &CameraSynchronizer::callback_right, this);
33
n_tilde.searchParam("left_info_async",searched_param);
34
n_tilde.param(searched_param,path,std::string());
36
left_info_sub = node.subscribe(path,10, &CameraSynchronizer::callback_info_left, this);
38
n_tilde.searchParam("right_info_async",searched_param);
39
n_tilde.param(searched_param,path,std::string());
41
right_info_sub = node.subscribe(path,10, &CameraSynchronizer::callback_info_right, this);
43
n_tilde.searchParam("left_sync",searched_param);
44
n_tilde.param(searched_param,path,std::string());
46
left_pub = node.advertise<sensor_msgs::Image>(path,1);
48
n_tilde.searchParam("right_sync",searched_param);
49
n_tilde.param(searched_param,path,std::string());
51
right_pub = node.advertise<sensor_msgs::Image>(path,1);
53
n_tilde.searchParam("left_info_sync",searched_param);
54
n_tilde.param(searched_param,path,std::string());
56
left_info_pub = node.advertise<sensor_msgs::CameraInfo>(path,1);
58
n_tilde.searchParam("right_info_sync",searched_param);
59
n_tilde.param(searched_param,path,std::string());
61
right_info_pub = node.advertise<sensor_msgs::CameraInfo>(path,1);
64
void CameraSynchronizer::callback_left(const sensor_msgs::ImageConstPtr& msg){
65
im_left=convertFromBoost(msg);
66
static tf::TransformBroadcaster br;
67
tf::Transform transform;
68
transform.setOrigin(tf::Vector3(0.0,0.0,0.0));
69
br.sendTransform(tf::StampedTransform(transform, ros::Time(timestamp),"fixed_frame", "test"));
73
void CameraSynchronizer::callback_right(const sensor_msgs::ImageConstPtr& msg){
74
im_right=convertFromBoost(msg);
77
void CameraSynchronizer::callback_info_left(const sensor_msgs::CameraInfoConstPtr& msg){
78
info_left=convertFromBoost(msg);
79
// info_left.roi.height=240;
80
// info_left.roi.width=320;
83
void CameraSynchronizer::callback_info_right(const sensor_msgs::CameraInfoConstPtr& msg){
84
info_right=convertFromBoost(msg);
86
n_tilde.param("right_offset", offset,0);
87
info_right.roi.x_offset=offset;
88
// info_right.roi.height=240;
89
// info_right.roi.width=320;
93
sensor_msgs::Image CameraSynchronizer::convertFromBoost(const sensor_msgs::ImageConstPtr& msg){
94
sensor_msgs::Image ret;
95
ret.height=msg->height;
97
// ret.header=msg->header;
98
ret.header.stamp=ros::Time(timestamp);
99
// ret.header.frame_id="/stereo/left/image_raw";
101
ret.is_bigendian=msg->is_bigendian;
107
sensor_msgs::CameraInfo CameraSynchronizer::convertFromBoost(const sensor_msgs::CameraInfoConstPtr& msg){
108
static tf::TransformBroadcaster br;
109
tf::Transform transform;
110
transform.setOrigin(tf::Vector3(0.0,0.0,0.0));
111
br.sendTransform(tf::StampedTransform(transform, ros::Time(timestamp),"fixed_frame", "test"));
112
sensor_msgs::CameraInfo ret;
113
ret.height=msg->height;
114
ret.width=msg->width;
120
ret.header.stamp=ros::Time(timestamp);
121
ret.header.frame_id="fixed_frame";
126
void CameraSynchronizer::publish(){
127
left_pub.publish(im_left);
128
right_pub.publish(im_right);
129
left_info_pub.publish(info_left);
130
right_info_pub.publish(info_right);
133
publish_rate.sleep();