-
Notifications
You must be signed in to change notification settings - Fork 0
/
topic_tool.cpp
67 lines (51 loc) · 2.03 KB
/
topic_tool.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <ros/ros.h>
#include <geometry_msgs/PoseStamped.h>
#include <nav_msgs/Odometry.h>
#include <geometry_msgs/TwistStamped.h>
#include <mavros_msgs/CommandBool.h>
#include <mavros_msgs/SetMode.h>
#include <mavros_msgs/State.h>
#include <tf/tf.h>
geometry_msgs::PoseStamped host_mocap;
void host_pos(const geometry_msgs::PoseStamped::ConstPtr& msg) /*get position and attitude data*/
{
double roll, pitch, yaw;
host_mocap = *msg;
tf::Quaternion Q(
msg->pose.orientation.x,
msg->pose.orientation.y,
msg->pose.orientation.z,
msg->pose.orientation.w);
tf::Matrix3x3(Q).getRPY(roll,pitch,yaw);
}
/*void host_pos(const nav_msgs::Odometry::ConstPtr& msg)
{
double roll, pitch, yaw;
host_mocap.header = msg->header;
host_mocap.pose.position = msg->pose.pose.position;
host_mocap.pose.orientation = msg->pose.pose.orientation;
tf::Quaternion Q(
host_mocap.pose.orientation.x,
host_mocap.pose.orientation.y,
host_mocap.pose.orientation.z,
host_mocap.pose.orientation.w);
tf::Matrix3x3(Q).getRPY(roll,pitch,yaw);
}*/
int main(int argc, char **argv)
{
ros::init(argc, argv, "topic");
ros::NodeHandle nh;
ros::Publisher mocap_pos_pub = nh.advertise<geometry_msgs::PoseStamped> /*output topic*/
("/mavros/vision_pose/pose", 2);
ros::Subscriber host_sub = nh.subscribe<geometry_msgs::PoseStamped>("/vrpn_client_node/RigidBody7/pose", 10, host_pos); /*input topic*/
// ros::Subscriber host_sub = nh.subscribe<nav_msgs::Odometry> ("/vins_estimator/odometry",2, host_pos);
// ros::Subscriber host_sub = nh.subscribe<nav_msgs::Odometry> ("/vins_estimator/imu_propagate",2, host_pos);
ros::Rate rate(30);
while (ros::ok()) {
ROS_INFO("vision_pose: %.3f,%.3f,%.3f",host_mocap.pose.position.x,host_mocap.pose.position.y,host_mocap.pose.position.z);
mocap_pos_pub.publish(host_mocap);
ros::spinOnce();
rate.sleep();
}
return 0;
}