Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Sprint 22/23 | PD-421] - [Enhancement] Use Jitsuyo For Utilities #49

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading