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-405] [Feature] Add implementation GRPC #13

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 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
51 changes: 51 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"configurations": [
{
"browse": {
"databaseFilename": "${default}",
"limitSymbolsToIncludedHeaders": false
},
"includePath": [
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/suiryoku/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/atama/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/aruku/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/kansei/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/akushon/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/tachimawari/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/tachimawari_interfaces/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/suiryoku_interfaces/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/ninshiki_cpp/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/shisen_cpp/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/shisen_interfaces/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/ninshiki_interfaces/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/keisan/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/kansei_interfaces/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/image_geometry/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/cv_bridge/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/atama_interfaces/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/aruku_interfaces/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/akushon_interfaces/include/**",
"/opt/ros/iron/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/src/akushon/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/src/aruku/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/src/atama/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/src/kansei/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/src/keisan/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/src/ninshiki_cpp/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/src/shisen_cpp/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/src/soccer/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/src/suiryoku/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/src/tachimawari/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/src/vision_opencv/cv_bridge/include/**",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/src/vision_opencv/image_geometry/include/**",
"/usr/include/**"
],
"name": "ROS",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++14"
}
],
"version": 4
}
34 changes: 34 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"python.autoComplete.extraPaths": [
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/tachimawari_interfaces/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/suiryoku_interfaces/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/ninshiki_py/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/ninshiki/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/shisen_interfaces/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/opencv_tests/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/ninshiki_interfaces/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/kansei_interfaces/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/image_geometry/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/cv_bridge/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/atama_interfaces/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/aruku_interfaces/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/akushon_interfaces/lib/python3.10/site-packages",
"/opt/ros/iron/lib/python3.10/site-packages"
],
"python.analysis.extraPaths": [
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/tachimawari_interfaces/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/suiryoku_interfaces/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/ninshiki_py/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/ninshiki/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/shisen_interfaces/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/opencv_tests/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/ninshiki_interfaces/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/kansei_interfaces/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/image_geometry/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/cv_bridge/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/atama_interfaces/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/aruku_interfaces/lib/python3.10/site-packages",
"/home/mbsaloka/Desktop/Ichiro/ros2-ws/install/akushon_interfaces/lib/python3.10/site-packages",
"/opt/ros/iron/lib/python3.10/site-packages"
]
}
21 changes: 19 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,31 @@ find_package(OpenCV REQUIRED)
find_package(rclcpp REQUIRED)
find_package(shisen_cpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(Protobuf CONFIG REQUIRED)
message(STATUS "Using protobuf ${Protobuf_VERSION}")

install(DIRECTORY "include" DESTINATION ".")
find_package(cv_bridge REQUIRED)

add_library(${PROJECT_NAME} SHARED
"src/${PROJECT_NAME}/config/utils/config.cpp"
"src/${PROJECT_NAME}/config/grpc/config.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_base.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_get_color_setting.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_set_color_setting.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_save_color_setting.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}/node/ninshiki_cpp_node.cpp"
"src/${PROJECT_NAME}/utils/utils.cpp")
"src/${PROJECT_NAME}/utils/utils.cpp"
)

target_include_directories(${PROJECT_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

Expand All @@ -45,14 +57,19 @@ ament_target_dependencies(${PROJECT_NAME}
sensor_msgs
cv_bridge)

install(DIRECTORY "include" DESTINATION ".")
# target_link_libraries(${PROJECT_NAME}
# gRPC::grpc++_reflection
# gRPC::grpc++
# )

install(TARGETS ${PROJECT_NAME}
EXPORT export_${PROJECT_NAME}
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "lib"
RUNTIME DESTINATION "bin")

target_compile_options(${PROJECT_NAME} PRIVATE -fPIC)

add_executable(detector "src/ninshiki_cpp_detector.cpp")
target_include_directories(detector PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
Expand Down
38 changes: 38 additions & 0 deletions data/color_classifier.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this as we have moved the configurations to config repo

"ball": {
"max_hsv": [
179,
100,
100
],
"min_hsv": [
151,
40,
10
]
},
"field": {
"max_hsv": [
116,
100,
100
],
"min_hsv": [
84,
10,
0
]
},
"line": {
"max_hsv": [
260,
60,
100
],
"min_hsv": [
180,
0,
55
]
}
}
3 changes: 3 additions & 0 deletions data/grpc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"port": 5858
}
87 changes: 87 additions & 0 deletions include/ninshiki_cpp/config/grpc/call_data.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (c) 2024 Ichiro ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#ifndef __NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_HPP__
#define __NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_HPP__

#include "ninshiki_cpp/config/grpc/call_data_base.hpp"
#include "ninshiki_interfaces/ninshiki.grpc.pb.h"
#include "ninshiki_interfaces/ninshiki.pb.h"
#include "grpc/support/log.h"
#include "grpcpp/grpcpp.h"

namespace ninshiki_cpp
{
template <class ConfigRequest, class ConfigReply>
class CallData : public CallDataBase
{
public:
CallData(
ninshiki_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq,
const std::string & path);

void Proceed();

protected:
virtual void AddNextToCompletionQueue() = 0;

enum CallStatus { CREATE, PROCESS, FINISH };

CallStatus status_; // The current serving state.

ninshiki_interfaces::proto::Config::AsyncService * service_;

const std::string path_;

grpc::ServerCompletionQueue * cq_;
grpc::ServerContext ctx_;
ConfigRequest request_;
ConfigReply reply_;
grpc::ServerAsyncResponseWriter<ConfigReply> responder_;
};

template <class ConfigRequest, class ConfigReply>
CallData<ConfigRequest, ConfigReply>::CallData(
ninshiki_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq,
const std::string & path)
: status_(CREATE), service_(service), cq_(cq), responder_(&ctx_), path_(path)
{
}

template <class ConfigRequest, class ConfigReply>
void CallData<ConfigRequest, ConfigReply>::Proceed()
{
if (status_ == CREATE) {
status_ = PROCESS;
WaitForRequest();
} else if (status_ == PROCESS) {
AddNextToCompletionQueue();
HandleRequest();
status_ = FINISH;
responder_.Finish(reply_, grpc::Status::OK, this);
} else {
GPR_ASSERT(status_ == FINISH);
delete this;
}
}

} // namespace ninshiki_cpp

#endif // __NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_HPP__
39 changes: 39 additions & 0 deletions include/ninshiki_cpp/config/grpc/call_data_base.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2024 Ichiro ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#ifndef NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_
#define NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_

namespace ninshiki_cpp
{
class CallDataBase
{
public:
CallDataBase();

virtual void Proceed() = 0;

protected:
virtual void WaitForRequest() = 0;
virtual void HandleRequest() = 0;
};
} // namespace ninshiki_cpp

#endif // NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_BASE_HPP_
43 changes: 43 additions & 0 deletions include/ninshiki_cpp/config/grpc/call_data_get_color_setting.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) 2024 Ichiro ITS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#ifndef NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_GET_COLOR_SETTING_HPP__
#define NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_GET_COLOR_SETTING_HPP__

#include <ninshiki_cpp/config/grpc/call_data.hpp>

namespace ninshiki_cpp
{
class CallDataGetColorSetting
: CallData<ninshiki_interfaces::proto::Empty, ninshiki_interfaces::proto::ConfigColor>
{
public:
CallDataGetColorSetting(
ninshiki_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq,
const std::string & path);

protected:
void AddNextToCompletionQueue() override;
void WaitForRequest();
void HandleRequest();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines should be marked as override.

Suggested change
void WaitForRequest();
void HandleRequest();
void WaitForRequest() override;
void HandleRequest() override;

};
} // namespace ninshiki_cpp

#endif // NINSHIKI_CPP__CONFIG__GRPC__CALL_DATA_GET_COLOR_SETTING_HPP__
Loading
Loading