16#ifndef EASYFLEET_MISSION_MANAGER__MISSION_HELPERS_HPP_
17#define EASYFLEET_MISSION_MANAGER__MISSION_HELPERS_HPP_
28#include "easyfleet_interfaces/action/manipulation.hpp"
29#include "easyfleet_interfaces/action/navigation.hpp"
30#include "easyfleet_interfaces/action/perception.hpp"
31#include "geometry_msgs/msg/pose_stamped.hpp"
32#include "rclcpp/rclcpp.hpp"
34#include "easyfleet_mission_manager/ansi.hpp"
35#include "easyfleet_mission_manager/capability_info.hpp"
36#include "easyfleet_mission_manager/output.hpp"
37#include "easyfleet_mission_manager/throttle.hpp"
44namespace easyfleet_mission_manager
47using Navigation = easyfleet_interfaces::action::Navigation;
48using Manipulation = easyfleet_interfaces::action::Manipulation;
49using Perception = easyfleet_interfaces::action::Perception;
53constexpr std::chrono::seconds kRunTimeout(10);
58inline std::thread spin_in_background(rclcpp::Executor & executor)
60 std::thread thread([&executor] {executor.spin();});
61 while (!executor.is_spinning()) {
62 std::this_thread::yield();
68inline void print_section(
const std::string & title)
70 std::ostringstream out;
71 out <<
"\n" << ansi::bold << ansi::blue <<
"== " << title <<
" ==" << ansi::reset;
72 safe_print(out.str());
77inline void print_step(
const std::string & text)
79 safe_print(std::string(
" ") + ansi::dim + text + ansi::reset);
87inline std::optional<std::reference_wrapper<const CapabilityInfo>> find_robot_capability(
88 const std::vector<CapabilityInfo> & capabilities,
89 const std::string & robot,
const std::string & capability)
91 auto it = std::find_if(
92 capabilities.begin(), capabilities.end(),
94 return info.robot == robot && info.capability == capability && info.active;
96 if (it == capabilities.end()) {
99 return std::cref(*it);
102inline Navigation::Goal make_navigation_goal()
104 Navigation::Goal goal;
105 goal.target_pose.header.frame_id =
"map";
106 goal.target_pose.pose.position.x = 2.0;
107 goal.target_pose.pose.position.y = 1.0;
108 goal.target_pose.pose.orientation.w = 1.0;
119inline Navigation::Goal make_navigation_goal(
const std::string & waypoint_id)
121 Navigation::Goal goal;
122 goal.parameters_json = R
"({"goal_id": ")" + waypoint_id + R"("})";
130inline std::function<void(
const Navigation::Feedback & )> make_navigation_feedback_printer(
131 const std::string & label)
133 Throttle throttle(std::chrono::milliseconds(500));
134 return [throttle, label](
const Navigation::Feedback & feedback) {
135 if (!throttle.ready()) {
138 std::ostringstream out;
139 out <<
" " << ansi::dim <<
"[" << label <<
"] " << ansi::reset
140 <<
"distance_remaining=" << feedback.distance_remaining <<
"m, "
141 <<
"elapsed=" << feedback.navigation_time.sec <<
"s, "
142 <<
"recoveries=" << feedback.number_of_recoveries;
143 safe_print(out.str());
147inline Manipulation::Goal make_manipulation_goal()
149 Manipulation::Goal goal;
150 goal.mode = Manipulation::Goal::MODE_JOINT_TARGET;
151 goal.joint_target.name = {
"joint1"};
152 goal.joint_target.position = {1.0};
159inline Manipulation::Goal make_manipulation_goal(
const geometry_msgs::msg::PoseStamped & pose)
161 Manipulation::Goal goal;
162 goal.mode = Manipulation::Goal::MODE_POSE_TARGET;
163 goal.pose_target = pose;
167inline std::function<void(
const Manipulation::Feedback & )> make_manipulation_feedback_printer(
168 const std::string & label)
170 Throttle throttle(std::chrono::milliseconds(500));
171 return [throttle, label](
const Manipulation::Feedback & feedback) {
172 if (!throttle.ready()) {
175 std::ostringstream out;
176 out <<
" " << ansi::dim <<
"[" << label <<
"] " << ansi::reset
177 <<
"state=" << feedback.state;
178 safe_print(out.str());
182inline Perception::Goal make_perception_goal()
184 Perception::Goal goal;
185 goal.object_classes.push_back(
"gato");
191inline Perception::Goal make_perception_goal(
const std::vector<std::string> & object_classes)
193 Perception::Goal goal;
194 goal.object_classes = object_classes;
198inline std::function<void(
const Perception::Feedback & )> make_perception_feedback_printer(
199 const std::string & label)
201 Throttle throttle(std::chrono::milliseconds(500));
202 return [throttle, label](
const Perception::Feedback & feedback) {
203 if (!throttle.ready()) {
206 std::ostringstream out;
207 out <<
" " << ansi::dim <<
"[" << label <<
"] " << ansi::reset
208 << feedback.detections_3d.detections.size() <<
" cat(s) detected (3D + 2D)";
209 safe_print(out.str());
Value-semantics rate limiter: copies (e.g.
Definition throttle.hpp:30
Everything known about one running capability instance, gathered from its /capabilities (easyfleet_in...
Definition capability_info.hpp:33