After I design and obtain all the data, I should find a method to record all my data. Here I use rosbag.
The rosbag can record all the published data, which means the data muss be messages and must be published by the topics.
Record Data
1. Enter your package and build a /bagfiles
2. Start to use rosbag command to record your data
- Here I want to record all the published topics, so I use
-a
rosbag record -a
- Or you can set your bagfile name and select which topics you want to record by using
-O
(upper case!)
rosbag record -O traj1.bag /q_state /vel_state /acc_state /tau_state /timestamp
because I combine the above msg into one msg type Dym_Data
and the topic is called /dym_state
, so I use:
rosbag record -O traj1.bag /dym_state
You can see:
[ INFO] [1577552509.209159767]: Subscribing to /acc_state
[ INFO] [1577552509.211626224]: Subscribing to /q_state
[ INFO] [1577552509.214206995]: Subscribing to /tau_state
[ INFO] [1577552509.216982598]: Subscribing to /timestamp
[ INFO] [1577552509.219205895]: Subscribing to /vel_state
[ INFO] [1577552509.453516103, 13183.184000000]: Recording to traj1.bag.
3. After running your programm, you should type “ctrl+c
” to the rosbag terminal to stop it
4.rosbag info
command to check the info
A .bag
file can be found in your /bagfiles
- named as “date-time.bag” (e.g. 2019-12-28-17-05-16.bag),
- or named as you set “traj1.bag”
Now you can use rosbag info
command to check the info of this bag.
rosbag info 2019-12-28-17-05-16.bag
You can see:
- 2019-12-28-17-05-16.bag record all data
path: 2019-12-28-17-05-16.bag
version: 2.0
duration: 28.3s
start: Jan 01 1970 03:57:32.82 (10652.82)
end: Jan 01 1970 03:58:01.14 (10681.14)
size: 90.5 MB
messages: 113270
compression: none [118/118 chunks]
types: dynamic_reconfigure/Config [958f16a05573709014982821e6822580]
dynamic_reconfigure/ConfigDescription [757ce9d44ba8ddd801bb30bc456f946f]
gazebo_msgs/ContactsState [acbcb1601a8e525bf72509f18e6f668d]
gazebo_msgs/LinkStates [48c080191eb15c41858319b4d8a609c2]
gazebo_msgs/ModelStates [48c080191eb15c41858319b4d8a609c2]
rosgraph_msgs/Clock [a9c97c1d230cfc112e270351a944ee47]
rosgraph_msgs/Log [acffd30cd6b6de30f120938c17c593fb]
sensor_msgs/JointState [3066dcd76a6cfaef579bd0f34173e9fd]
std_msgs/Float64 [fdb28210bfa9d7c91146260178d9a584]
std_msgs/Float64MultiArray [4b7d974086d4060e7db4613a7e6c3ba4]
tf2_msgs/TFMessage [94810edda583a504dfda3829e70d7eec]
topics: /acc_state 1628 msgs : std_msgs/Float64MultiArray
/clock 28327 msgs : rosgraph_msgs/Clock
/franka/joint1_position_controller/command 1629 msgs : std_msgs/Float64
/franka/joint2_position_controller/command 1629 msgs : std_msgs/Float64
/franka/joint3_position_controller/command 1629 msgs : std_msgs/Float64
/franka/joint4_position_controller/command 1629 msgs : std_msgs/Float64
/franka/joint5_position_controller/command 1629 msgs : std_msgs/Float64
/franka/joint6_position_controller/command 1629 msgs : std_msgs/Float64
/franka/joint7_position_controller/command 1629 msgs : std_msgs/Float64
/gazebo/link_states 28234 msgs : gazebo_msgs/LinkStates
/gazebo/model_states 28239 msgs : gazebo_msgs/ModelStates
/gazebo/parameter_descriptions 1 msg : dynamic_reconfigure/ConfigDescription
/gazebo/parameter_updates 1 msg : dynamic_reconfigure/Config
/gazebo_gui/parameter_descriptions 1 msg : dynamic_reconfigure/ConfigDescription
/gazebo_gui/parameter_updates 1 msg : dynamic_reconfigure/Config
/gazebo_ros_control/pid_gains/panda_joint1/parameter_descriptions 1 msg : dynamic_reconfigure/ConfigDescription
/gazebo_ros_control/pid_gains/panda_joint1/parameter_updates 1 msg : dynamic_reconfigure/Config
/gazebo_ros_control/pid_gains/panda_joint2/parameter_descriptions 1 msg : dynamic_reconfigure/ConfigDescription
/gazebo_ros_control/pid_gains/panda_joint2/parameter_updates 1 msg : dynamic_reconfigure/Config
/gazebo_ros_control/pid_gains/panda_joint3/parameter_descriptions 1 msg : dynamic_reconfigure/ConfigDescription
/gazebo_ros_control/pid_gains/panda_joint3/parameter_updates 1 msg : dynamic_reconfigure/Config
/gazebo_ros_control/pid_gains/panda_joint4/parameter_descriptions 1 msg : dynamic_reconfigure/ConfigDescription
/gazebo_ros_control/pid_gains/panda_joint4/parameter_updates 1 msg : dynamic_reconfigure/Config
/gazebo_ros_control/pid_gains/panda_joint5/parameter_descriptions 1 msg : dynamic_reconfigure/ConfigDescription
/gazebo_ros_control/pid_gains/panda_joint5/parameter_updates 1 msg : dynamic_reconfigure/Config
/gazebo_ros_control/pid_gains/panda_joint6/parameter_descriptions 1 msg : dynamic_reconfigure/ConfigDescription
/gazebo_ros_control/pid_gains/panda_joint6/parameter_updates 1 msg : dynamic_reconfigure/Config
/gazebo_ros_control/pid_gains/panda_joint7/parameter_descriptions 1 msg : dynamic_reconfigure/ConfigDescription
/gazebo_ros_control/pid_gains/panda_joint7/parameter_updates 1 msg : dynamic_reconfigure/Config
/joint_states 1111 msgs : sensor_msgs/JointState
/panda_link0_contact_sensor_state 830 msgs : gazebo_msgs/ContactsState
/panda_link1_contact_sensor_state 827 msgs : gazebo_msgs/ContactsState
/panda_link2_contact_sensor_state 829 msgs : gazebo_msgs/ContactsState
/panda_link3_contact_sensor_state 829 msgs : gazebo_msgs/ContactsState
/panda_link4_contact_sensor_state 829 msgs : gazebo_msgs/ContactsState
/panda_link5_contact_sensor_state 829 msgs : gazebo_msgs/ContactsState
/panda_link6_contact_sensor_state 829 msgs : gazebo_msgs/ContactsState
/panda_link7_contact_sensor_state 829 msgs : gazebo_msgs/ContactsState
/q_state 1628 msgs : std_msgs/Float64MultiArray
/rosout 35 msgs : rosgraph_msgs/Log (5 connections)
/rosout_agg 20 msgs : rosgraph_msgs/Log
/tau_state 1628 msgs : std_msgs/Float64MultiArray
/tf 1111 msgs : tf2_msgs/TFMessage
/tf_static 1 msg : tf2_msgs/TFMessage
/timestamp 1628 msgs : std_msgs/Float64
/vel_state 1628 msgs : std_msgs/Float64MultiArray
- traj1.bag record specific data
path: traj1.bag
version: 2.0
duration: 18.2s
start: Jan 01 1970 04:54:39.98 (14079.98)
end: Jan 01 1970 04:54:58.13 (14098.13)
size: 1.0 MB
messages: 9080
compression: none [2/2 chunks]
types: std_msgs/Float64 [fdb28210bfa9d7c91146260178d9a584]
std_msgs/Float64MultiArray [4b7d974086d4060e7db4613a7e6c3ba4]
topics: /acc_state 1816 msgs : std_msgs/Float64MultiArray
/q_state 1816 msgs : std_msgs/Float64MultiArray
/tau_state 1816 msgs : std_msgs/Float64MultiArray
/timestamp 1816 msgs : std_msgs/Float64
/vel_state 1816 msgs : std_msgs/Float64MultiArray
5. This command can replay the data from the bag.
6.Transform .bag
data to .txt
file
Enter your /bagfiles
, run this command:
rostopic echo -b file-name.bag -p /topic-name > Txt-name.txt
NOTE!!!
I got the trouble like Problem including rosbag.h.
After above operations you can’t directly use rosbag in your code. You should add some links for rosbag in your package.
find_package(catkin REQUIRED COMPONENTS
roscpp
rospy
########
std_msgs
message_generation
rosbag REQUIRED
gazebo REQUIRED
##########
)
catkin_package(
LIBRARIES
franka_robot
CATKIN_DEPENDS
roscpp message_runtime std_msgs rosbag
)
your node also!
target_link_libraries(robot_record
${catkin_LIBRARIES}
${Eigen3_LIBRARIES}
${rosbag_LIBRARIES}
)