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

Conversation

mbsaloka
Copy link
Contributor

Jira Link:

https://ichiro-its.atlassian.net/browse/PD-405?atlOrigin=eyJpIjoiZjcyMmNiZGY0YjQ5NDliYzkxYjhkZjBiODFmODk2OWUiLCJwIjoiaiJ9

Description

Added grpc to implement get, set and save functions. The gRPC server runs on port :5858 and consists of 3 RPCs, GetColorSetting, SetColorSetting, and SaveColorSetting. It has been tested using Postman and it works.

Example Message:

GetColorSetting

{}

SetColorSetting

{
    "max_hue": 123,
    "max_saturation": 123,
    "max_value": 123,
    "min_hue": 123,
    "min_saturation": 123,
    "min_value": 123,
    "name": "line"
}

SaveColorSetting

{
    "json_color": "{\"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]}}"
}

Type of Change

  • Bugfix
  • Enhancement
  • New feature
  • Breaking change (fix or feature that would cause the existing functionality to not work as expected)

How Has This Been Tested?

  • New unit tests added.
  • Manual tested.

Checklist:

  • Using Branch Name Convention
    • feature/JIRA-ID-SHORT-DESCRIPTION if has a JIRA ticket
    • enhancement/SHORT-DESCRIPTION if has/has no JIRA ticket and contain enhancement
    • hotfix/SHORT-DESCRIPTION if the change doesn't need to be tested (urgent)
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have made the documentation for the corresponding changes.

Copy link
Contributor

@FaaizHaikal FaaizHaikal left a comment

Choose a reason for hiding this comment

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

remove .vscode dir

include/ninshiki_cpp/config/grpc/config.hpp Show resolved Hide resolved
item.max_value = color.max_value;

std::cout << "[DEBUG] Color setting has been applied!" << std::endl;
std::cout << "name: " << item.name << std::endl;
Copy link
Contributor

Choose a reason for hiding this comment

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

remove these debugging lines

Copy link
Member

@threeal threeal left a comment

Choose a reason for hiding this comment

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

I suggest creating a dedicated gRPC utility package first before merging this change, as I see there are many duplications of CallData, CallDataBase, etc., across different projects that are going to implement gRPC (see ichiro-its/shisen_cpp#25 and ichiro-its/aruku#20).

@@ -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

@@ -0,0 +1,56 @@
// Copyright (c) 2021 ICHIRO ITS
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't this done in branch refactor ninshiki ? Maybe remove all changes that are done in refactor ninshiki branch before merging this branch later

Comment on lines 38 to 39
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;

Comment on lines 39 to 40
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.

Ditto.

Comment on lines 42 to 43
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.

Ditto.

Comment on lines 24 to 45
#include <absl/flags/flag.h>
#include <absl/flags/parse.h>
#include <absl/strings/str_format.h>
#include <grpc/support/log.h>
#include <grpcpp/grpcpp.h>
#include <ninshiki_cpp/config/grpc/call_data.hpp>
#include <ninshiki_cpp/config/grpc/call_data_base.hpp>
#include <ninshiki_cpp/detector/color_detector.hpp>
#include <ninshiki_interfaces/msg/color_setting.hpp>
#include <ninshiki_interfaces/ninshiki.grpc.pb.h>
#include <ninshiki_interfaces/ninshiki.pb.h>
#include <nlohmann/json.hpp>
#include <rclcpp/rclcpp.hpp>

#include <chrono>
#include <fstream>
#include <future>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <thread>
Copy link
Member

Choose a reason for hiding this comment

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

Some of these headers may be unnecessary, don't put all of them in the header file.


namespace ninshiki_cpp
{
CallDataBase::CallDataBase() {}
Copy link
Member

Choose a reason for hiding this comment

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

Just remove the constructor if it does not do anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

after I deleted the constructor or deleted the call_data_base.cpp file, when building the package it produced an error

/usr/bin/ld: libninshiki_cpp.so: undefined reference to `ninshiki_cpp::CallDataBase::CallDataBase()'

Copy link
Member

Choose a reason for hiding this comment

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

You also need to remove the constructor from the class declaration in the .hpp file.

Comment on lines 51 to 67
std::string name = request_.name();
int min_hue = request_.min_hue();
int max_hue = request_.max_hue();
int min_saturation = request_.min_saturation();
int max_saturation = request_.max_saturation();
int min_value = request_.min_value();
int max_value = request_.max_value();

utils::Color color(
name,
min_hue,
max_hue,
min_saturation,
max_saturation,
min_value,
max_value
);
Copy link
Member

Choose a reason for hiding this comment

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

Simpler

Suggested change
std::string name = request_.name();
int min_hue = request_.min_hue();
int max_hue = request_.max_hue();
int min_saturation = request_.min_saturation();
int max_saturation = request_.max_saturation();
int min_value = request_.min_value();
int max_value = request_.max_value();
utils::Color color(
name,
min_hue,
max_hue,
min_saturation,
max_saturation,
min_value,
max_value
);
utils::Color color(
request_.name(),
request_.min_hue(),
request_.max_hue(),
request_.min_saturation(),
request_.max_saturation(),
request_.min_value(),
request_.max_value()
);

FaaizHaikal
FaaizHaikal previously approved these changes Jun 4, 2024
@FaaizHaikal
Copy link
Contributor

I suggest creating a dedicated gRPC utility package first before merging this change, as I see there are many duplications of CallData, CallDataBase, etc., across different projects that are going to implement gRPC (see ichiro-its/shisen_cpp#25 and ichiro-its/aruku#20).

I think there are going to be a lot of changes while working on this. It might be worked on after this year's competition mas, which is around next month.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants