sensor_alignment_tf_dyn.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 
3 // PCL specific includes
5 #include <pcl/point_cloud.h>
6 #include <pcl/point_types.h>
7 #include <pcl_ros/transforms.h>
8 
9 #include <dynamic_reconfigure/server.h>
10 #include <sick_scan/tf_dynConfig.h>
11 
14 #include <tf2_eigen/tf2_eigen.h>
15 
16 Eigen::Affine3d child_2_parent;
17 
19 {
20 public:
21  std::string parentFrame;
22  std::string childFrame;
23  double trans_x;
24  double trans_y;
25  double trans_z;
26  double trans_rot_x;
27  double trans_rot_y;
28  double trans_rot_z;
29 };
30 
32 
33 
34 // for setting region of interest
35 Eigen::Vector4f min_point;
36 Eigen::Vector4f max_point;
37 
39 
40 
41 void callback(sick_scan_fusion::tf_dynConfig &config, uint32_t level)
42 {
43  cfgTrans.parentFrame = config.parent_frame;
44  cfgTrans.childFrame = config.child_frame;
45 
46  cfgTrans.trans_x = config.tf_x;
47  cfgTrans.trans_y = config.tf_y;
48  cfgTrans.trans_z = config.tf_z;
49  cfgTrans.trans_rot_x = config.tf_rot_x * M_PI / 180.0;
50  cfgTrans.trans_rot_y = config.tf_rot_y * M_PI / 180.0;
51  cfgTrans.trans_rot_z = config.tf_rot_z * M_PI / 180.0;
52  }
53 
54 int main (int argc, char** argv)
55 {
56  // initialize
57  ros::init (argc, argv, "sick_scan_fusion_tf_dyn");
58  ros::NodeHandle nh;
59 
61 
62 
63  child_2_parent = Eigen::Affine3d::Identity();
64 
65  // dynamic reconfigure
66  dynamic_reconfigure::Server<sick_scan_fusion::tf_dynConfig> server;
67  dynamic_reconfigure::Server<sick_scan_fusion::tf_dynConfig>::CallbackType f;
68  f = boost::bind(&callback, _1, _2);
69  server.setCallback(f);
70 
71 
72  unsigned seq= 0;
73  ros::Rate loop_rate(100);
74  while (ros::ok())
75  {
76  if ((seq % 20) == 0)
77  {
78  printf("Par. %s Child: %s Trans x: %0.3lf\n", cfgTrans.childFrame.c_str(), cfgTrans.parentFrame.c_str(), cfgTrans.trans_x);
80  child_2_parent = Eigen::Affine3d::Identity();
81  child_2_parent.translate(Eigen::Vector3d( cfgTrans.trans_x,0,0));
82  child_2_parent.translate(Eigen::Vector3d(0, cfgTrans.trans_y,0));
83  child_2_parent.translate(Eigen::Vector3d(0, 0, cfgTrans.trans_z));
84  // pitch
85  child_2_parent.rotate(Eigen::AngleAxisd(cfgTrans.trans_rot_x, Eigen::Vector3d(1, 0, 0)));
86  // yaw
87  child_2_parent.rotate(Eigen::AngleAxisd(cfgTrans.trans_rot_y, Eigen::Vector3d(0, 1, 0)));
88  // yaw
89  child_2_parent.rotate(Eigen::AngleAxisd(cfgTrans.trans_rot_z, Eigen::Vector3d(0, 0, 1)));
90 
91  geometry_msgs::TransformStamped transform_base_trans = tf2::eigenToTransform(child_2_parent);
92  transform_base_trans.header.frame_id = cfgTrans.parentFrame;
93  transform_base_trans.child_frame_id = cfgTrans.childFrame;
94  transform_base_trans.header.stamp = ros::Time::now();
95  transform_base_trans.header.seq = seq;
96  br.sendTransform(transform_base_trans);
97 
98  ros::spinOnce();
99  loop_rate.sleep();
100  ++seq;
101  }
102 }
103 
min_point
Eigen::Vector4f min_point
Definition: sensor_alignment_tf_dyn.cpp:35
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
tf2_eigen.h
ros.h
ConfigTrans::trans_z
double trans_z
Definition: sensor_alignment_tf_dyn.cpp:25
ros::spinOnce
ROSCPP_DECL void spinOnce()
ConfigTrans
Definition: sensor_alignment_tf_dyn.cpp:18
ros::ok
ROSCPP_DECL bool ok()
transform_broadcaster.h
tf_buffer
tf2_ros::Buffer tf_buffer
Definition: sensor_alignment_tf_dyn.cpp:38
transforms.h
ConfigTrans::trans_rot_x
double trans_rot_x
Definition: sensor_alignment_tf_dyn.cpp:26
tf2::eigenToTransform
geometry_msgs::TransformStamped eigenToTransform(const Eigen::Affine3d &T)
f
f
tf2_ros::TransformListener
tf2_ros::TransformBroadcaster::sendTransform
void sendTransform(const geometry_msgs::TransformStamped &transform)
callback
void callback(sick_scan_fusion::tf_dynConfig &config, uint32_t level)
Definition: sensor_alignment_tf_dyn.cpp:41
ConfigTrans::trans_x
double trans_x
Definition: sensor_alignment_tf_dyn.cpp:23
Quaternion.h
tf2_ros::Buffer
ConfigTrans::parentFrame
std::string parentFrame
Definition: sensor_alignment_tf_dyn.cpp:21
ros::Rate::sleep
bool sleep()
ConfigTrans::childFrame
std::string childFrame
Definition: sensor_alignment_tf_dyn.cpp:22
ConfigTrans::trans_rot_z
double trans_rot_z
Definition: sensor_alignment_tf_dyn.cpp:28
ConfigTrans::trans_rot_y
double trans_rot_y
Definition: sensor_alignment_tf_dyn.cpp:27
main
int main(int argc, char **argv)
Definition: sensor_alignment_tf_dyn.cpp:54
tf2_ros::TransformBroadcaster
ros::Rate
ConfigTrans::trans_y
double trans_y
Definition: sensor_alignment_tf_dyn.cpp:24
cfgTrans
ConfigTrans cfgTrans
Definition: sensor_alignment_tf_dyn.cpp:31
max_point
Eigen::Vector4f max_point
Definition: sensor_alignment_tf_dyn.cpp:36
child_2_parent
Eigen::Affine3d child_2_parent
Definition: sensor_alignment_tf_dyn.cpp:16
ros::NodeHandle
ros::Time::now
static Time now()
pcl_conversions.h


sick_scan
Author(s): Michael Lehning , Jochen Sprickerhof , Martin Günther
autogenerated on Thu Sep 8 2022 02:30:19