Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
multi_cell_builder
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Matteo Anedda
multi_cell_builder
Commits
ae0e0eb7
Commit
ae0e0eb7
authored
Apr 3, 2023
by
KingMaZito
Browse files
Options
Downloads
Patches
Plain Diff
evaluation
parent
e7fc1098
No related branches found
No related tags found
No related merge requests found
Changes
21
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/reader/test_bt.cpp
+159
-10
159 additions, 10 deletions
test/reader/test_bt.cpp
with
159 additions
and
10 deletions
test/reader/test_bt.cpp
+
159
−
10
View file @
ae0e0eb7
...
...
@@ -13,11 +13,6 @@
#include
<boost/circular_buffer.hpp>
TEST
(
BtTestSuit
,
basicParallelTest
){
BT
::
BehaviorTreeFactory
factory
;
factory
.
registerNodeType
<
Execution
>
(
"Execution"
);
factory
.
registerNodeType
<
PositionCondition
>
(
"PositionCondition"
);
factory
.
registerNodeType
<
Parallel_robot
>
(
"Parallel_robot"
);
std
::
map
<
const
std
::
string
,
std
::
vector
<
std
::
tuple
<
const
std
::
string
,
tf2
::
Vector3
,
std
::
vector
<
moveit_task_constructor_msgs
::
ExecuteTaskSolutionGoal
>>>>
task_but_different
;
boost
::
circular_buffer
<
std
::
pair
<
std
::
string
,
job_data
>>
cb_jd
;
...
...
@@ -26,17 +21,17 @@ TEST(BtTestSuit, basicParallelTest){
job1
.
jobs_
=
{
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
0
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
1
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
1
,
1
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
1
,
0
,
0
))};
job2
.
jobs_
=
{
tf2
::
Transform
(
tf2
::
Quaternion
(
2
,
2
,
0
,
1
),
tf2
::
Vector3
(
0
,
0
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
2
,
3
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
3
,
3
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
3
,
2
,
0
))};
std
::
vector
<
tf2
::
Vector3
>
boxes
=
{
tf2
::
Vector3
(
0
,
0
,
0
),
tf2
::
Vector3
(
2
,
2
,
0
)};
cb_jd
.
push_back
({
"
box
1"
,
job1
});
cb_jd
.
push_back
({
"
box
2"
,
job2
});
std
::
vector
<
std
::
pair
<
std
::
string
,
tf2
::
Vector3
>
>
boxes
=
{
{
"box1"
,
tf2
::
Vector3
(
0
,
0
,
0
)
},
{
"box2"
,
tf2
::
Vector3
(
2
,
2
,
0
)}
}
;
cb_jd
.
push_back
({
"
panda_arm
1"
,
job1
});
cb_jd
.
push_back
({
"
panda_arm
2"
,
job2
});
while
(
!
cb_jd
.
empty
()){
for
(
auto
&
box
:
boxes
){
std
::
pair
<
std
::
string
,
job_data
>
temp
=
cb_jd
.
front
();
if
(
tf2
::
tf2Distance2
(
temp
.
second
.
jobs_
.
front
().
getOrigin
(),
box
)
==
0
)
{
if
(
tf2
::
tf2Distance2
(
temp
.
second
.
jobs_
.
front
().
getOrigin
(),
box
.
second
)
==
0
)
{
for
(
int
k
=
1
;
k
<
temp
.
second
.
jobs_
.
size
();
k
++
){
box
=
temp
.
second
.
jobs_
[
k
].
getOrigin
();
box
.
second
=
temp
.
second
.
jobs_
[
k
].
getOrigin
();
}
cb_jd
.
pop_front
();
}
else
{
cb_jd
.
push_back
(
temp
);}
...
...
@@ -45,6 +40,160 @@ TEST(BtTestSuit, basicParallelTest){
ASSERT_EQ
(
cb_jd
.
size
(),
0
);
//All jobs
}
TEST
(
BtTestSuit
,
basicCooperativeTest
){
// BT::BehaviorTreeFactory factory;
// factory.registerNodeType<Execution>("Execution");
// factory.registerNodeType<PositionCondition>("PositionCondition");
// factory.registerNodeType<Parallel_robot>("Parallel_robot");
std
::
map
<
const
std
::
string
,
std
::
vector
<
std
::
tuple
<
const
std
::
string
,
tf2
::
Vector3
,
std
::
vector
<
moveit_task_constructor_msgs
::
ExecuteTaskSolutionGoal
>>>>
task_but_different
;
boost
::
circular_buffer
<
std
::
pair
<
std
::
string
,
job_data
>>
cb_jd
;
job_data
job1
,
job2
,
job3
;
job1
.
jobs_
=
{
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
0
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
1
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
1
,
1
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
1
,
0
,
0
))};
job2
.
jobs_
=
{
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
2
,
2
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
2
,
3
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
3
,
3
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
3
,
2
,
0
))};
job3
.
jobs_
=
{
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
1
,
0
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
1
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
1
,
1
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
0
,
0
))};
std
::
vector
<
std
::
pair
<
std
::
string
,
tf2
::
Vector3
>>
boxes
=
{{
"box1"
,
tf2
::
Vector3
(
0
,
0
,
0
)},
{
"box2"
,
tf2
::
Vector3
(
2
,
2
,
0
)}};
cb_jd
.
push_back
({
"panda_arm1"
,
job1
});
cb_jd
.
push_back
({
"panda_arm2"
,
job2
});
cb_jd
.
push_back
({
"panda_arm1"
,
job3
});
while
(
!
cb_jd
.
empty
()){
for
(
auto
&
box
:
boxes
){
std
::
pair
<
std
::
string
,
job_data
>
temp
=
cb_jd
.
front
();
if
(
tf2
::
tf2Distance2
(
temp
.
second
.
jobs_
.
front
().
getOrigin
(),
box
.
second
)
==
0
)
{
for
(
int
k
=
1
;
k
<
temp
.
second
.
jobs_
.
size
();
k
++
){
box
.
second
=
temp
.
second
.
jobs_
[
k
].
getOrigin
();
}
cb_jd
.
pop_front
();
}
else
{
cb_jd
.
push_back
(
temp
);}
}
}
ASSERT_EQ
(
cb_jd
.
size
(),
0
);
//All jobs
}
TEST
(
BtTestSuit
,
ComplexCooperativeTest
){
std
::
map
<
const
std
::
string
,
std
::
vector
<
std
::
tuple
<
const
std
::
string
,
tf2
::
Vector3
,
std
::
vector
<
moveit_task_constructor_msgs
::
ExecuteTaskSolutionGoal
>>>>
task_but_different
;
boost
::
circular_buffer
<
std
::
pair
<
std
::
string
,
job_data
>>
cb_jd
(
3
);
job_data
job1
,
job2
,
job3
;
job1
.
jobs_
=
{
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
1.5f
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
2
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
2.5f
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
3
,
0
))};
job2
.
jobs_
=
{
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
0
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
0.5f
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
1
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
1.5f
,
0
))};
job3
.
jobs_
=
{
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
1.5f
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
2
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
2.5f
,
0
)),
tf2
::
Transform
(
tf2
::
Quaternion
(
0
,
0
,
0
,
1
),
tf2
::
Vector3
(
0
,
3
,
0
))};
std
::
vector
<
std
::
pair
<
std
::
string
,
tf2
::
Vector3
>>
boxes
=
{{
"box1"
,
tf2
::
Vector3
(
0
,
0
,
0
)},
{
"box2"
,
tf2
::
Vector3
(
2
,
2
,
0
)}};
cb_jd
.
push_back
({
"panda_arm1"
,
job3
});
cb_jd
.
push_back
({
"panda_arm1"
,
job1
});
cb_jd
.
push_back
({
"panda_arm2"
,
job2
});
//ASSERT_FALSE(boxes[0].second == cb_jd[0].second.jobs_[0].getOrigin());
bool
jobs_remaining
=
true
;
while
(
jobs_remaining
&&
!
cb_jd
.
empty
()
&&
!
boxes
.
empty
())
{
bool
moved
=
false
;
for
(
auto
it
=
cb_jd
.
begin
();
it
!=
cb_jd
.
end
();)
{
auto
&
temp
=
*
it
;
bool
ready_to_move
=
true
;
for
(
auto
&
box
:
boxes
)
{
if
(
temp
.
second
.
jobs_
.
front
().
getOrigin
()
==
box
.
second
)
{
for
(
int
k
=
1
;
k
<
temp
.
second
.
jobs_
.
size
();
k
++
)
{
box
.
second
=
temp
.
second
.
jobs_
[
k
].
getOrigin
();
}
if
(
ready_to_move
)
{
moved
=
true
;
it
=
cb_jd
.
erase
(
it
);
break
;
}
}
else
{
ready_to_move
=
false
;
}
}
if
(
!
ready_to_move
)
{
++
it
;
}
}
jobs_remaining
=
moved
;
}
ASSERT_EQ
(
cb_jd
.
size
(),
1
);
// All jobs
boxes
.
clear
();
cb_jd
.
push_back
({
"panda_arm1"
,
job3
});
cb_jd
.
push_back
({
"panda_arm1"
,
job1
});
cb_jd
.
push_back
({
"panda_arm2"
,
job2
});
jobs_remaining
=
true
;
while
(
jobs_remaining
&&
!
cb_jd
.
empty
()
&&
!
boxes
.
empty
())
{
bool
moved
=
false
;
for
(
auto
it
=
cb_jd
.
begin
();
it
!=
cb_jd
.
end
();)
{
auto
&
temp
=
*
it
;
bool
ready_to_move
=
true
;
for
(
auto
&
box
:
boxes
)
{
if
(
temp
.
second
.
jobs_
.
front
().
getOrigin
()
==
box
.
second
)
{
for
(
int
k
=
1
;
k
<
temp
.
second
.
jobs_
.
size
();
k
++
)
{
box
.
second
=
temp
.
second
.
jobs_
[
k
].
getOrigin
();
}
if
(
ready_to_move
)
{
moved
=
true
;
it
=
cb_jd
.
erase
(
it
);
break
;
}
}
else
{
ready_to_move
=
false
;
}
}
if
(
!
ready_to_move
)
{
++
it
;
}
}
jobs_remaining
=
moved
;
}
ASSERT_EQ
(
cb_jd
.
size
(),
3
);
// All jobs
}
TEST
(
BtTestSuit
,
bahviorTest
){
//std::unique_ptr<moveit::planning_interface::PlanningSceneInterface> psi_ = std::make_unique<moveit::planning_interface::PlanningSceneInterface>();
BT
::
BehaviorTreeFactory
factory
;
factory
.
registerNodeType
<
Execution
>
(
"Execution"
);
factory
.
registerNodeType
<
PositionCondition
>
(
"PositionCondition"
);
factory
.
registerNodeType
<
Parallel_robot
>
(
"Parallel_robot"
);
std
::
vector
<
std
::
string
>
robots_
=
{
"panda_arm1"
,
"panda_arm2"
};
std
::
map
<
std
::
string
,
std
::
vector
<
std
::
tuple
<
std
::
string
,
tf2
::
Vector3
,
std
::
vector
<
tf2
::
Vector3
>>>>
tasks
;
tasks
[
"panda_arm1"
].
push_back
({
"box1"
,
tf2
::
Vector3
(
0
,
0
,
0
),
{
tf2
::
Vector3
(
0
,
0
,
0
)}});
tasks
[
"panda_arm2"
].
push_back
({
"box2"
,
tf2
::
Vector3
(
0
,
0
,
0
),
{
tf2
::
Vector3
(
0
,
0
,
0
)}});
std
::
stringstream
ss
;
ss
<<
"<root main_tree_to_execute =
\"
MainTree
\"
>
\n
"
;
ss
<<
"<BehaviorTree ID=
\"
MainTree
\"
>
\n
"
;
ss
<<
"<Control ID=
\"
Parallel
\"
name=
\"
Agents
\"
success_threshold=
\"
2
\"
failure_threshold=
\"
2
\"
>
\n
"
;
for
(
auto
&
rob
:
robots_
){
ss
<<
"<Control ID=
\"
Parallel_robot
\"
name=
\"
"
<<
rob
<<
"
\"
success_threshold=
\"
3
\"
failure_threshold=
\"
3
\"
>
\n
"
;
for
(
auto
&
task
:
tasks
){
ss
<<
"<SequenceStar name=
\"
root_sequence
\"
>
\n
"
;
ss
<<
"<Condition ID=
\"
PositionCondition
\"
name=
\"
Position_condition
\"
/>
\n
"
;
ss
<<
"<Action ID=
\"
Execution
\"
name=
\"
Execution
\"
/>
\n
"
;
ss
<<
"</SequenceStar>
\n
"
;
}
ss
<<
"</Control>
\n
"
;
}
ss
<<
"</Control>
\n
"
;
ss
<<
"</BehaviorTree>
\n
"
;
ss
<<
"</root>
\n
"
;
auto
tree
=
factory
.
createTreeFromText
(
ss
.
str
());
auto
node_it
=
tree
.
nodes
.
begin
();
ASSERT_TRUE
(
true
);
}
int
main
(
int
argc
,
char
**
argv
){
testing
::
InitGoogleTest
(
&
argc
,
argv
);
ros
::
init
(
argc
,
argv
,
"bt-test"
);
...
...
This diff is collapsed.
Click to expand it.
Prev
1
2
Next
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment