main.cpp
Go to the documentation of this file.
1 
18 #include "ros/ros.h"
19 #include "move_base_msgs/MoveBaseActionGoal.h"
20 #include <fstream>
21 #include <sstream>
22 #include <string>
23 #include <ctime>
24 
25 
26 std::time_t t = std::time(0);
27 std::string path = std::to_string(t)+"posen.xml";
28 
29 void chatterCallback(const move_base_msgs::MoveBaseActionGoal::ConstPtr& msg)
30 {
31  std::string xmlString;
32 
33  float x = msg->goal.target_pose.pose.position.x;
34  float y = msg->goal.target_pose.pose.position.y;
35  float z = msg->goal.target_pose.pose.position.z;
36 
37  float xq = msg->goal.target_pose.pose.orientation.x;
38  float yq = msg->goal.target_pose.pose.orientation.y;
39  float zq = msg->goal.target_pose.pose.orientation.z;
40  float wq = msg->goal.target_pose.pose.orientation.w;
41 
42  ROS_INFO("I heard x : [%f]",x);
43  ROS_INFO("I heard y : [%f]",y);
44  ROS_INFO("I heard z : [%f]",z);
45 
46  ROS_INFO("I heard x quat : [%f]",xq);
47  ROS_INFO("I heard y quat : [%f]",yq);
48  ROS_INFO("I heard z quat : [%f]",zq);
49  ROS_INFO("I heard w quat : [%f]",wq);
50 
51  xmlString += "<Pose X=\""+std::to_string(x)+"\" ";
52  xmlString += "Y=\""+std::to_string(y)+"\" ";
53  xmlString += "Z=\""+std::to_string(z)+"\" ";
54  xmlString += "XQ=\""+std::to_string(xq)+"\" ";
55  xmlString += "YQ=\""+std::to_string(yq)+"\" ";
56  xmlString += "ZQ=\""+std::to_string(zq)+"\" ";
57  xmlString += "WQ=\""+std::to_string(wq)+"\"></Pose>";
58 
59  std::ofstream pose_xml_file(path,std::ofstream::out|std::ofstream::app);
60  pose_xml_file << xmlString << std::endl;
61  pose_xml_file.close();
62 
63 }
64 
65 int main(int argc, char **argv)
66 {
67 
68  std::string xmlString = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
69  std::ofstream pose_xml_file(path,std::ofstream::out|std::ofstream::app);
70  pose_xml_file << xmlString << std::endl << "<Posen>" << std::endl;
71 
72  ros::init(argc, argv, "asr_rviz_pose_manager");
73 
75 
76  ros::Subscriber sub = n.subscribe("move_base/goal", 1000, chatterCallback);
77 
78  ros::spin();
79 
80  pose_xml_file << "</Posen>" << std::endl;
81  pose_xml_file.close();
82 
83 
84  return 0;
85 }
std::string path
Definition: main.cpp:27
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
int main(int argc, char **argv)
Definition: main.cpp:65
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
#define ROS_INFO(...)
ROSCPP_DECL void spin()
void chatterCallback(const move_base_msgs::MoveBaseActionGoal::ConstPtr &msg)
Definition: main.cpp:29
std::time_t t
Definition: main.cpp:26


asr_rviz_pose_manager
Author(s): Borella Jocelyn
autogenerated on Mon Jun 10 2019 12:43:10