SMACC2
Loading...
Searching...
No Matches
cp_decision_manager.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 <smacc2/component.hpp>
23
24#include <mutex>
25
26namespace cl_mission_tracker
27{
28
37{
38public:
39 CpDecisionManager() = default;
40
41 virtual ~CpDecisionManager() = default;
42
43 void onInitialize() override { RCLCPP_INFO(getLogger(), "[CpDecisionManager] Initialized"); }
44
50 {
51 std::lock_guard<std::mutex> lock(mutex_);
52 return decisionCounter_;
53 }
54
60 {
61 std::lock_guard<std::mutex> lock(mutex_);
62 int current = decisionCounter_;
64 RCLCPP_INFO_STREAM(
65 getLogger(), "[CpDecisionManager] Decision " << current << " -> " << decisionCounter_);
66 return current;
67 }
68
73 {
74 std::lock_guard<std::mutex> lock(mutex_);
76 RCLCPP_INFO(getLogger(), "[CpDecisionManager] Decision counter reset");
77 }
78
83 void setDecisionCounter(int value)
84 {
85 std::lock_guard<std::mutex> lock(mutex_);
86 decisionCounter_ = value;
87 RCLCPP_INFO_STREAM(getLogger(), "[CpDecisionManager] Decision counter set to " << value);
88 }
89
90private:
91 mutable std::mutex mutex_;
93};
94
95} // namespace cl_mission_tracker
Component that manages mission decision state.
void setDecisionCounter(int value)
Set the decision counter to a specific value.
int getDecisionCounter() const
Get the current decision counter value.
void resetDecisionCounter()
Reset the decision counter to zero.
int nextDecision()
Increment the decision counter and return the previous value.
rclcpp::Logger getLogger() const