SMACC2
smacc_state.cpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI 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
23
24namespace smacc2
25{
26std::string ISmaccState::getClassName() { return demangleSymbol(typeid(*this).name()); }
27
29{
30 RCLCPP_INFO_STREAM(getLogger(), "TRANSITION RULE TRIGGERED: " << transitionType->getFullName());
31
32 //auto currstateinfo = this->getStateMachine().getCurrentStateInfo();
33 auto currstateinfo = this->stateInfo_;
34
35 if (currstateinfo != nullptr)
36 {
37 //RCLCPP_ERROR_STREAM(getLogger(),"CURRENT STATE INFO: " << currstateinfo->fullStateName);
38 for (auto & transition : currstateinfo->transitions_)
39 {
40 std::string transitionCandidateName = transition.transitionTypeInfo->getFullName();
41 //RCLCPP_ERROR_STREAM(getLogger(),"candidate transition: " << transitionCandidateName);
42
43 if (transitionType->getFullName() == transitionCandidateName)
44 {
45 this->getStateMachine().publishTransition(transition);
46 return;
47 }
48 }
49
50 // debug information if not found
51 RCLCPP_ERROR_STREAM(
52 getLogger(),
53 "Transition happened, from current state "
54 << currstateinfo->getDemangledFullName()
55 << " but there is not any transitioninfo match available to publish transition: "
56 << transitionType->getFullName());
57 std::stringstream ss;
58
59 auto stateinfo = currstateinfo;
60
61 for (auto & transition : currstateinfo->transitions_)
62 {
63 std::string transitionCandidateName = transition.transitionTypeInfo->getFullName();
64 RCLCPP_ERROR_STREAM(getLogger(), "- candidate transition: " << transitionCandidateName);
65 }
66
67 RCLCPP_ERROR(getLogger(), "Ancestors candidates: ");
68
69 std::list<const SmaccStateInfo *> ancestors;
70 stateinfo->getAncestors(ancestors);
71
72 for (auto & ancestor : ancestors)
73 {
74 RCLCPP_ERROR_STREAM(getLogger(), " * Ancestor " << ancestor->getDemangledFullName() << ":");
75 for (auto & transition : ancestor->transitions_)
76 {
77 std::string transitionCandidateName = transition.transitionTypeInfo->getFullName();
78 RCLCPP_ERROR_STREAM(getLogger(), "- candidate transition: " << transitionCandidateName);
79 if (transitionType->getFullName() == transitionCandidateName)
80 {
81 RCLCPP_ERROR(getLogger(), "GOTCHA");
82 }
83 }
84 }
85 }
86 else
87 {
88 RCLCPP_ERROR_STREAM(
89 getLogger(), "Transition happened, but current state was not set. Transition candidates:");
90 }
91}
92
93} // namespace smacc2
void publishTransition(const SmaccTransitionInfo &transitionInfo)
rclcpp::Logger getLogger()
Definition: smacc_state.hpp:36
virtual std::string getClassName()
Definition: smacc_state.cpp:26
virtual ISmaccStateMachine & getStateMachine()=0
const smacc2::introspection::SmaccStateInfo * stateInfo_
void notifyTransitionFromTransitionTypeInfo(std::shared_ptr< smacc2::introspection::TypeInfo > &transitionTypeInfo)
Definition: smacc_state.cpp:28
std::shared_ptr< TypeInfo > Ptr
std::string demangleSymbol(const std::string &name)