Skip to content

Commit

Permalink
fix: porting Jazzy and Rolling bag APIs
Browse files Browse the repository at this point in the history
Signed-off-by: homalozoa <[email protected]>
  • Loading branch information
homalozoa committed Oct 24, 2024
1 parent 8481c2e commit 9159a45
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ch6/ch6_bag_cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ endif()
if(${ROS_DISTRO} STREQUAL "foxy" OR ${ROS_DISTRO} STREQUAL "galactic")
add_compile_definitions(DEPRECATED_BAG_API)
endif()
if(${ROS_DISTRO} STREQUAL "rolling" OR ${ROS_DISTRO} STREQUAL "jazzy")
add_compile_definitions(JAZZY_NEWER_BAG_API)
endif()

set(executable_data pubdata)
set(executable_bag operatebag)
Expand Down
15 changes: 15 additions & 0 deletions ch6/ch6_bag_cpp/src/operatebag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifdef JAZZY_NEWER_BAG_API
#include <filesystem>
#endif
#include <memory>
#include <string>
#include <vector>
Expand All @@ -31,9 +34,17 @@ int main()
const auto LOGTAG = std::string("OperateBag");
using TimeT = builtin_interfaces::msg::Time;
TimeT time = rclcpp::Clock().now();
#ifdef JAZZY_NEWER_BAG_API
auto rosbag_dir = std::filesystem::path("time_box");
#else
auto rosbag_dir = rcpputils::fs::path("time_box");
#endif
rclcpp::Serialization<TimeT> serialization;
#ifdef JAZZY_NEWER_BAG_API
std::filesystem::remove_all(rosbag_dir);
#else
rcpputils::fs::remove_all(rosbag_dir);
#endif
{
#ifdef FOXY_BAG_API
const rosbag2_cpp::StorageOptions storage_options({rosbag_dir.string(), "sqlite3"});
Expand All @@ -54,7 +65,11 @@ int main()
#else
writer.open(rosbag_dir.string());
#endif
#ifndef JAZZY_NEWER_BAG_API
if (rcutils_system_time_now(&write_bag_msg->time_stamp) != RCL_RET_OK) {
#else
if (rcutils_system_time_now(&write_bag_msg->recv_timestamp) != RCL_RET_OK) {
#endif
RCLCPP_ERROR(rclcpp::get_logger(LOGTAG), "Get time failed.");
return 1;
}
Expand Down

0 comments on commit 9159a45

Please sign in to comment.