SMACC2
Loading...
Searching...
No Matches
cb_spiral_motion.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
21#pragma once
22
25
26namespace cl_nav2z
27{
28
29// client behaviors typically accept parameters to be customized in the state it is being used
30// we follow this pattern, with a basic structure with optional fields, that make thee initialization of the behavior more readable in the
31// state initialization. It also avoid an explosion of constructors for each variation of the parameters.
33{
34 // A field left empty means "use the default"; onEntry falls back to these constants.
35 static constexpr float kDefaultLinearVelocity = 0.0f;
36 static constexpr float kDefaultMaxLinearVelocity = 0.5f;
37 static constexpr float kDefaultInitialAngularVelocity = 1.5f;
38 static constexpr double kDefaultSpiralMotionSeconds = 40.0;
39 static constexpr float kDefaultFinalRadius = 20.0f; // meters
40
41 std::optional<float> linearVelocity = kDefaultLinearVelocity;
44 std::optional<rclcpp::Duration> spiralMotionDuration =
45 rclcpp::Duration::from_seconds(kDefaultSpiralMotionSeconds);
46 std::optional<float> finalRadius = kDefaultFinalRadius;
47};
48
49/* a basic client behavior has a simple onEntry and onExit functions. When we enter into a state we call onEntry.
50This client behavior is asynchronous so that onEntry returns immediately, it opens a thread to run the behavior*/
52{
53public:
54 //
55 // constructor, we accept an empty usage of the behavior, but also any other combination of parameters
56 CbSpiralMotion(std::optional<CbSpiralMotionOptions> options = std::nullopt);
57
58 void onEntry() override;
59
60 void onExit() override;
61
62private:
63 // this client behavior has its own temporal publisher to control the robot
64 rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr cmdVelPub_;
65
66 // we store the options that customize the behavior
68};
69} // namespace cl_nav2z
static constexpr float kDefaultInitialAngularVelocity
std::optional< float > initialAngularVelocity
std::optional< float > linearVelocity
static constexpr float kDefaultMaxLinearVelocity
std::optional< rclcpp::Duration > spiralMotionDuration
std::optional< float > maxLinearVelocity
std::optional< float > finalRadius
static constexpr double kDefaultSpiralMotionSeconds
static constexpr float kDefaultFinalRadius
static constexpr float kDefaultLinearVelocity
CbSpiralMotionOptions options_
rclcpp::Publisher< geometry_msgs::msg::Twist >::SharedPtr cmdVelPub_
CbSpiralMotion(std::optional< CbSpiralMotionOptions > options=std::nullopt)