Texas Aerial Robotics Documentation
positionEstimate.cpp
Go to the documentation of this file.
1 #include <ros/ros.h>
2 #include <geometry_msgs/TransformStamped.h>
3 #include <geometry_msgs/PoseStamped.h>
4 #include <mavros_msgs/OverrideRCIn.h>
5 #include <gazebo_msgs/ModelStates.h>
6 #include <geometry_msgs/Pose.h>
7 #include <tf/transform_broadcaster.h>
8 #include <nav_msgs/Odometry.h>
9 
10 geometry_msgs::PoseStamped currentDroneState;
11 
12 // use ideal odometry from gazebo
13 void model_cb(const gazebo_msgs::ModelStates::ConstPtr& msg)
14 {
15  gazebo_msgs::ModelStates current_states = *msg;
16  int irisArrPos = 999;
17 
18  //search for the drone
19  for (int i=0; i< current_states.name.size(); i++)
20  {
21  if(current_states.name[i] == "iris")
22  {
23  irisArrPos = i;
24  break;
25  }
26 
27  }
28  if (irisArrPos == 999)
29  {
30  std::cout << "iris is not in world" << std::endl;
31  }else{
32  //assign drone pose to pose stamped
33  currentDroneState.pose = current_states.pose[irisArrPos];
34  currentDroneState.header.stamp = ros::Time::now();
35  }
36 
37 
38  //std::cout << current_states << std::endl;
39 }
40 nav_msgs::Odometry current_poseEKF;
41 void pose_cb(const nav_msgs::Odometry::ConstPtr& msg)
42 {
43  current_poseEKF = *msg;
44  // ROS_INFO("x: %f y: %f z: %f", current_pose.pose.pose.position.x, current_pose.pose.pose.position.y, current_pose.pose.pose.position.z);
45 }
46 
47 
48 int main(int argc, char **argv) {
49 
50  ros::init(argc, argv, "position_sender");
51  ros::NodeHandle n;
52  ros::Publisher pub = n.advertise<geometry_msgs::TransformStamped>("/mavros/fake_gps/mocap/tf", 10);
53  ros::Publisher pubStamped = n.advertise<geometry_msgs::PoseStamped>("/mavros/vision_pose/pose", 10);
54  ros::Subscriber currentHeading = n.subscribe<gazebo_msgs::ModelStates>("/gazebo/model_states", 10, model_cb);
55  ros::Subscriber currentPos = n.subscribe<nav_msgs::Odometry>("mavros/global_position/local", 10, pose_cb);
56  ros::Rate rate(20.0);
57 
58  tf::TransformBroadcaster brVision;
59  tf::TransformBroadcaster brEKF;
60  tf::Transform Tmap2droneVison;
61  tf::Transform Tmap2droneEKF;
62 
63 
64 
65  while(ros::ok())
66  {
67  //vison pose
68  Tmap2droneVison.setOrigin( tf::Vector3(currentDroneState.pose.position.x, currentDroneState.pose.position.y, currentDroneState.pose.position.z) );
69  tf::Quaternion q;
70  q.setRPY(0, 0, 0);
71  Tmap2droneVison.setRotation(tf::Quaternion(currentDroneState.pose.orientation.x, currentDroneState.pose.orientation.y, currentDroneState.pose.orientation.z, currentDroneState.pose.orientation.w));
72  brVision.sendTransform(tf::StampedTransform(Tmap2droneVison, ros::Time::now(), "map", "droneVsion"));
73 
74  //EKF pose
75  Tmap2droneVison.setOrigin( tf::Vector3(current_poseEKF.pose.pose.position.x, current_poseEKF.pose.pose.position.y, current_poseEKF.pose.pose.position.z) );
76  tf::Quaternion qEKF;
77  qEKF.setRPY(0, 0, 0);
78  Tmap2droneVison.setRotation(tf::Quaternion(current_poseEKF.pose.pose.orientation.x, current_poseEKF.pose.pose.orientation.y, current_poseEKF.pose.pose.orientation.z, current_poseEKF.pose.pose.orientation.w));
79  brEKF.sendTransform(tf::StampedTransform(Tmap2droneEKF, ros::Time::now(), "map", "droneEKF"));
80 
81  //pubStamped.publish(currentDroneState);
82  ros::spinOnce();
83  rate.sleep();
84  }
85 }
nav_msgs::Odometry current_poseEKF
void model_cb(const gazebo_msgs::ModelStates::ConstPtr &msg)
void pose_cb(const nav_msgs::Odometry::ConstPtr &msg)
ros::Subscriber currentPos
int main(int argc, char **argv)
geometry_msgs::PoseStamped currentDroneState