Skip to content

Commit

Permalink
Merge pull request #49 from ichiro-its/enhancement/use-jitsuyo-utils
Browse files Browse the repository at this point in the history
[Sprint 22/23 | PD-421] - [Enhancement] Use Jitsuyo For Utilities
  • Loading branch information
Mobilizes authored Jun 24, 2024
2 parents 26a6923 + 2d94534 commit 2615ed8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ endif()
find_package(ament_cmake REQUIRED)
find_package(ament_index_cpp REQUIRED)
find_package(akushon_interfaces REQUIRED)
find_package(jitsuyo REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_action REQUIRED)
find_package(std_msgs REQUIRED)
Expand Down Expand Up @@ -74,6 +75,7 @@ $<INSTALL_INTERFACE:include>)
ament_target_dependencies(${PROJECT_NAME}
ament_index_cpp
akushon_interfaces
jitsuyo
rclcpp
rclcpp_action
std_msgs
Expand All @@ -84,6 +86,7 @@ ament_target_dependencies(${PROJECT_NAME}
ament_target_dependencies(${PROJECT_NAME}_exported
ament_index_cpp
akushon_interfaces
jitsuyo
rclcpp
rclcpp_action
std_msgs
Expand Down Expand Up @@ -145,6 +148,7 @@ endif()
ament_export_dependencies(
ament_index_cpp
akushon_interfaces
jitsuyo
rclcpp
rclcpp_action
std_msgs
Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>ament_index_cpp</depend>
<depend>akushon_interfaces</depend>
<depend>jitsuyo</depend>
<depend>nlohmann-json-dev</depend>
<depend>rclcpp</depend>
<depend>rclcpp_action</depend>
Expand Down
42 changes: 27 additions & 15 deletions src/akushon/config/utils/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "akushon/action/model/action_name.hpp"
#include "akushon/config/utils/config.hpp"
#include <jitsuyo/config.hpp>
#include "nlohmann/json.hpp"

namespace akushon
Expand All @@ -42,20 +43,30 @@ std::string Config::get_config() const
for (const auto & action_file : std::filesystem::directory_iterator(path)) {
std::string file_name = action_file.path();

try {
std::string action_name = "";
for (auto i = path.size(); i < file_name.size() - 5; i++) {
action_name += file_name[i];
}
std::cout << action_name << " | ";
std::string action_name = "";
for (auto i = path.size(); i < file_name.size() - 5; ++i) {
action_name += file_name[i];
}
std::cout << action_name << " | ";

std::ifstream file(action_file.path());
nlohmann::json action_data;
if (!jitsuyo::load_config(path, action_name + ".json", action_data)) {
std::cerr << "Failed to load " << file_name << std::endl;
continue;
}

std::ifstream file(action_file.path());
nlohmann::json action_data = nlohmann::json::parse(file);
actions_list[action_name] = action_data;
} catch (nlohmann::json::parse_error & ex) {
// TODO(maroqijalil): will be used for logging
// std::cerr << "parse error at byte " << ex.byte << std::endl;
if (action_data["name"] != action_name) {
std::cerr << "Action name does not match file name in " << file_name << std::endl;
continue;
}

if (action_data["poses"].empty()) {
std::cerr << file_name << "\'s poses is empty" << std::endl;
continue;
}

actions_list[action_name] = action_data;
}
std::cout << std::endl;
return actions_list.dump();
Expand All @@ -71,9 +82,10 @@ void Config::save_config(const std::string & actions_data)
std::string file_name = path + action_name + ".json";
std::ofstream file;

file.open(file_name);
file << val.dump(2);
file.close();
if (!jitsuyo::save_config(path, action_name + ".json", val)) {
std::cerr << "Failed to save " << file_name << std::endl;
continue;
}
}
}

Expand Down

0 comments on commit 2615ed8

Please sign in to comment.