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 #19

Merged
merged 8 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 6 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
endif()

find_package(ament_cmake REQUIRED)
find_package(jitsuyo REQUIRED)
find_package(keisan REQUIRED)
find_package(ninshiki_interfaces REQUIRED)
find_package(OpenCV REQUIRED)
Expand All @@ -36,25 +37,22 @@ add_library(${PROJECT_NAME} SHARED
"src/${PROJECT_NAME}/config/grpc/call_data_load_config.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_save_color_setting.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_set_color_setting.cpp"
"src/${PROJECT_NAME}/config/utils/config.cpp"
"src/${PROJECT_NAME}/detector/color_detector.cpp"
"src/${PROJECT_NAME}/detector/dnn_detector.cpp"
"src/${PROJECT_NAME}/detector/lbp_detector.cpp"
"src/${PROJECT_NAME}/node/ninshiki_cpp_node.cpp"
"src/${PROJECT_NAME}/utils/color.cpp"
"src/${PROJECT_NAME}/utils/contours.cpp"
"src/${PROJECT_NAME}/utils/circle.cpp"
"src/${PROJECT_NAME}/node/ninshiki_cpp_node.cpp"
"src/${PROJECT_NAME}/utils/utils.cpp")
"src/${PROJECT_NAME}/node/ninshiki_cpp_node.cpp")

add_library(${PROJECT_NAME}_exported SHARED
"src/${PROJECT_NAME}/detector/color_detector.cpp"
"src/${PROJECT_NAME}/detector/dnn_detector.cpp"
"src/${PROJECT_NAME}/detector/lbp_detector.cpp"
"src/${PROJECT_NAME}/utils/color.cpp"
"src/${PROJECT_NAME}/utils/contours.cpp"
"src/${PROJECT_NAME}/utils/circle.cpp"
"src/${PROJECT_NAME}/utils/utils.cpp")
"src/${PROJECT_NAME}/utils/circle.cpp")

target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand All @@ -65,6 +63,7 @@ target_include_directories(${PROJECT_NAME}_exported PUBLIC
$<INSTALL_INTERFACE:include>)

ament_target_dependencies(${PROJECT_NAME}
jitsuyo
keisan
ninshiki_interfaces
OpenCV
Expand All @@ -75,6 +74,7 @@ ament_target_dependencies(${PROJECT_NAME}
gRPC)

ament_target_dependencies(${PROJECT_NAME}_exported
jitsuyo
keisan
ninshiki_interfaces
OpenCV
Expand Down Expand Up @@ -118,6 +118,7 @@ if(BUILD_TESTING)
endif()

ament_export_dependencies(
jitsuyo
keisan
ninshiki_interfaces
OpenCV
Expand Down
47 changes: 0 additions & 47 deletions include/ninshiki_cpp/config/utils/config.hpp

This file was deleted.

1 change: 0 additions & 1 deletion include/ninshiki_cpp/detector/color_detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "keisan/geometry/point_2.hpp"
#include "ninshiki_cpp/detector/detector.hpp"
#include "ninshiki_cpp/utils/color.hpp"
#include "ninshiki_cpp/utils/utils.hpp"
#include "ninshiki_interfaces/msg/point.hpp"
#include "ninshiki_interfaces/msg/contour.hpp"
#include "ninshiki_interfaces/msg/contours.hpp"
Expand Down
1 change: 0 additions & 1 deletion include/ninshiki_cpp/detector/detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#ifndef NINSHIKI_CPP__DETECTOR__DETECTOR_HPP_
#define NINSHIKI_CPP__DETECTOR__DETECTOR_HPP_

#include "ninshiki_cpp/utils/utils.hpp"
#include "ninshiki_interfaces/msg/detected_object.hpp"
#include "ninshiki_interfaces/msg/detected_objects.hpp"

Expand Down
1 change: 0 additions & 1 deletion include/ninshiki_cpp/detector/dnn_detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#define NINSHIKI_CPP__DETECTOR__DNN_DETECTOR_HPP_

#include "ninshiki_cpp/detector/detector.hpp"
#include "ninshiki_cpp/utils/utils.hpp"
#include "ninshiki_interfaces/msg/detected_object.hpp"
#include "ninshiki_interfaces/msg/detected_objects.hpp"

Expand Down
1 change: 0 additions & 1 deletion include/ninshiki_cpp/detector/lbp_detector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#define NINSHIKI_CPP__DETECTOR__LBP_DETECTOR_HPP_

#include "ninshiki_cpp/detector/detector.hpp"
#include "ninshiki_cpp/utils/utils.hpp"
#include "ninshiki_interfaces/msg/detected_object.hpp"
#include "ninshiki_interfaces/msg/detected_objects.hpp"

Expand Down
43 changes: 0 additions & 43 deletions include/ninshiki_cpp/utils/utils.hpp

This file was deleted.

1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<maintainer email="[email protected]">Nathanael</maintainer>
<license>MIT License</license>
<buildtool_depend>ament_cmake</buildtool_depend>
<depend>jitsuyo</depend>
<depend>keisan</depend>
<depend>libopencv-dev</depend>
<depend>ninshiki_interfaces</depend>
Expand Down
11 changes: 8 additions & 3 deletions src/ninshiki_cpp/config/grpc/call_data_get_color_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
// THE SOFTWARE.

#include "ninshiki_cpp/config/grpc/call_data_get_color_setting.hpp"
#include "ninshiki_cpp/config/utils/config.hpp"

#include "jitsuyo/config.hpp"
#include "ninshiki_interfaces/ninshiki.grpc.pb.h"
#include "ninshiki_interfaces/ninshiki.pb.h"
#include "rclcpp/rclcpp.hpp"
Expand All @@ -46,8 +47,12 @@ void CallDataGetColorSetting::WaitForRequest()

void CallDataGetColorSetting::HandleRequest()
{
Config config(path_);
reply_.set_json_color(config.get_color_setting("color"));
nlohmann::json data;
if (!jitsuyo::load_config(path_, "color_classifier.json", data)) {
RCLCPP_ERROR(rclcpp::get_logger("Get config"), "Failed to load config!");
return;
}
reply_.set_json_color(data.dump());
RCLCPP_INFO(rclcpp::get_logger("Get config"), "config has been sent!");
}
} // namespace ninshiki_cpp
3 changes: 2 additions & 1 deletion src/ninshiki_cpp/config/grpc/call_data_load_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
// THE SOFTWARE.

#include "ninshiki_cpp/config/grpc/call_data_load_config.hpp"
#include "ninshiki_cpp/config/utils/config.hpp"

#include "ninshiki_interfaces/ninshiki.grpc.pb.h"
#include "ninshiki_interfaces/ninshiki.pb.h"
#include "nlohmann/json.hpp"
Mobilizes marked this conversation as resolved.
Show resolved Hide resolved
#include "rclcpp/rclcpp.hpp"

namespace ninshiki_cpp
Expand Down
6 changes: 3 additions & 3 deletions src/ninshiki_cpp/config/grpc/call_data_save_color_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
// THE SOFTWARE.

#include "ninshiki_cpp/config/grpc/call_data_save_color_setting.hpp"
#include "ninshiki_cpp/config/utils/config.hpp"

#include "jitsuyo/config.hpp"
#include "ninshiki_interfaces/ninshiki.grpc.pb.h"
#include "ninshiki_interfaces/ninshiki.pb.h"
#include "nlohmann/json.hpp"
Expand Down Expand Up @@ -47,12 +48,11 @@ void CallDataSaveColorSetting::WaitForRequest()

void CallDataSaveColorSetting::HandleRequest()
{
Config config(path_);
try {
std::string json_string = request_.json_color();
nlohmann::json color_data = nlohmann::json::parse(json_string);

config.save_color_setting(color_data);
jitsuyo::save_config(path_, "color_classifier.json", color_data);
RCLCPP_INFO(rclcpp::get_logger("Save config"), "config has been saved!");
} catch (nlohmann::json::exception & e) {
RCLCPP_ERROR(rclcpp::get_logger("Save config"), e.what());
Expand Down
4 changes: 2 additions & 2 deletions src/ninshiki_cpp/config/grpc/call_data_set_color_setting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
// THE SOFTWARE.

#include "ninshiki_cpp/config/grpc/call_data_set_color_setting.hpp"
#include "ninshiki_cpp/config/utils/config.hpp"

#include "ninshiki_interfaces/ninshiki.grpc.pb.h"
#include "ninshiki_interfaces/ninshiki.pb.h"
#include "nlohmann/json.hpp"
Mobilizes marked this conversation as resolved.
Show resolved Hide resolved
#include "rclcpp/rclcpp.hpp"

namespace ninshiki_cpp
Expand All @@ -46,7 +47,6 @@ void CallDataSetColorSetting::WaitForRequest()

void CallDataSetColorSetting::HandleRequest()
{
Config config(path_);
try {
utils::Color color(
request_.name(),
Expand Down
10 changes: 7 additions & 3 deletions src/ninshiki_cpp/config/grpc/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#include "jitsuyo/config.hpp"
#include "rclcpp/rclcpp.hpp"
#include "ninshiki_cpp/config/grpc/call_data_base.hpp"
#include "ninshiki_cpp/config/grpc/call_data_get_color_setting.hpp"
#include "ninshiki_cpp/config/grpc/call_data_load_config.hpp"
#include "ninshiki_cpp/config/grpc/call_data_save_color_setting.hpp"
#include "ninshiki_cpp/config/grpc/call_data_set_color_setting.hpp"
#include "ninshiki_cpp/config/grpc/config.hpp"
#include "ninshiki_cpp/config/utils/config.hpp"

#include <chrono>
#include <csignal>
Expand Down Expand Up @@ -54,9 +54,13 @@ void ConfigGrpc::SignIntHandler(int signum)

void ConfigGrpc::Run(const std::string & path, std::shared_ptr<ninshiki_cpp::detector::ColorDetector> color_detection)
{
Config config(path);
nlohmann::json grpc_config;
if (!jitsuyo::load_config(path, "grpc.json", grpc_config)) {
RCLCPP_ERROR(rclcpp::get_logger("ConfigGrpc"), "Failed to load grpc config");
return;
}
std::string server_address =
absl::StrFormat("0.0.0.0:%d", config.get_grpc_config()["port"].get<uint16_t>());
absl::StrFormat("0.0.0.0:%d", grpc_config["port"].get<uint16_t>());

ServerBuilder builder;
builder.AddListeningPort(server_address, grpc::InsecureServerCredentials());
Expand Down
58 changes: 0 additions & 58 deletions src/ninshiki_cpp/config/utils/config.cpp

This file was deleted.

Loading
Loading