Skip to content

Commit

Permalink
Fixes bug when reporting number of positions/velocities for discrete …
Browse files Browse the repository at this point in the history
…state context (RobotLocomotion#9524)
  • Loading branch information
amcastro-tri authored Sep 26, 2018
1 parent 2fe8fe2 commit 0addfac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ class AcrobotPlantTests : public ::testing::Test {
discrete_context_->FixInputPort(
discrete_plant_->get_actuation_input_port().get_index(),
Vector1<double>(0.0));

const auto& mbt_context =
dynamic_cast<MultibodyTreeContext<double>&>(*discrete_context_);
ASSERT_EQ(mbt_context.num_positions(), 2);
ASSERT_EQ(mbt_context.num_velocities(), 2);
ASSERT_EQ(mbt_context.get_positions().size(), 2);
ASSERT_EQ(mbt_context.get_velocities().size(), 2);
}

// Computes the vector of generalized forces due to gravity.
Expand Down
4 changes: 2 additions & 2 deletions multibody/multibody_tree/multibody_tree_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ class MultibodyTreeContext: public systems::LeafContext<T> {

/// Returns the size of the generalized positions vector.
int num_positions() const {
return this->get_continuous_state().get_generalized_position().size();
return topology_.num_positions();
}

/// Returns the size of the generalized velocities vector.
int num_velocities() const {
return this->get_continuous_state().get_generalized_velocity().size();
return topology_.num_velocities();
}

/// Returns `true` if the state is discrete and `false` if the state is
Expand Down

0 comments on commit 0addfac

Please sign in to comment.