Test.cpp
Go to the documentation of this file.
1 
18 #include "../test/Test.h"
19 
20 #include <pcl_ros/transforms.h>
21 #include <tf/transform_listener.h>
22 
23 namespace amcl3d
24 {
26 {
27 }
28 
30 {
31 }
32 
33 void Test::spin()
34 {
35  ROS_DEBUG("[%s] Test::spin()", ros::this_node::getName().data());
36 
40 
45 
47  vicon_sub_ = nh_.subscribe("vicon_client/ROSIN_F550/pose", 1, &Test::baseCallback, this);
48  vicon_pub_ = nh_.advertise<geometry_msgs::TransformStamped>("vicon_odometry", 1);
49 
50  pointcloud_sub_ = nh_.subscribe("/os1_cloud_node/points", 1, &Test::cloudCallback, this);
51  pointcloud_pub_ = nh_.advertise<sensor_msgs::PointCloud2>("lidar_pointcloud", 1);
52 
53  while (ros::ok())
54  {
55  ros::spinOnce();
56  }
57 
58  nh_.shutdown();
59 }
60 
61 void Test::cloudCallback(const sensor_msgs::PointCloud2Ptr& msg)
62 {
63  sensor_msgs::PointCloud2 base_cloud;
64  pcl_ros::transformPointCloud("base_link", pointcloud_2base_tf_, *msg, base_cloud);
65 
67  base_cloud.header.stamp = ros::Time(0);
68 
69  pointcloud_pub_.publish(base_cloud);
70 }
71 
72 void Test::baseCallback(const geometry_msgs::PoseStampedConstPtr& msg)
73 {
75 
76  vicon_tf_.setOrigin(tf::Vector3(msg->pose.position.x, msg->pose.position.y, msg->pose.position.z));
77  vicon_tf_.setRotation(tf::Quaternion(msg->pose.orientation.x, msg->pose.orientation.y, msg->pose.orientation.z,
78  msg->pose.orientation.w));
79 
80  if (!got_vicon_init_)
81  {
82  vicon_init_tf_.setOrigin(tf::Vector3(msg->pose.position.x, msg->pose.position.y, msg->pose.position.z));
83 
84  tf::Quaternion q(msg->pose.orientation.x, msg->pose.orientation.y, msg->pose.orientation.z,
85  +msg->pose.orientation.w);
86 
87  double roll, pitch, yaw;
88  tf::Matrix3x3(q).getRPY(roll, pitch, yaw);
90 
91  got_vicon_init_ = true;
92  }
93 
95 
98 
99  geometry_msgs::TransformStamped vicon_relative;
100  vicon_relative.header.stamp = ros::Time::now();
101  vicon_relative.header.frame_id = "vicon_odometry";
102  vicon_relative.transform.translation.x = position.getX();
103  vicon_relative.transform.translation.y = position.getY();
104  vicon_relative.transform.translation.z = position.getZ();
105  vicon_relative.transform.rotation.x = orientation.getX();
106  vicon_relative.transform.rotation.y = orientation.getY();
107  vicon_relative.transform.rotation.z = orientation.getZ();
108  vicon_relative.transform.rotation.w = orientation.getW();
109 
110  vicon_pub_.publish(vicon_relative);
111 
112  br_.sendTransform(tf::StampedTransform(vicon_tf_, ros::Time::now(), "world", "vicon_real"));
113 }
114 } // namespace amcl3d
ros::Subscriber vicon_sub_
Definition: Test.h:40
static tf::Quaternion createQuaternionFromRPY(double roll, double pitch, double yaw)
TFSIMD_FORCE_INLINE void setRotation(const Quaternion &q)
tf::Transform vicon_init_tf_
Definition: Test.h:49
ros::NodeHandle nh_
Definition: Test.h:38
void publish(const boost::shared_ptr< M > &message) const
tf::Transform vicon_relative_tf_
Definition: Test.h:50
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
virtual ~Test()
Definition: Test.cpp:29
ROSCPP_DECL const std::string & getName()
TFSIMD_FORCE_INLINE const tfScalar & getY() const
void spin()
Definition: Test.cpp:33
#define M_PI
TFSIMD_FORCE_INLINE const tfScalar & getW() const
TFSIMD_FORCE_INLINE const tfScalar & getZ() const
void baseCallback(const geometry_msgs::PoseStampedConstPtr &msg)
Definition: Test.cpp:72
void setIdentity()
Include Grid.hpp.
Definition: Grid3d.cpp:23
void getRPY(tfScalar &roll, tfScalar &pitch, tfScalar &yaw, unsigned int solution_number=1) const
tf::Transform pointcloud_2base_tf_
Definition: Test.h:54
void cloudCallback(const sensor_msgs::PointCloud2Ptr &msg)
Definition: Test.cpp:61
tf::TransformBroadcaster br_
Definition: Test.h:52
ROSCPP_DECL bool ok()
void sendTransform(const StampedTransform &transform)
Transform inverse() const
bool got_vicon_init_
Definition: Test.h:46
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
tf::Transform vicon_tf_
Definition: Test.h:48
TFSIMD_FORCE_INLINE Vector3 & getOrigin()
ros::Publisher vicon_pub_
Definition: Test.h:43
Quaternion getRotation() const
void transformPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, const tf::Transform &transform)
ros::Publisher pointcloud_pub_
Definition: Test.h:44
TFSIMD_FORCE_INLINE const tfScalar & getX() const
static Time now()
ros::Subscriber pointcloud_sub_
Definition: Test.h:41
ROSCPP_DECL void spinOnce()
TFSIMD_FORCE_INLINE void setOrigin(const Vector3 &origin)
#define ROS_DEBUG(...)


amcl3d
Author(s): Francisco J.Perez-Grau
autogenerated on Sun Sep 15 2019 04:08:05