SMACC2
Loading...
Searching...
No Matches
cp_waypoints_navigator_base.hpp
Go to the documentation of this file.
1// Copyright 2025 Robosoft Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20#pragma once
21
22#include <cl_nav2z/cl_nav2z.hpp>
24#include <smacc2/smacc.hpp>
25
26#include <geometry_msgs/msg/pose.hpp>
27
28namespace cl_nav2z
29{
30struct Pose2D
31{
32 Pose2D(double x, double y, double yaw)
33 {
34 this->x_ = x;
35 this->y_ = y;
36 this->yaw_ = yaw;
37 }
38
39 double x_;
40 double y_;
41 double yaw_;
42};
43
44// This component contains a list of waypoints. These waypoints can
45// be iterated in the different states using CbNextWaiPoint
46// waypoint index is only incremented if the current waypoint is successfully reached
48{
49public:
51
53
54 ~CpWaypointNavigatorBase() override;
55
56 void onInitialize() override;
57
58 template <typename TOrthogonal, typename TSourceObject>
60 {
61 ClNav2Z * client = dynamic_cast<ClNav2Z *>(owner_);
62 waypointsEventDispatcher.initialize<TSourceObject, TOrthogonal>(client);
63 }
64
65 // Both return false, with the list empty, when the file cannot be opened or is not valid YAML.
66 bool loadWayPointsFromFile(std::string filepath);
67
68 bool loadWayPointsFromFile2(std::string filepath);
69
70 void setWaypoints(const std::vector<geometry_msgs::msg::Pose> & waypoints);
71
72 void setWaypoints(const std::vector<Pose2D> & waypoints);
73
74 const std::vector<geometry_msgs::msg::Pose> & getWaypoints() const;
75 const std::vector<std::string> & getWaypointNames() const;
76 std::optional<geometry_msgs::msg::Pose> getNamedPose(std::string name) const;
77 geometry_msgs::msg::Pose getPose(int index) const;
78 geometry_msgs::msg::Pose getCurrentPose() const;
79
80 long getCurrentWaypointIndex() const;
81 std::optional<std::string> getCurrentWaypointName() const;
82
84
85 // Move the index `count` waypoints back or forward, stopping at the first and the last.
86 void rewind(int count);
87
88 void forward(int count);
89 // Moves the index to the waypoint of that name; false, with the index unchanged, if there is none.
90 bool seekName(std::string name);
91
93 std::string parameter_name, std::string yaml_file_package_name);
94
95 void notifyGoalReached();
96
97protected:
98 void insertWaypoint(int index, geometry_msgs::msg::Pose & newpose);
99
100 void removeWaypoint(int index);
101
102 // The two lists always have the same length; a waypoint with no name has an empty one.
103 std::vector<geometry_msgs::msg::Pose> waypoints_;
104
105 std::vector<std::string> waypointsNames_;
106
107private:
108 void addWaypoint(const geometry_msgs::msg::Pose & pose, const std::string & name);
109
110 void clearWaypoints();
111};
112} // namespace cl_nav2z
void setWaypoints(const std::vector< geometry_msgs::msg::Pose > &waypoints)
const std::vector< geometry_msgs::msg::Pose > & getWaypoints() const
bool loadWayPointsFromFile2(std::string filepath)
std::vector< geometry_msgs::msg::Pose > waypoints_
geometry_msgs::msg::Pose getCurrentPose() const
std::optional< std::string > getCurrentWaypointName() const
std::optional< geometry_msgs::msg::Pose > getNamedPose(std::string name) const
geometry_msgs::msg::Pose getPose(int index) const
bool loadWayPointsFromFile(std::string filepath)
void addWaypoint(const geometry_msgs::msg::Pose &pose, const std::string &name)
bool loadWaypointsFromYamlParameter(std::string parameter_name, std::string yaml_file_package_name)
const std::vector< std::string > & getWaypointNames() const
void insertWaypoint(int index, geometry_msgs::msg::Pose &newpose)
ISmaccClient * owner_
Definition component.hpp:96
Pose2D(double x, double y, double yaw)