68 lines
No EOL
1.7 KiB
C++
68 lines
No EOL
1.7 KiB
C++
// Copyright 2019 Intelligent Robotics Lab
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include <memory>
|
|
#include <algorithm>
|
|
|
|
#include "plansys2_executor/ActionExecutorClient.hpp"
|
|
|
|
#include "rclcpp/rclcpp.hpp"
|
|
#include "rclcpp_action/rclcpp_action.hpp"
|
|
|
|
using namespace std::chrono_literals;
|
|
|
|
class AssembleAction : public plansys2::ActionExecutorClient
|
|
{
|
|
public:
|
|
AssembleAction()
|
|
: plansys2::ActionExecutorClient("assemble", 500ms)
|
|
{
|
|
progress_ = 0.0;
|
|
}
|
|
|
|
private:
|
|
void do_work()
|
|
{
|
|
if (progress_ < 1.0) {
|
|
progress_ += 0.05;
|
|
send_feedback(progress_, "Assemble running");
|
|
} else {
|
|
finish(true, 1.0, "Assemble completed");
|
|
|
|
progress_ = 0.0;
|
|
std::cout << std::endl;
|
|
}
|
|
|
|
std::cout << "\r\e[K" << std::flush;
|
|
std::cout << "Assemble ... [" << std::min(100.0, progress_ * 100.0) << "%] " <<
|
|
std::flush;
|
|
}
|
|
|
|
float progress_;
|
|
};
|
|
|
|
int main(int argc, char ** argv)
|
|
{
|
|
rclcpp::init(argc, argv);
|
|
auto node = std::make_shared<AssembleAction>();
|
|
|
|
node->set_parameter(rclcpp::Parameter("action_name", "assemble"));
|
|
node->trigger_transition(lifecycle_msgs::msg::Transition::TRANSITION_CONFIGURE);
|
|
|
|
rclcpp::spin(node->get_node_base_interface());
|
|
|
|
rclcpp::shutdown();
|
|
|
|
return 0;
|
|
} |