37
37
38
38
/*
39
39
* Author: Sofie Nilsson
40
+ * Author: Thomas Lindemeier
40
41
*/
41
-
42
+
42
43
#include < pointcloud_to_laserscan/frame_publisher.h>
43
44
44
45
FramePublisher::FramePublisher () :
@@ -52,58 +53,60 @@ bool FramePublisher::initialize()
52
53
{
53
54
priv_nh_ = ros::NodeHandle (" ~" );
54
55
55
- priv_nh_.param <double >(" update_rate" , update_rate_, 0.01 ); // 100Hz
56
+ priv_nh_.param <double >(" update_rate" , update_rate_, 0.01 ); // 100Hz
57
+
58
+ priv_nh_.param <std::string>(" from_frame" , from_frame_, " base_link" );
59
+ priv_nh_.param <std::string>(" to_frame" , to_frame_, " torso_center_link" );
60
+ priv_nh_.param <std::string>(" frame_name" , frame_name_, " torso_rotated_base_link" );
56
61
57
- priv_nh_.param <std::string>(" base_frame" , base_frame_, " base_link" );
58
- priv_nh_.param <std::string>(" rotation_frame" , rotation_frame_, " torso_center_link" );
59
- priv_nh_.param <std::string>(" target_frame" , target_frame_, " torso_rotated_base_link" );
62
+ priv_nh_.param <bool >(" use_to_frame_translation" , use_to_frame_translation_, true );
60
63
61
64
priv_nh_.param <bool >(" rot_z" , rot_z_, false );
62
65
priv_nh_.param <bool >(" rot_x" , rot_x_, false );
63
66
priv_nh_.param <bool >(" rot_y" , rot_y_, false );
64
67
65
68
frame_broadcast_timer_ = nh_.createTimer (ros::Duration (update_rate_), &FramePublisher::frameBroadcastCallback, this );
66
69
67
- ros::Duration (1.0 ).sleep (); // give tf_listener some time
70
+ ros::Duration (1.0 ).sleep (); // give tf_listener some time
68
71
69
72
return true ;
70
73
}
71
74
72
- // / Broadcast a frame aligned with the base frame but rotated around specified axes as rotation_frame
75
+ // / Broadcast a new frame based on a given transformation from_frame -> to_frame - resetting either translation and/or individual rotation axes to zero
73
76
void FramePublisher::frameBroadcastCallback (const ros::TimerEvent& event)
74
77
{
75
- ros::Time time = event.current_real ;
76
78
geometry_msgs::TransformStamped transform_msg;
77
- try {
78
- transform_msg = tf_buffer_.lookupTransform (base_frame_, rotation_frame_, time, ros::Duration (0.1 ));
79
+ try
80
+ {
81
+ transform_msg = tf_buffer_.lookupTransform (from_frame_, to_frame_, ros::Time (0 ), ros::Duration (0.1 ));
82
+ ROS_DEBUG_STREAM (" FramePublisher::frameBroadcastCallback: transform_msg:\n " << transform_msg);
79
83
}
80
- catch (tf2::TransformException & ex)
84
+ catch (tf2::TransformException& ex)
81
85
{
82
- ROS_ERROR (" FramePublisher::frameBroadcastCallback: \n %s" ,ex.what ());
86
+ ROS_ERROR (" FramePublisher::frameBroadcastCallback: \n %s" , ex.what ());
83
87
return ;
84
88
}
85
- // ROS_WARN_STREAM("FramePublisher::frameBroadcastCallback: \n" << transform_msg);
86
89
87
90
tf2::Stamped<tf2::Transform> transform_tf;
88
91
tf2::fromMsg (transform_msg, transform_tf);
89
92
double rot_frame_roll, rot_frame_pitch, rot_frame_yaw;
90
93
transform_tf.getBasis ().getRPY (rot_frame_roll, rot_frame_pitch, rot_frame_yaw);
91
94
92
95
// Use rotations according to settings
93
- double target_frame_roll = 0 ;
94
- double target_frame_pitch = 0 ;
95
- double target_frame_yaw = 0 ;
96
- if (rot_z_ ){ target_frame_yaw = rot_frame_yaw; }
97
- if (rot_x_ ){ target_frame_roll = rot_frame_roll; }
98
- if (rot_y_ ){ target_frame_pitch = rot_frame_pitch; }
96
+ double published_frame_roll = 0 ;
97
+ double published_frame_pitch = 0 ;
98
+ double published_frame_yaw = 0 ;
99
+ if (rot_x_ ){ published_frame_roll = rot_frame_roll; }
100
+ if (rot_y_ ){ published_frame_pitch = rot_frame_pitch; }
101
+ if (rot_z_ ){ published_frame_yaw = rot_frame_yaw; }
99
102
100
- tf2::Stamped<tf2::Transform> target_tf (transform_tf); // keep header
101
- target_tf .setOrigin (tf2::Vector3 (0 ,0 ,0 ));
102
- target_tf .getBasis ().setRPY (target_frame_roll, target_frame_pitch, target_frame_yaw );
103
+ tf2::Stamped<tf2::Transform> published_tf (transform_tf); // keep header and translation
104
+ if (!use_to_frame_translation_){ published_tf .setOrigin (tf2::Vector3 (0 ,0 ,0 )); }
105
+ published_tf .getBasis ().setRPY (published_frame_roll, published_frame_pitch, published_frame_yaw );
103
106
104
107
// Broadcast new frame
105
- geometry_msgs::TransformStamped target_msg = tf2::toMsg (target_tf );
106
- target_msg .child_frame_id = target_frame_ ;
107
- // ROS_ERROR_STREAM("FramePublisher::frameBroadcastCallback: \n" << target_msg );
108
- tf_broadcaster_. sendTransform (target_msg );
108
+ geometry_msgs::TransformStamped published_msg = tf2::toMsg (published_tf );
109
+ published_msg .child_frame_id = frame_name_ ;
110
+ tf_broadcaster_. sendTransform (published_msg );
111
+ ROS_DEBUG_STREAM ( " FramePublisher::frameBroadcastCallback: published_msg: \n " << published_msg );
109
112
}
0 commit comments