Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
wolf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mobile_robotics
wolf_projects
wolf_lib
wolf
Commits
d9c78507
Commit
d9c78507
authored
5 years ago
by
Joan Solà Ortega
Browse files
Options
Downloads
Patches
Plain Diff
Move state accessors to HasStateBlocks
parent
9b7b5adb
No related branches found
No related tags found
1 merge request
!323
Resolve "New data structure for storing stateblocks"
Pipeline
#4353
failed
5 years ago
Stage: build
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/core/frame/frame_base.h
+0
-5
0 additions, 5 deletions
include/core/frame/frame_base.h
include/core/state_block/has_state_blocks.h
+91
-9
91 additions, 9 deletions
include/core/state_block/has_state_blocks.h
src/frame/frame_base.cpp
+11
-63
11 additions, 63 deletions
src/frame/frame_base.cpp
with
102 additions
and
77 deletions
include/core/frame/frame_base.h
+
0
−
5
View file @
d9c78507
...
@@ -39,7 +39,6 @@ class FrameBase : public NodeBase, public HasStateBlocks, public std::enable_sha
...
@@ -39,7 +39,6 @@ class FrameBase : public NodeBase, public HasStateBlocks, public std::enable_sha
TrajectoryBaseWPtr
trajectory_ptr_
;
TrajectoryBaseWPtr
trajectory_ptr_
;
CaptureBasePtrList
capture_list_
;
CaptureBasePtrList
capture_list_
;
FactorBasePtrList
constrained_by_list_
;
FactorBasePtrList
constrained_by_list_
;
std
::
string
structure_
;
static
unsigned
int
frame_id_count_
;
static
unsigned
int
frame_id_count_
;
...
@@ -107,10 +106,6 @@ class FrameBase : public NodeBase, public HasStateBlocks, public std::enable_sha
...
@@ -107,10 +106,6 @@ class FrameBase : public NodeBase, public HasStateBlocks, public std::enable_sha
// States
// States
public:
public:
void
setState
(
const
Eigen
::
VectorXs
&
_state
);
void
setState
(
const
Eigen
::
VectorXs
&
_state
);
Eigen
::
VectorXs
getState
()
const
;
void
getState
(
Eigen
::
VectorXs
&
_state
)
const
;
unsigned
int
getSize
()
const
;
unsigned
int
getLocalSize
()
const
;
bool
getCovariance
(
Eigen
::
MatrixXs
&
_cov
)
const
;
bool
getCovariance
(
Eigen
::
MatrixXs
&
_cov
)
const
;
// Wolf tree access ---------------------------------------------------
// Wolf tree access ---------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
include/core/state_block/has_state_blocks.h
+
91
−
9
View file @
d9c78507
...
@@ -9,7 +9,6 @@
...
@@ -9,7 +9,6 @@
#define STATE_BLOCK_HAS_STATE_BLOCKS_H_
#define STATE_BLOCK_HAS_STATE_BLOCKS_H_
#include
"core/common/wolf.h"
#include
"core/common/wolf.h"
#include
"core/state_block/state_block.h"
#include
<map>
#include
<map>
...
@@ -20,8 +19,12 @@ class HasStateBlocks
...
@@ -20,8 +19,12 @@ class HasStateBlocks
{
{
public:
public:
HasStateBlocks
();
HasStateBlocks
();
HasStateBlocks
(
const
std
::
string
&
_structure
)
:
structure_
(
_structure
){}
virtual
~
HasStateBlocks
();
virtual
~
HasStateBlocks
();
const
std
::
string
&
getFrameStructure
()
const
{
return
structure_
;}
std
::
string
&
getFrameStructure
(){
return
structure_
;}
void
appendToStructure
(
const
std
::
string
&
_frame_type
){
structure_
+=
_frame_type
;}
const
std
::
map
<
std
::
string
,
StateBlockPtr
>&
getStateBlockMap
()
const
;
const
std
::
map
<
std
::
string
,
StateBlockPtr
>&
getStateBlockMap
()
const
;
std
::
map
<
std
::
string
,
StateBlockPtr
>&
getStateBlockMap
();
std
::
map
<
std
::
string
,
StateBlockPtr
>&
getStateBlockMap
();
...
@@ -52,14 +55,8 @@ class HasStateBlocks
...
@@ -52,14 +55,8 @@ class HasStateBlocks
}
}
StateBlockPtr
getStateBlock
(
const
std
::
string
&
_sb_type
)
const
;
StateBlockPtr
getStateBlock
(
const
std
::
string
&
_sb_type
)
const
;
StateBlockPtr
getStateBlock
(
const
char
&
_sb_type
)
const
{
return
getStateBlock
(
std
::
string
(
1
,
_sb_type
));}
StateBlockPtr
getStateBlock
(
const
char
&
_sb_type
)
const
{
return
getStateBlock
(
std
::
string
(
1
,
_sb_type
));}
unsigned
int
removeStateBlock
(
const
std
::
string
&
_sb_type
)
unsigned
int
removeStateBlock
(
const
std
::
string
&
_sb_type
);
{
unsigned
int
removeStateBlock
(
const
char
&
_sb_type
);
return
state_block_map_
.
erase
(
_sb_type
);
}
unsigned
int
removeStateBlock
(
const
char
&
_sb_type
)
{
return
removeStateBlock
(
std
::
string
(
1
,
_sb_type
));
}
// Emplace derived state blocks (angle, quaternion, etc).
// Emplace derived state blocks (angle, quaternion, etc).
template
<
typename
SB
,
typename
...
Args
>
template
<
typename
SB
,
typename
...
Args
>
...
@@ -69,12 +66,29 @@ class HasStateBlocks
...
@@ -69,12 +66,29 @@ class HasStateBlocks
template
<
typename
...
Args
>
template
<
typename
...
Args
>
inline
std
::
__1
::
shared_ptr
<
StateBlock
>
emplaceStateBlock
(
const
std
::
string
&
_sb_type
,
Args
&&
...
_args_of_base_state_block_constructor
);
inline
std
::
__1
::
shared_ptr
<
StateBlock
>
emplaceStateBlock
(
const
std
::
string
&
_sb_type
,
Args
&&
...
_args_of_base_state_block_constructor
);
// States
public
:
void
setState
(
const
Eigen
::
VectorXs
&
_state
,
const
bool
_notify
=
true
);
Eigen
::
VectorXs
getState
()
const
;
void
getState
(
Eigen
::
VectorXs
&
_state
)
const
;
unsigned
int
getSize
()
const
;
unsigned
int
getLocalSize
()
const
;
private
:
private
:
std
::
map
<
std
::
string
,
StateBlockPtr
>
state_block_map_
;
std
::
map
<
std
::
string
,
StateBlockPtr
>
state_block_map_
;
std
::
string
structure_
;
};
};
}
// namespace wolf
//////////// IMPLEMENTATION /////////////
#include
"core/state_block/state_block.h"
namespace
wolf
{
inline
HasStateBlocks
::
HasStateBlocks
()
:
inline
HasStateBlocks
::
HasStateBlocks
()
:
state_block_map_
()
state_block_map_
()
{
{
...
@@ -103,6 +117,16 @@ inline wolf::StateBlockPtr HasStateBlocks::setStateBlock(const std::string& _sb_
...
@@ -103,6 +117,16 @@ inline wolf::StateBlockPtr HasStateBlocks::setStateBlock(const std::string& _sb_
return
_sb
;
return
_sb
;
}
}
inline
unsigned
int
HasStateBlocks
::
removeStateBlock
(
const
char
&
_sb_type
)
{
return
removeStateBlock
(
std
::
string
(
1
,
_sb_type
));
}
inline
unsigned
int
HasStateBlocks
::
removeStateBlock
(
const
std
::
string
&
_sb_type
)
{
return
state_block_map_
.
erase
(
_sb_type
);
}
template
<
typename
SB
,
typename
...
Args
>
template
<
typename
SB
,
typename
...
Args
>
inline
std
::
shared_ptr
<
SB
>
HasStateBlocks
::
emplaceStateBlock
(
const
std
::
string
&
_sb_type
,
Args
&&
...
_args_of_derived_state_block_constructor
)
inline
std
::
shared_ptr
<
SB
>
HasStateBlocks
::
emplaceStateBlock
(
const
std
::
string
&
_sb_type
,
Args
&&
...
_args_of_derived_state_block_constructor
)
{
{
...
@@ -205,5 +229,63 @@ inline bool HasStateBlocks::isFixed() const
...
@@ -205,5 +229,63 @@ inline bool HasStateBlocks::isFixed() const
return
fixed
;
return
fixed
;
}
}
inline
void
HasStateBlocks
::
setState
(
const
Eigen
::
VectorXs
&
_state
,
const
bool
_notify
)
{
int
size
=
getSize
();
assert
(
_state
.
size
()
==
size
&&
"In FrameBase::setState wrong state size"
);
unsigned
int
index
=
0
;
for
(
const
char
&
key
:
getFrameStructure
())
// note: key is a char
{
const
auto
&
sb
=
getStateBlock
(
key
);
// note: we need a string, not a char. Use string constructor s(1,char).
sb
->
setState
(
_state
.
segment
(
index
,
sb
->
getSize
()),
_notify
);
// do not notify if state block is not estimated by the solver
index
+=
sb
->
getSize
();
}
}
inline
void
HasStateBlocks
::
getState
(
Eigen
::
VectorXs
&
_state
)
const
{
_state
.
resize
(
getSize
());
unsigned
int
index
=
0
;
for
(
const
char
&
key
:
getFrameStructure
())
// note: key is a char
{
const
auto
&
sb
=
getStateBlock
(
key
);
// note: we need a string, not a char. Use string constructor s(1,char).
_state
.
segment
(
index
,
sb
->
getSize
())
=
sb
->
getState
();
index
+=
sb
->
getSize
();
}
}
inline
Eigen
::
VectorXs
HasStateBlocks
::
getState
()
const
{
Eigen
::
VectorXs
state
;
getState
(
state
);
return
state
;
}
inline
unsigned
int
HasStateBlocks
::
getSize
()
const
{
unsigned
int
size
=
0
;
for
(
const
auto
&
pair_key_sb
:
getStateBlockMap
())
size
+=
pair_key_sb
.
second
->
getSize
();
return
size
;
}
inline
unsigned
int
HasStateBlocks
::
getLocalSize
()
const
{
unsigned
int
size
=
0
;
for
(
const
auto
&
pair_key_sb
:
getStateBlockMap
())
size
+=
pair_key_sb
.
second
->
getLocalSize
();
return
size
;
}
}
// namespace wolf
}
// namespace wolf
#endif
/* STATE_BLOCK_HAS_STATE_BLOCKS_H_ */
#endif
/* STATE_BLOCK_HAS_STATE_BLOCKS_H_ */
This diff is collapsed.
Click to expand it.
src/frame/frame_base.cpp
+
11
−
63
View file @
d9c78507
...
@@ -13,8 +13,8 @@ unsigned int FrameBase::frame_id_count_ = 0;
...
@@ -13,8 +13,8 @@ unsigned int FrameBase::frame_id_count_ = 0;
FrameBase
::
FrameBase
(
const
TimeStamp
&
_ts
,
StateBlockPtr
_p_ptr
,
StateBlockPtr
_o_ptr
,
StateBlockPtr
_v_ptr
)
:
FrameBase
::
FrameBase
(
const
TimeStamp
&
_ts
,
StateBlockPtr
_p_ptr
,
StateBlockPtr
_o_ptr
,
StateBlockPtr
_v_ptr
)
:
NodeBase
(
"FRAME"
,
"Base"
),
NodeBase
(
"FRAME"
,
"Base"
),
HasStateBlocks
(
""
),
trajectory_ptr_
(),
trajectory_ptr_
(),
structure_
(
""
),
frame_id_
(
++
frame_id_count_
),
frame_id_
(
++
frame_id_count_
),
type_
(
NON_ESTIMATED
),
type_
(
NON_ESTIMATED
),
time_stamp_
(
_ts
)
time_stamp_
(
_ts
)
...
@@ -22,24 +22,24 @@ FrameBase::FrameBase(const TimeStamp& _ts, StateBlockPtr _p_ptr, StateBlockPtr _
...
@@ -22,24 +22,24 @@ FrameBase::FrameBase(const TimeStamp& _ts, StateBlockPtr _p_ptr, StateBlockPtr _
if
(
_p_ptr
)
if
(
_p_ptr
)
{
{
setStateBlock
(
"P"
,
_p_ptr
);
setStateBlock
(
"P"
,
_p_ptr
);
s
tructure
_
+=
"P"
;
appendToS
tructure
(
"P"
)
;
}
}
if
(
_o_ptr
)
if
(
_o_ptr
)
{
{
setStateBlock
(
"O"
,
_o_ptr
);
setStateBlock
(
"O"
,
_o_ptr
);
s
tructure
_
+=
"O"
;
appendToS
tructure
(
"O"
)
;
}
}
if
(
_v_ptr
)
if
(
_v_ptr
)
{
{
setStateBlock
(
"V"
,
_v_ptr
);
setStateBlock
(
"V"
,
_v_ptr
);
s
tructure
_
+=
"V"
;
appendToS
tructure
(
"V"
)
;
}
}
}
}
FrameBase
::
FrameBase
(
const
FrameType
&
_tp
,
const
TimeStamp
&
_ts
,
StateBlockPtr
_p_ptr
,
StateBlockPtr
_o_ptr
,
StateBlockPtr
_v_ptr
)
:
FrameBase
::
FrameBase
(
const
FrameType
&
_tp
,
const
TimeStamp
&
_ts
,
StateBlockPtr
_p_ptr
,
StateBlockPtr
_o_ptr
,
StateBlockPtr
_v_ptr
)
:
NodeBase
(
"FRAME"
,
"Base"
),
NodeBase
(
"FRAME"
,
"Base"
),
HasStateBlocks
(
""
),
trajectory_ptr_
(),
trajectory_ptr_
(),
structure_
(
""
),
frame_id_
(
++
frame_id_count_
),
frame_id_
(
++
frame_id_count_
),
type_
(
_tp
),
type_
(
_tp
),
time_stamp_
(
_ts
)
time_stamp_
(
_ts
)
...
@@ -47,24 +47,24 @@ FrameBase::FrameBase(const FrameType & _tp, const TimeStamp& _ts, StateBlockPtr
...
@@ -47,24 +47,24 @@ FrameBase::FrameBase(const FrameType & _tp, const TimeStamp& _ts, StateBlockPtr
if
(
_p_ptr
)
if
(
_p_ptr
)
{
{
setStateBlock
(
"P"
,
_p_ptr
);
setStateBlock
(
"P"
,
_p_ptr
);
s
tructure
_
+=
"P"
;
appendToS
tructure
(
"P"
)
;
}
}
if
(
_o_ptr
)
if
(
_o_ptr
)
{
{
setStateBlock
(
"O"
,
_o_ptr
);
setStateBlock
(
"O"
,
_o_ptr
);
s
tructure
_
+=
"O"
;
appendToS
tructure
(
"O"
)
;
}
}
if
(
_v_ptr
)
if
(
_v_ptr
)
{
{
setStateBlock
(
"V"
,
_v_ptr
);
setStateBlock
(
"V"
,
_v_ptr
);
s
tructure
_
+=
"V"
;
appendToS
tructure
(
"V"
)
;
}
}
}
}
FrameBase
::
FrameBase
(
const
std
::
string
_frame_structure
,
const
SizeEigen
_dim
,
const
FrameType
&
_tp
,
const
TimeStamp
&
_ts
,
const
Eigen
::
VectorXs
&
_x
)
:
FrameBase
::
FrameBase
(
const
std
::
string
_frame_structure
,
const
SizeEigen
_dim
,
const
FrameType
&
_tp
,
const
TimeStamp
&
_ts
,
const
Eigen
::
VectorXs
&
_x
)
:
NodeBase
(
"FRAME"
,
"Base"
),
NodeBase
(
"FRAME"
,
"Base"
),
HasStateBlocks
(
_frame_structure
),
trajectory_ptr_
(),
trajectory_ptr_
(),
structure_
(
_frame_structure
),
frame_id_
(
++
frame_id_count_
),
frame_id_
(
++
frame_id_count_
),
type_
(
_tp
),
type_
(
_tp
),
time_stamp_
(
_ts
)
time_stamp_
(
_ts
)
...
@@ -154,7 +154,7 @@ void FrameBase::registerNewStateBlocks()
...
@@ -154,7 +154,7 @@ void FrameBase::registerNewStateBlocks()
void
FrameBase
::
removeStateBlocks
()
void
FrameBase
::
removeStateBlocks
()
{
{
for
(
const
char
&
key
:
s
tructure
_
)
// note: key is a char
for
(
const
char
&
key
:
getFrameS
tructure
()
)
// note: key is a char
{
{
auto
sbp
=
getStateBlock
(
key
);
auto
sbp
=
getStateBlock
(
key
);
if
(
sbp
!=
nullptr
)
if
(
sbp
!=
nullptr
)
...
@@ -213,59 +213,7 @@ void FrameBase::setAux()
...
@@ -213,59 +213,7 @@ void FrameBase::setAux()
void
FrameBase
::
setState
(
const
Eigen
::
VectorXs
&
_state
)
void
FrameBase
::
setState
(
const
Eigen
::
VectorXs
&
_state
)
{
{
int
size
=
getSize
();
HasStateBlocks
::
setState
(
_state
,
isKeyOrAux
());
assert
(
_state
.
size
()
==
size
&&
"In FrameBase::setState wrong state size"
);
unsigned
int
index
=
0
;
for
(
const
char
&
key
:
structure_
)
// note: key is a char
{
const
auto
&
sb
=
getStateBlock
(
key
);
// note: we need a string, not a char. Use string constructor s(1,char).
sb
->
setState
(
_state
.
segment
(
index
,
sb
->
getSize
()),
isKeyOrAux
());
// do not notify if state block is not estimated by the solver
index
+=
sb
->
getSize
();
}
}
void
FrameBase
::
getState
(
Eigen
::
VectorXs
&
_state
)
const
{
_state
.
resize
(
getSize
());
unsigned
int
index
=
0
;
for
(
const
char
&
key
:
structure_
)
// note: key is a char
{
const
auto
&
sb
=
getStateBlock
(
key
);
// note: we need a string, not a char. Use string constructor s(1,char).
_state
.
segment
(
index
,
sb
->
getSize
())
=
sb
->
getState
();
index
+=
sb
->
getSize
();
}
}
Eigen
::
VectorXs
FrameBase
::
getState
()
const
{
Eigen
::
VectorXs
state
;
getState
(
state
);
return
state
;
}
unsigned
int
FrameBase
::
getSize
()
const
{
unsigned
int
size
=
0
;
for
(
const
auto
&
pair_key_sb
:
getStateBlockMap
())
size
+=
pair_key_sb
.
second
->
getSize
();
return
size
;
}
unsigned
int
FrameBase
::
getLocalSize
()
const
{
unsigned
int
size
=
0
;
for
(
const
auto
&
pair_key_sb
:
getStateBlockMap
())
size
+=
pair_key_sb
.
second
->
getLocalSize
();
return
size
;
}
}
bool
FrameBase
::
getCovariance
(
Eigen
::
MatrixXs
&
_cov
)
const
bool
FrameBase
::
getCovariance
(
Eigen
::
MatrixXs
&
_cov
)
const
...
...
This diff is collapsed.
Click to expand it.
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