Skip to content

Commit 5c522d1

Browse files
committed
Add DumpRosbagFromBvh.cpp
1 parent 80d95c1 commit 5c522d1

9 files changed

+65
-8
lines changed

Diff for: CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ project(${PROJECT_NAME} LANGUAGES CXX)
2020
# RBDyn
2121
find_package(RBDyn REQUIRED)
2222

23-
find_package(catkin REQUIRED COMPONENTS roscpp roslib sensor_msgs)
23+
find_package(catkin REQUIRED COMPONENTS roscpp roslib rosbag sensor_msgs)
2424

2525
catkin_package(
2626
CATKIN_DEPENDS
2727
roscpp
2828
roslib
29+
rosbag
2930
sensor_msgs
3031
INCLUDE_DIRS
3132
include

Diff for: README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,21 @@ $ catkin build -DCMAKE_BUILD_TYPE=RelWithDebInfo
1717

1818
## Examples
1919

20+
### Visualize BVH animation
21+
```bash
22+
$ roslaunch mocap_ros_utils visualize_bvh.launch
23+
```
24+
25+
https://github.com/isri-aist/MocapRosUtils/assets/6636600/c1c3b077-3f81-42dd-9d78-1073588b167a
26+
2027
### Dump URDF file from BVH hierarchy data
2128
```bash
2229
$ rosrun mocap_ros_utils GenerateUrdfFromBvh `rospack find mocap_ros_utils`/data/sample_walk.bvh /tmp/BvhRobot.urdf BvhRobot
2330
# Visualize URDF model
2431
$ roslaunch urdf_tutorial display.launch model:=/tmp/BvhRobot.urdf
2532
```
2633

27-
### Visualize BVH motion with TF
34+
### Dump rosbag file from BVH motion data
2835
```bash
29-
$ roslaunch mocap_ros_utils visualize_bvh.launch
36+
$ rosrun mocap_ros_utils DumpRosbagFromBvh `rospack find mocap_ros_utils`/data/sample_walk.bvh /tmp/sample_walk.bag
3037
```
31-
32-
https://github.com/isri-aist/MocapRosUtils/assets/6636600/c1c3b077-3f81-42dd-9d78-1073588b167a

Diff for: include/MocapRosUtils/JointTrajData.h

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class JointTrajData
3131
*/
3232
void publishJointState(bool loop = false) const;
3333

34+
/** \brief Dump joint state message to a rosbag file.
35+
\param rosbag_filename Path of the rosbag file
36+
*/
37+
void dumpRosbag(const std::string & rosbag_filename) const;
38+
3439
public:
3540
//! Sampling period [sec]
3641
double dt_ = 0;

Diff for: node/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
set(MocapRosUtils_node_list GenerateUrdfFromBvh PublishJointStateFromBvh)
1+
set(MocapRosUtils_node_list GenerateUrdfFromBvh PublishJointStateFromBvh
2+
DumpRosbagFromBvh)
23

34
foreach(NAME IN LISTS MocapRosUtils_node_list)
45
add_executable(${NAME} ${NAME}.cpp)

Diff for: node/DumpRosbagFromBvh.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/* Author: Masaki Murooka */
2+
3+
#include <MocapRosUtils/BvhConverter.h>
4+
5+
using namespace MocapRosUtils;
6+
7+
int main(int argc, char ** argv)
8+
{
9+
if(argc != 3)
10+
{
11+
std::cout << "Usage:\n " << argv[0] << " <bvh_file_path> <rosbag_file_path>" << std::endl;
12+
return 1;
13+
}
14+
std::string bvh_filename = argv[1];
15+
std::string rosbag_filename = argv[2];
16+
17+
BvhConverter::Configuration bvh_converter_config;
18+
bvh_converter_config.print_level = 0;
19+
bvh_converter_config.pos_scale = 1e-2;
20+
bvh_converter_config.urdf_cylinder_radius_list = {{"Spine", 0.03}, {"Spine1", 0.03}, {"Head", 0.1}};
21+
bvh_converter_config.disable_end_link_visual = false;
22+
23+
BvhConverter bvh_converter(bvh_filename, bvh_converter_config);
24+
25+
ros::Time::init();
26+
bvh_converter.joint_traj_data_.dumpRosbag(rosbag_filename);
27+
28+
return 0;
29+
}

Diff for: node/GenerateUrdfFromBvh.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ int main(int argc, char ** argv)
2121
bvh_converter_config.print_level = 1;
2222
bvh_converter_config.pos_scale = 1e-2;
2323
bvh_converter_config.urdf_cylinder_radius_list = {{"Spine", 0.03}, {"Spine1", 0.03}, {"Head", 0.1}};
24-
bvh_converter_config.disable_end_link_visual = true;
24+
bvh_converter_config.disable_end_link_visual = false;
2525

2626
BvhConverter bvh_converter(bvh_filename, bvh_converter_config);
2727

Diff for: node/PublishJointStateFromBvh.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main(int argc, char ** argv)
1313
bvh_converter_config.print_level = 0;
1414
bvh_converter_config.pos_scale = 1e-2;
1515
bvh_converter_config.urdf_cylinder_radius_list = {{"Spine", 0.03}, {"Spine1", 0.03}, {"Head", 0.1}};
16-
bvh_converter_config.disable_end_link_visual = true;
16+
bvh_converter_config.disable_end_link_visual = false;
1717

1818
std::string bvh_filename;
1919
nh.getParam("bvh_filename", bvh_filename);

Diff for: package.xml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
<depend>roscpp</depend>
1616
<depend>roslib</depend>
17+
<depend>rosbag</depend>
1718
<depend>sensor_msgs</depend>
1819

1920
<exec_depend>tf2_ros</exec_depend>

Diff for: src/JointTrajData.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include <ros/ros.h>
66

7+
#include <rosbag/bag.h>
8+
79
using namespace MocapRosUtils;
810

911
sensor_msgs::JointState JointTrajData::makeJointStateMsg(int frame_idx) const
@@ -50,3 +52,16 @@ void JointTrajData::publishJointState(bool loop) const
5052
}
5153
}
5254
}
55+
56+
void JointTrajData::dumpRosbag(const std::string & rosbag_filename) const
57+
{
58+
rosbag::Bag bag;
59+
bag.open(rosbag_filename, rosbag::bagmode::Write);
60+
61+
for(int frame_idx = 0; frame_idx < pos_list_.rows(); frame_idx++)
62+
{
63+
bag.write("joint_states", ros::Time::now(), makeJointStateMsg(frame_idx));
64+
}
65+
66+
bag.close();
67+
}

0 commit comments

Comments
 (0)