-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
scalar_dense_output.h
56 lines (45 loc) · 1.72 KB
/
scalar_dense_output.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include "drake/common/default_scalars.h"
#include "drake/common/drake_copyable.h"
#include "drake/systems/analysis/dense_output.h"
namespace drake {
namespace systems {
/// A DenseOutput class interface extension to deal with scalar ODE
/// solutions. A ScalarDenseOutput instance is also a DenseOutput
/// instance with single element vector values (i.e. size() == 1).
/// As such, its value can evaluated in both scalar and vectorial
/// form (via EvaluateScalar() and Evaluate(), respectively).
///
/// @tparam_default_scalar
template <typename T>
class ScalarDenseOutput : public DenseOutput<T> {
public:
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(ScalarDenseOutput)
virtual ~ScalarDenseOutput() = default;
/// Evaluates output at the given time @p t.
/// @param t Time at which to evaluate output.
/// @returns Output scalar value.
/// @pre Output is not empty i.e. is_empty() is false.
/// @throws std::exception if any of the preconditions is not met.
/// @throws std::exception if given @p t is not within output's domain
/// i.e. @p t ∉ [start_time(), end_time()].
T EvaluateScalar(const T& t) const {
this->ThrowIfOutputIsEmpty(__func__);
this->ThrowIfTimeIsInvalid(__func__, t);
return this->DoEvaluateScalar(t);
}
protected:
ScalarDenseOutput() = default;
VectorX<T> DoEvaluate(const T& t) const override {
return VectorX<T>::Constant(1, this->DoEvaluateScalar(t));
}
int do_size() const override {
return 1;
}
// @see EvaluateScalar(const T&)
virtual T DoEvaluateScalar(const T& t) const = 0;
};
} // namespace systems
} // namespace drake
DRAKE_DECLARE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_SCALARS(
class drake::systems::ScalarDenseOutput)