Skip to content

Commit

Permalink
Merge pull request #48 from ichiro-its/feature/brake-action-service
Browse files Browse the repository at this point in the history
[Feature] Add Brake Action Service
  • Loading branch information
mbsaloka authored Jul 13, 2024
2 parents 1c1ff40 + fe25f96 commit 7901cbb
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ 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_brake_action.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_get_config.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_load_config.cpp"
"src/${PROJECT_NAME}/config/grpc/call_data_save_config.cpp"
Expand Down
45 changes: 45 additions & 0 deletions include/akushon/config/grpc/call_data_brake_action.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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 AKUSHON__CONFIG__GRPC__BRAKE_ACTION_HPP_
#define AKUSHON__CONFIG__GRPC__BRAKE_ACTION_HPP_

#include "akushon/action/node/action_manager.hpp"
#include "akushon/config/grpc/call_data.hpp"

namespace akushon
{
class CallDataBrakeAction
: CallData<akushon_interfaces::proto::Empty, akushon_interfaces::proto::Empty>
{
public:
CallDataBrakeAction(
akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq,
const std::string& path, const std::shared_ptr<ActionManager>& action_manager);

protected:
void AddNextToCompletionQueue() override;
void WaitForRequest() override;
void HandleRequest() override;
std::shared_ptr<ActionManager> action_manager_;
};
} // namespace akushon

#endif // AKUSHON__CONFIG__GRPC__BRAKE_ACTION_HPP_
58 changes: 58 additions & 0 deletions src/akushon/config/grpc/call_data_brake_action.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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.

#include "akushon/config/grpc/call_data_brake_action.hpp"
#include "akushon/config/utils/config.hpp"

#include <nlohmann/json.hpp>
#include <rclcpp/rclcpp.hpp>

namespace akushon
{

CallDataBrakeAction::CallDataBrakeAction(
akushon_interfaces::proto::Config::AsyncService * service, grpc::ServerCompletionQueue * cq,
const std::string& path, const std::shared_ptr<ActionManager>& action_manager)
: CallData(service, cq, path), action_manager_(action_manager)
{
Proceed();
}

void CallDataBrakeAction::AddNextToCompletionQueue()
{
new CallDataBrakeAction(service_, cq_, path_, action_manager_);
}

void CallDataBrakeAction::WaitForRequest()
{
service_->RequestBrakeAction(&ctx_, &request_, &responder_, cq_, cq_, this);
}

void CallDataBrakeAction::HandleRequest()
{
try {
action_manager_->brake();
RCLCPP_INFO(rclcpp::get_logger("BrakeAction"), "Action has been braked!");
} catch (nlohmann::json::exception e) {
RCLCPP_ERROR(rclcpp::get_logger("BrakeAction"), e.what());
}
}

} // namespace akushon
2 changes: 2 additions & 0 deletions src/akushon/config/grpc/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

#include "akushon/config/utils/config.hpp"
#include "rclcpp/rclcpp.hpp"
#include "akushon/config/grpc/call_data_brake_action.hpp"
#include "akushon/config/grpc/call_data_get_config.hpp"
#include "akushon/config/grpc/call_data_load_config.hpp"
#include "akushon/config/grpc/call_data_save_config.hpp"
Expand Down Expand Up @@ -68,6 +69,7 @@ void ConfigGrpc::Run(uint16_t port, const std::string& path, rclcpp::Node::Share
exit(signum);
});
async_server = std::thread([path, this, &node, &action_manager]() {
new CallDataBrakeAction(&service_, cq_.get(), path, action_manager);
new CallDataGetConfig(&service_, cq_.get(), path);
new CallDataSaveConfig(&service_, cq_.get(), path, action_manager);
new CallDataPublishSetJoints(&service_, cq_.get(), path, node);
Expand Down

0 comments on commit 7901cbb

Please sign in to comment.