forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request RobotLocomotion#3151 from jwnimmer-tri/basic-state…
…-and-output-vector Add vector base type that serves as both State and Output
- Loading branch information
Showing
14 changed files
with
227 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#include "drake/systems/framework/basic_state_and_output_vector.h" | ||
|
||
// Catch compile errors early, by forcing an instantiation. | ||
template class drake::systems::BasicStateAndOutputVector<double>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
#include <Eigen/Dense> | ||
|
||
#include "drake/common/eigen_types.h" | ||
#include "drake/systems/framework/basic_state_vector.h" | ||
#include "drake/systems/framework/vector_interface.h" | ||
|
||
namespace drake { | ||
namespace systems { | ||
|
||
/// BasicStateAndOutputVector is a concrete class template that implements | ||
/// StateVector in a convenient manner for LeafSystem blocks, and implements | ||
/// VectorInterface so that it may also be used as an output. | ||
/// | ||
/// @tparam T A mathematical type compatible with Eigen's Scalar. | ||
template <typename T> | ||
class BasicStateAndOutputVector : public BasicStateVector<T>, | ||
public VectorInterface<T> { | ||
public: | ||
/// Constructs a BasicStateAndOutputVector of the specified @p size. | ||
explicit BasicStateAndOutputVector(int size) : BasicStateVector<T>(size) {} | ||
|
||
/// Constructs a BasicStateAndOutputVector with the specified @p data. | ||
explicit BasicStateAndOutputVector(const std::vector<T>& data) | ||
: BasicStateVector<T>(data) {} | ||
|
||
/// Constructs a BasicStateAndOutputVector that owns an arbitrary @p vector, | ||
/// which must not be nullptr. | ||
explicit BasicStateAndOutputVector(std::unique_ptr<VectorInterface<T>> vector) | ||
: BasicStateVector<T>(std::move(vector)) {} | ||
|
||
// The size() method overrides both BasicStateVector and VectorInterface. | ||
int size() const override { return this->get_wrapped_vector().size(); } | ||
|
||
// These VectorInterface overrides merely delegate to the wrapped object. | ||
void set_value(const Eigen::Ref<const VectorX<T>>& value) override { | ||
this->get_wrapped_vector().set_value(value); | ||
} | ||
Eigen::VectorBlock<const VectorX<T>> get_value() const override { | ||
return this->get_wrapped_vector().get_value(); | ||
} | ||
Eigen::VectorBlock<VectorX<T>> get_mutable_value() override { | ||
return this->get_wrapped_vector().get_mutable_value(); | ||
} | ||
|
||
// This VectorInterface override must not delegate, because we need to | ||
// maintain our class type (BasicStateAndOutputVector) during cloning. | ||
std::unique_ptr<VectorInterface<T>> CloneVector() const override { | ||
return std::unique_ptr<VectorInterface<T>>(DoClone()); | ||
} | ||
|
||
protected: | ||
BasicStateAndOutputVector(const BasicStateAndOutputVector& other) | ||
: BasicStateVector<T>(other) {} | ||
|
||
BasicStateAndOutputVector<T>* DoClone() const override { | ||
return new BasicStateAndOutputVector<T>(*this); | ||
} | ||
|
||
private: | ||
// Disable these, for consistency with parent class. | ||
BasicStateAndOutputVector& operator=(const BasicStateAndOutputVector&) = | ||
delete; | ||
BasicStateAndOutputVector(BasicStateAndOutputVector&&) = delete; | ||
BasicStateAndOutputVector& operator=(BasicStateAndOutputVector&&) = delete; | ||
}; | ||
|
||
} // namespace systems | ||
} // namespace drake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.