Skip to content

Commit 1883a2a

Browse files
committed
first commit
0 parents  commit 1883a2a

File tree

5 files changed

+361
-0
lines changed

5 files changed

+361
-0
lines changed

CMakeLists.txt

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
cmake_minimum_required(VERSION 3.0.2)
2+
project(rosbag_data)
3+
4+
## Compile as C++11, supported in ROS Kinetic and newer
5+
# add_compile_options(-std=c++11)
6+
7+
## Find catkin macros and libraries
8+
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
9+
## is used, also find other catkin packages
10+
find_package(catkin REQUIRED COMPONENTS
11+
nav_msgs
12+
rosbag
13+
roscpp
14+
rospy
15+
sensor_msgs
16+
)
17+
18+
## System dependencies are found with CMake's conventions
19+
# find_package(Boost REQUIRED COMPONENTS system)
20+
21+
22+
## Uncomment this if the package has a setup.py. This macro ensures
23+
## modules and global scripts declared therein get installed
24+
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
25+
# catkin_python_setup()
26+
27+
################################################
28+
## Declare ROS messages, services and actions ##
29+
################################################
30+
31+
## To declare and build messages, services or actions from within this
32+
## package, follow these steps:
33+
## * Let MSG_DEP_SET be the set of packages whose message types you use in
34+
## your messages/services/actions (e.g. std_msgs, actionlib_msgs, ...).
35+
## * In the file package.xml:
36+
## * add a build_depend tag for "message_generation"
37+
## * add a build_depend and a exec_depend tag for each package in MSG_DEP_SET
38+
## * If MSG_DEP_SET isn't empty the following dependency has been pulled in
39+
## but can be declared for certainty nonetheless:
40+
## * add a exec_depend tag for "message_runtime"
41+
## * In this file (CMakeLists.txt):
42+
## * add "message_generation" and every package in MSG_DEP_SET to
43+
## find_package(catkin REQUIRED COMPONENTS ...)
44+
## * add "message_runtime" and every package in MSG_DEP_SET to
45+
## catkin_package(CATKIN_DEPENDS ...)
46+
## * uncomment the add_*_files sections below as needed
47+
## and list every .msg/.srv/.action file to be processed
48+
## * uncomment the generate_messages entry below
49+
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)
50+
51+
## Generate messages in the 'msg' folder
52+
# add_message_files(
53+
# FILES
54+
# Message1.msg
55+
# Message2.msg
56+
# )
57+
58+
## Generate services in the 'srv' folder
59+
# add_service_files(
60+
# FILES
61+
# Service1.srv
62+
# Service2.srv
63+
# )
64+
65+
## Generate actions in the 'action' folder
66+
# add_action_files(
67+
# FILES
68+
# Action1.action
69+
# Action2.action
70+
# )
71+
72+
## Generate added messages and services with any dependencies listed here
73+
# generate_messages(
74+
# DEPENDENCIES
75+
# nav_msgs# sensor_msgs
76+
# )
77+
78+
################################################
79+
## Declare ROS dynamic reconfigure parameters ##
80+
################################################
81+
82+
## To declare and build dynamic reconfigure parameters within this
83+
## package, follow these steps:
84+
## * In the file package.xml:
85+
## * add a build_depend and a exec_depend tag for "dynamic_reconfigure"
86+
## * In this file (CMakeLists.txt):
87+
## * add "dynamic_reconfigure" to
88+
## find_package(catkin REQUIRED COMPONENTS ...)
89+
## * uncomment the "generate_dynamic_reconfigure_options" section below
90+
## and list every .cfg file to be processed
91+
92+
## Generate dynamic reconfigure parameters in the 'cfg' folder
93+
# generate_dynamic_reconfigure_options(
94+
# cfg/DynReconf1.cfg
95+
# cfg/DynReconf2.cfg
96+
# )
97+
98+
###################################
99+
## catkin specific configuration ##
100+
###################################
101+
## The catkin_package macro generates cmake config files for your package
102+
## Declare things to be passed to dependent projects
103+
## INCLUDE_DIRS: uncomment this if your package contains header files
104+
## LIBRARIES: libraries you create in this project that dependent projects also need
105+
## CATKIN_DEPENDS: catkin_packages dependent projects also need
106+
## DEPENDS: system dependencies of this project that dependent projects also need
107+
catkin_package(
108+
# INCLUDE_DIRS include
109+
# LIBRARIES rosbag_data
110+
# CATKIN_DEPENDS nav_msgs rosbag roscpp rospy sensor_msgs
111+
# DEPENDS system_lib
112+
)
113+
114+
###########
115+
## Build ##
116+
###########
117+
118+
## Specify additional locations of header files
119+
## Your package locations should be listed before other locations
120+
include_directories(
121+
# include
122+
${catkin_INCLUDE_DIRS}
123+
)
124+
125+
## Declare a C++ library
126+
# add_library(${PROJECT_NAME}
127+
# src/${PROJECT_NAME}/rosbag_data.cpp
128+
# )
129+
130+
## Add cmake target dependencies of the library
131+
## as an example, code may need to be generated before libraries
132+
## either from message generation or dynamic reconfigure
133+
# add_dependencies(${PROJECT_NAME} ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
134+
135+
## Declare a C++ executable
136+
## With catkin_make all packages are built within a single CMake context
137+
## The recommended prefix ensures that target names across packages don't collide
138+
add_executable(get_data_node src/get_data.cpp)
139+
## Rename C++ executable without prefix
140+
## The above recommended prefix causes long target names, the following renames the
141+
## target back to the shorter version for ease of user use
142+
## e.g. "rosrun someones_pkg node" instead of "rosrun someones_pkg someones_pkg_node"
143+
# set_target_properties(${PROJECT_NAME}_node PROPERTIES OUTPUT_NAME node PREFIX "")
144+
145+
## Add cmake target dependencies of the executable
146+
## same as for the library above
147+
# add_dependencies(${PROJECT_NAME}_node ${${PROJECT_NAME}_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
148+
149+
## Specify libraries to link a library or executable target against
150+
target_link_libraries(get_data_node
151+
${catkin_LIBRARIES}
152+
)
153+
154+
#############
155+
## Install ##
156+
#############
157+
158+
# all install targets should use catkin DESTINATION variables
159+
# See http://ros.org/doc/api/catkin/html/adv_user_guide/variables.html
160+
161+
## Mark executable scripts (Python etc.) for installation
162+
## in contrast to setup.py, you can choose the destination
163+
# catkin_install_python(PROGRAMS
164+
# scripts/my_python_script
165+
# DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
166+
# )
167+
168+
## Mark executables for installation
169+
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_executables.html
170+
# install(TARGETS ${PROJECT_NAME}_node
171+
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
172+
# )
173+
174+
## Mark libraries for installation
175+
## See http://docs.ros.org/melodic/api/catkin/html/howto/format1/building_libraries.html
176+
# install(TARGETS ${PROJECT_NAME}
177+
# ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
178+
# LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
179+
# RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION}
180+
# )
181+
182+
## Mark cpp header files for installation
183+
# install(DIRECTORY include/${PROJECT_NAME}/
184+
# DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
185+
# FILES_MATCHING PATTERN "*.h"
186+
# PATTERN ".svn" EXCLUDE
187+
# )
188+
189+
## Mark other files for installation (e.g. launch and bag files, etc.)
190+
# install(FILES
191+
# # myfile1
192+
# # myfile2
193+
# DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
194+
# )
195+
196+
#############
197+
## Testing ##
198+
#############
199+
200+
## Add gtest based cpp test target and link libraries
201+
# catkin_add_gtest(${PROJECT_NAME}-test test/test_rosbag_data.cpp)
202+
# if(TARGET ${PROJECT_NAME}-test)
203+
# target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})
204+
# endif()
205+
206+
## Add folders to be run by python nosetests
207+
# catkin_add_nosetests(test)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#将ROSBag中的imu数据保存到txt文件中

launch/run_getbag.launch

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<launch>
2+
<node name="get_data" pkg="rosbag_data" type="get_data_node">
3+
<param name="BAGPATH" type="string" value="/home/xh_cai/Rosbag/20230314/imu_mag_img_2023-03-14-16-50-17.bag"/>
4+
</node>
5+
</launch>

package.xml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0"?>
2+
<package format="2">
3+
<name>rosbag_data</name>
4+
<version>0.0.0</version>
5+
<description>The rosbag_data package</description>
6+
7+
<!-- One maintainer tag required, multiple allowed, one person per tag -->
8+
<!-- Example: -->
9+
<!-- <maintainer email="[email protected]">Jane Doe</maintainer> -->
10+
<maintainer email="[email protected]">xh_cai</maintainer>
11+
12+
13+
<!-- One license tag required, multiple allowed, one license per tag -->
14+
<!-- Commonly used license strings: -->
15+
<!-- BSD, MIT, Boost Software License, GPLv2, GPLv3, LGPLv2.1, LGPLv3 -->
16+
<license>TODO</license>
17+
18+
19+
<!-- Url tags are optional, but multiple are allowed, one per tag -->
20+
<!-- Optional attribute type can be: website, bugtracker, or repository -->
21+
<!-- Example: -->
22+
<!-- <url type="website">http://wiki.ros.org/rosbag_data</url> -->
23+
24+
25+
<!-- Author tags are optional, multiple are allowed, one per tag -->
26+
<!-- Authors do not have to be maintainers, but could be -->
27+
<!-- Example: -->
28+
<!-- <author email="[email protected]">Jane Doe</author> -->
29+
30+
31+
<!-- The *depend tags are used to specify dependencies -->
32+
<!-- Dependencies can be catkin packages or system dependencies -->
33+
<!-- Examples: -->
34+
<!-- Use depend as a shortcut for packages that are both build and exec dependencies -->
35+
<!-- <depend>roscpp</depend> -->
36+
<!-- Note that this is equivalent to the following: -->
37+
<!-- <build_depend>roscpp</build_depend> -->
38+
<!-- <exec_depend>roscpp</exec_depend> -->
39+
<!-- Use build_depend for packages you need at compile time: -->
40+
<!-- <build_depend>message_generation</build_depend> -->
41+
<!-- Use build_export_depend for packages you need in order to build against this package: -->
42+
<!-- <build_export_depend>message_generation</build_export_depend> -->
43+
<!-- Use buildtool_depend for build tool packages: -->
44+
<!-- <buildtool_depend>catkin</buildtool_depend> -->
45+
<!-- Use exec_depend for packages you need at runtime: -->
46+
<!-- <exec_depend>message_runtime</exec_depend> -->
47+
<!-- Use test_depend for packages you need only for testing: -->
48+
<!-- <test_depend>gtest</test_depend> -->
49+
<!-- Use doc_depend for packages you need only for building documentation: -->
50+
<!-- <doc_depend>doxygen</doc_depend> -->
51+
<buildtool_depend>catkin</buildtool_depend>
52+
<build_depend>nav_msgs</build_depend>
53+
<build_depend>rosbag</build_depend>
54+
<build_depend>roscpp</build_depend>
55+
<build_depend>rospy</build_depend>
56+
<build_depend>sensor_msgs</build_depend>
57+
<build_depend>geometry_msgs</build_depend>
58+
<build_export_depend>nav_msgs</build_export_depend>
59+
<build_export_depend>rosbag</build_export_depend>
60+
<build_export_depend>roscpp</build_export_depend>
61+
<build_export_depend>rospy</build_export_depend>
62+
<build_export_depend>sensor_msgs</build_export_depend>
63+
<build_export_depend>geometry_msgs</build_export_depend>
64+
<exec_depend>nav_msgs</exec_depend>
65+
<exec_depend>rosbag</exec_depend>
66+
<exec_depend>roscpp</exec_depend>
67+
<exec_depend>rospy</exec_depend>
68+
<exec_depend>sensor_msgs</exec_depend>
69+
<exec_depend>geometry_msgs</exec_depend>
70+
71+
72+
<!-- The export tag contains other, unspecified, tags -->
73+
<export>
74+
<!-- Other tools can request additional information be placed here -->
75+
76+
</export>
77+
</package>

src/get_data.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#include <ros/ros.h>
2+
#include <nav_msgs/Odometry.h>
3+
#include <geometry_msgs/PoseWithCovarianceStamped.h>
4+
#include <rosbag/bag.h>
5+
#include <rosbag/view.h>
6+
#include <sensor_msgs/Imu.h>
7+
8+
#include <string>
9+
#include <fstream>
10+
11+
int main(int argc, char **argv)
12+
{
13+
ros::init(argc,argv,"get_data");
14+
ros::NodeHandle nh;
15+
16+
rosbag::Bag mybag;
17+
std::string bagpath;
18+
//nh.getParam("BAGPATH",bagpath,"/home/xh_cai/Project/XhProject/openvins_nx_debug/rosbag/2022_11_1/trace_2022-11-01-13-41-45.bag");
19+
mybag.open("/home/xh_cai/Rosbag/20230314/imu_mag_img_2023-03-14-16-50-17.bag",rosbag::bagmode::Read);
20+
std::vector<std::string> topics;
21+
22+
topics.push_back(std::string("/fdi_imu"));
23+
topics.push_back(std::string("/mavros/imu/data"));
24+
25+
rosbag::View view(mybag,rosbag::TopicQuery(topics));
26+
27+
rosbag::View::iterator it = view.begin();
28+
29+
for(; it != view.end(); ++it)
30+
{
31+
auto m = *it;
32+
std::string topic = m.getTopic();
33+
34+
if(topic == "/fdi_imu")
35+
{
36+
sensor_msgs::Imu::ConstPtr fdimu = m.instantiate<sensor_msgs::Imu>();
37+
std::ofstream foutt265("/home/xh_cai/Project/XhProject/getimudata_ws/src/out/fdimu.txt",std::ios::app);
38+
foutt265.setf(std::ios::fixed,std::ios::floatfield);
39+
foutt265.precision(0);
40+
foutt265 << fdimu->header.stamp.toSec()*1e3 << " ";
41+
foutt265.precision(5);
42+
foutt265 << fdimu->angular_velocity.x<< " "
43+
<< fdimu->angular_velocity.y << " "
44+
<< fdimu->angular_velocity.z << " "
45+
<< fdimu->linear_acceleration.x << " "
46+
<< fdimu->linear_acceleration.y << " "
47+
<< fdimu->linear_acceleration.z <<std::endl;
48+
foutt265.close();
49+
50+
}
51+
if(topic == "/mavros/imu/data")
52+
{
53+
sensor_msgs::Imu::ConstPtr mavrosimu = m.instantiate<sensor_msgs::Imu>();
54+
std::ofstream foutvins("/home/xh_cai/Project/XhProject/getimudata_ws/src/out/mavrosimu.txt",std::ios::app);
55+
foutvins.setf(std::ios::fixed,std::ios::floatfield);
56+
foutvins.precision(0);
57+
foutvins << mavrosimu->header.stamp.toSec()*1e3 << " ";
58+
foutvins.precision(5);
59+
foutvins << mavrosimu->angular_velocity.x<< " "
60+
<< mavrosimu->angular_velocity.y << " "
61+
<< mavrosimu->angular_velocity.z << " "
62+
<< mavrosimu->linear_acceleration.x << " "
63+
<< mavrosimu->linear_acceleration.y << " "
64+
<< mavrosimu->linear_acceleration.z <<std::endl;
65+
foutvins.close();
66+
67+
}
68+
}
69+
mybag.close();
70+
71+
}

0 commit comments

Comments
 (0)