Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 081c554

Browse files
committed
tests passed
1 parent 0ab3895 commit 081c554

File tree

5 files changed

+37
-137
lines changed

5 files changed

+37
-137
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ list(APPEND BT_SOURCE
152152
src/controls/reactive_fallback.cpp
153153
src/controls/sequence_node.cpp
154154
src/controls/sequence_star_node.cpp
155+
src/controls/latched_sequence.cpp
156+
src/controls/latched_fallback.cpp
155157

156158
src/loggers/bt_cout_logger.cpp
157159
src/loggers/bt_file_logger.cpp

include/behaviortree_cpp_v3/controls/fallback_node.h

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2015-2018 Michele Colledanchise - All Rights Reserved
1+
/* Copyright (C) 2015-2020 Michele Colledanchise - All Rights Reserved
22
* Copyright (C) 2018-2019 Davide Faconti, Eurecat - All Rights Reserved
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
@@ -14,7 +14,17 @@
1414
#ifndef FALLBACKNODE_H
1515
#define FALLBACKNODE_H
1616

17-
#include "behaviortree_cpp_v3/control_node.h"
17+
#if __cplusplus >= 201402L
18+
#define DEPRECATED(msg) [[ deprecated(msg) ]]
19+
#elif defined(__GNUC__)
20+
#define DEPRECATED(msg) __attribute__ ((deprecated(msg)))
21+
#elif defined(_MSC_VER)
22+
#define DEPRECATED(msg) __declspec(deprecated(msg))
23+
#else
24+
#define DEPRECATED(msg)
25+
#endif
26+
27+
#include "behaviortree_cpp_v3/controls/latched_fallback.h"
1828

1929
namespace BT
2030
{
@@ -30,21 +40,14 @@ namespace BT
3040
* - If a child returns SUCCESS, stop the loop and return SUCCESS.
3141
*
3242
*/
33-
class FallbackNode : public ControlNode
43+
class FallbackNode : public LatchedFallback
3444
{
3545
public:
46+
DEPRECATED("Please use ReactiveFallback or LatchedFallback to make clear"
47+
" which kind of Fallback Node you mean to use")
3648
FallbackNode(const std::string& name);
37-
38-
virtual ~FallbackNode() override = default;
39-
40-
virtual void halt() override;
41-
42-
private:
43-
size_t current_child_idx_;
44-
45-
virtual BT::NodeStatus tick() override;
4649
};
4750

4851
}
4952

50-
#endif
53+
#endif //FALLBACKNODE_H

include/behaviortree_cpp_v3/controls/sequence_node.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2015-2018 Michele Colledanchise - All Rights Reserved
1+
/* Copyright (C) 2015-2020 Michele Colledanchise - All Rights Reserved
22
* Copyright (C) 2018-2019 Davide Faconti, Eurecat - All Rights Reserved
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
@@ -14,7 +14,17 @@
1414
#ifndef SEQUENCENODE_H
1515
#define SEQUENCENODE_H
1616

17-
#include "behaviortree_cpp_v3/control_node.h"
17+
#if __cplusplus >= 201402L
18+
#define DEPRECATED(msg) [[ deprecated(msg) ]]
19+
#elif defined(__GNUC__)
20+
#define DEPRECATED(msg) __attribute__ ((deprecated(msg)))
21+
#elif defined(_MSC_VER)
22+
#define DEPRECATED(msg) __declspec(deprecated(msg))
23+
#else
24+
#define DEPRECATED(msg)
25+
#endif
26+
27+
#include "behaviortree_cpp_v3/controls/latched_sequence.h"
1828

1929
namespace BT
2030
{
@@ -31,19 +41,12 @@ namespace BT
3141
* Restart the loop only if (reset_on_failure == true)
3242
*
3343
*/
34-
class SequenceNode : public ControlNode
44+
class SequenceNode : public LatechedSequence
3545
{
3646
public:
47+
DEPRECATED("Please use ReactiveSequence or LatchedSequence to make clear"
48+
" which kind of Sequence Node you mean to use")
3749
SequenceNode(const std::string& name);
38-
39-
virtual ~SequenceNode() override = default;
40-
41-
virtual void halt() override;
42-
43-
private:
44-
size_t current_child_idx_;
45-
46-
virtual BT::NodeStatus tick() override;
4750
};
4851

4952
}

src/controls/fallback_node.cpp

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2015-2018 Michele Colledanchise - All Rights Reserved
1+
/* Copyright (C) 2015-2020 Michele Colledanchise - All Rights Reserved
22
* Copyright (C) 2018-2019 Davide Faconti, Eurecat - All Rights Reserved
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
@@ -17,62 +17,9 @@ namespace BT
1717
{
1818

1919
FallbackNode::FallbackNode(const std::string& name)
20-
: ControlNode::ControlNode(name, {} )
21-
,current_child_idx_(0)
20+
: LatchedFallback::LatchedFallback(name)
2221
{
2322
setRegistrationID("Fallback");
2423
}
2524

26-
NodeStatus FallbackNode::tick()
27-
{
28-
const size_t children_count = children_nodes_.size();
29-
30-
setStatus(NodeStatus::RUNNING);
31-
32-
while (current_child_idx_ < children_count)
33-
{
34-
TreeNode* current_child_node = children_nodes_[current_child_idx_];
35-
const NodeStatus child_status = current_child_node->executeTick();
36-
37-
switch (child_status)
38-
{
39-
case NodeStatus::RUNNING:
40-
{
41-
return child_status;
42-
}
43-
case NodeStatus::SUCCESS:
44-
{
45-
haltChildren(0);
46-
current_child_idx_ = 0;
47-
return child_status;
48-
}
49-
case NodeStatus::FAILURE:
50-
{
51-
current_child_idx_++;
52-
}
53-
break;
54-
55-
case NodeStatus::IDLE:
56-
{
57-
throw LogicError("A child node must never return IDLE");
58-
}
59-
} // end switch
60-
} // end while loop
61-
62-
// The entire while loop completed. This means that all the children returned FAILURE.
63-
if (current_child_idx_ == children_count)
64-
{
65-
haltChildren(0);
66-
current_child_idx_ = 0;
67-
}
68-
69-
return NodeStatus::FAILURE;
70-
}
71-
72-
void FallbackNode::halt()
73-
{
74-
current_child_idx_ = 0;
75-
ControlNode::halt();
76-
}
77-
7825
}

src/controls/sequence_node.cpp

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (C) 2015-2018 Michele Colledanchise - All Rights Reserved
1+
/* Copyright (C) 2015-2020 Michele Colledanchise - All Rights Reserved
22
* Copyright (C) 2018-2019 Davide Faconti, Eurecat - All Rights Reserved
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
@@ -17,64 +17,9 @@
1717
namespace BT
1818
{
1919

20-
2120
SequenceNode::SequenceNode(const std::string& name)
22-
: ControlNode::ControlNode(name, {} )
23-
, current_child_idx_(0)
21+
: LatechedSequence::LatechedSequence(name)
2422
{
2523
setRegistrationID("Sequence");
2624
}
27-
28-
void SequenceNode::halt()
29-
{
30-
current_child_idx_ = 0;
31-
ControlNode::halt();
32-
}
33-
34-
NodeStatus SequenceNode::tick()
35-
{
36-
const size_t children_count = children_nodes_.size();
37-
38-
setStatus(NodeStatus::RUNNING);
39-
40-
while (current_child_idx_ < children_count)
41-
{
42-
TreeNode* current_child_node = children_nodes_[current_child_idx_];
43-
const NodeStatus child_status = current_child_node->executeTick();
44-
45-
switch (child_status)
46-
{
47-
case NodeStatus::RUNNING:
48-
{
49-
return child_status;
50-
}
51-
case NodeStatus::FAILURE:
52-
{
53-
// Reset on failure
54-
haltChildren(0);
55-
current_child_idx_ = 0;
56-
return child_status;
57-
}
58-
case NodeStatus::SUCCESS:
59-
{
60-
current_child_idx_++;
61-
}
62-
break;
63-
64-
case NodeStatus::IDLE:
65-
{
66-
throw LogicError("A child node must never return IDLE");
67-
}
68-
} // end switch
69-
} // end while loop
70-
71-
// The entire while loop completed. This means that all the children returned SUCCESS.
72-
if (current_child_idx_ == children_count)
73-
{
74-
haltChildren(0);
75-
current_child_idx_ = 0;
76-
}
77-
return NodeStatus::SUCCESS;
78-
}
79-
8025
}

0 commit comments

Comments
 (0)