Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • mobile_robotics/wolf_projects/wolf_lib/wolf
1 result
Show changes
Commits on Source (5)
...@@ -341,11 +341,7 @@ inline void HasStateBlocks::setState(const StateStructure& _structure, const std ...@@ -341,11 +341,7 @@ inline void HasStateBlocks::setState(const StateStructure& _structure, const std
//// _structure can be either stateblock structure of the node or a subset of this structure //// _structure can be either stateblock structure of the node or a subset of this structure
inline VectorXd HasStateBlocks::getStateVector(const StateStructure& _structure) const inline VectorXd HasStateBlocks::getStateVector(const StateStructure& _structure) const
{ {
StateStructure structure; const StateStructure& structure = (_structure == "" ? structure_ : _structure);
if (_structure == "")
structure = structure_;
else
structure = _structure;
VectorXd state(getSize(structure)); VectorXd state(getSize(structure));
...@@ -353,8 +349,9 @@ inline VectorXd HasStateBlocks::getStateVector(const StateStructure& _structure) ...@@ -353,8 +349,9 @@ inline VectorXd HasStateBlocks::getStateVector(const StateStructure& _structure)
for (const char key : structure) for (const char key : structure)
{ {
const auto& sb = getStateBlock(key); const auto& sb = getStateBlock(key);
if (sb == nullptr){
assert(sb != nullptr && "Requested StateBlock key not in the structure"); throw std::runtime_error("Requested StateBlock key not in the structure");
}
state.segment(index,sb->getSize()) = sb->getState(); state.segment(index,sb->getSize()) = sb->getState();
index += sb->getSize(); index += sb->getSize();
...@@ -370,11 +367,12 @@ inline VectorComposite HasStateBlocks::getState(const StateStructure& _structure ...@@ -370,11 +367,12 @@ inline VectorComposite HasStateBlocks::getState(const StateStructure& _structure
for (const auto key : structure) for (const auto key : structure)
{ {
auto state_it = state_block_map_.find(key); const auto& sb = getStateBlock(key);
if (sb == nullptr){
if (state_it != state_block_map_.end()) throw std::runtime_error("Requested StateBlock key not in the structure");
}
state.emplace(key, state_it->second->getState()); state.emplace(key, sb->getState());
} }
return state; return state;
......
...@@ -209,15 +209,6 @@ TEST_F(HasStateBlocksTest, getState_structure) ...@@ -209,15 +209,6 @@ TEST_F(HasStateBlocksTest, getState_structure)
ASSERT_TRUE(state0.count('P')); ASSERT_TRUE(state0.count('P'));
ASSERT_FALSE(state0.count('O')); ASSERT_FALSE(state0.count('O'));
ASSERT_TRUE(state0.count('V')); ASSERT_TRUE(state0.count('V'));
state0 = F0->getState("OW"); // W does not exist
WOLF_DEBUG("getState(\"OW\") = ", state0);
ASSERT_EQ(state0.size(), 1);
ASSERT_FALSE(state0.count('P'));
ASSERT_TRUE(state0.count('O'));
ASSERT_FALSE(state0.count('V'));
ASSERT_FALSE(state0.count('W'));
} }
......