25 #ifndef SRC_CORE_INCLUDE_CORBO_CORE_SIGNALS_H_ 26 #define SRC_CORE_INCLUDE_CORBO_CORE_SIGNALS_H_ 33 #ifdef MESSAGE_SUPPORT 34 #include <corbo-communication/messages/core/signals.pb.h> 40 #include <type_traits> 41 #include <unordered_map> 77 std::string name =
"unknown";
79 int value_dimension = 0;
80 bool zero_order_hold =
false;
84 std::size_t found = name.find_last_of(
"/");
85 return name.substr(found + 1);
88 #ifdef MESSAGE_SUPPORT 89 void toMessage(corbo::messages::SignalHeader& message)
const 92 message.set_time(time.
toSec());
93 message.set_name(name);
94 message.set_value_dimension(value_dimension);
95 message.set_zero_order_hold(zero_order_hold);
98 void fromMessage(
const corbo::messages::SignalHeader& message, std::stringstream* issues =
nullptr)
101 name = message.name();
102 value_dimension = message.value_dimension();
103 zero_order_hold = message.zero_order_hold();
136 using Ptr = std::shared_ptr<SignalInterface>;
137 using ConstPtr = std::shared_ptr<const SignalInterface>;
151 #ifdef MESSAGE_SUPPORT 152 virtual void toMessage(corbo::messages::Signal& message)
const {}
155 virtual void fromMessage(
const corbo::messages::Signal& message, std::stringstream* issues =
nullptr) {}
174 using Ptr = std::shared_ptr<Measurement>;
175 using ConstPtr = std::shared_ptr<const Measurement>;
180 Measurement(
double time,
const std::vector<double>& values) : _time(time), _values(values) {}
188 void set(
double time,
const std::vector<double>& values)
198 _values.assign(values.data(), values.data() + values.size());
202 const std::vector<double>&
getValues()
const {
return _values; }
215 void getValueLabels(std::vector<std::string>& sublabels)
const override { sublabels = _value_labels; }
217 #ifdef MESSAGE_SUPPORT 219 void toMessage(corbo::messages::Signal& message)
const override;
221 void fromMessage(
const corbo::messages::Signal& message, std::stringstream* issues =
nullptr)
override;
247 using Ptr = std::shared_ptr<TimeSeriesSignal>;
248 using ConstPtr = std::shared_ptr<const TimeSeriesSignal>;
260 bool isEmpty()
const {
return _time_series ? _time_series->isEmpty() :
true; }
268 if (_time_series) sublabels = _time_series->getValueLabels();
276 void add(
double time,
const std::vector<double>& values);
295 void setTimeFromStart(
double time_from_start);
305 #ifdef MESSAGE_SUPPORT 307 void toMessage(corbo::messages::Signal& message)
const override;
309 void fromMessage(
const corbo::messages::Signal& message, std::stringstream* issues =
nullptr)
override;
336 using Ptr = std::shared_ptr<TimeSeriesSequenceSignal>;
337 using ConstPtr = std::shared_ptr<const TimeSeriesSequenceSignal>;
345 bool isEmpty()
const {
return _ts_sequence ? _ts_sequence->isEmpty() :
true; }
352 if (_ts_sequence && !_ts_sequence->isEmpty() && _ts_sequence->getSequence().front())
353 sublabels = _ts_sequence->getSequence().front()->getValueLabels();
370 #ifdef MESSAGE_SUPPORT 372 void toMessage(corbo::messages::Signal& message)
const override;
374 void fromMessage(
const corbo::messages::Signal& message, std::stringstream* issues =
nullptr)
override;
393 using Ptr = std::shared_ptr<IndexedValuesSignal>;
394 using ConstPtr = std::shared_ptr<const IndexedValuesSignal>;
408 bool isEmpty()
const {
return _values.empty(); }
420 void add(
double value) { _values.push_back(value); }
424 void add(
const std::vector<double>& values);
427 void set(
int index,
double value);
431 void set(
int index,
const std::vector<double>& values);
436 const std::vector<double>&
getValues()
const {
return _values; }
443 #ifdef MESSAGE_SUPPORT 447 void toMessage(corbo::messages::Signal& message)
const override 449 header.toMessage(*message.mutable_header());
450 toMessage(*message.mutable_indexed_values());
453 void fromMessage(
const corbo::messages::Signal& message, std::stringstream* issues =
nullptr)
override 455 header.fromMessage(message.header());
456 fromMessage(message.indexed_values(), issues);
477 using Ptr = std::shared_ptr<IndexedValuesSetSignal>;
478 using ConstPtr = std::shared_ptr<const IndexedValuesSetSignal>;
479 using Map = std::map<int, std::vector<double>>;
485 bool isEmpty()
const {
return _values_map.empty(); }
491 void add(
int index,
double value);
497 void add(
int index,
const std::vector<double>& values);
505 int getMaxValueDimension()
const;
507 void clear() { _values_map.clear(); }
509 #ifdef MESSAGE_SUPPORT 513 void toMessage(corbo::messages::Signal& message)
const override 515 header.toMessage(*message.mutable_header());
516 toMessage(*message.mutable_indexed_values_set());
519 void fromMessage(
const corbo::messages::Signal& message, std::stringstream* issues =
nullptr)
override 521 header.fromMessage(message.header());
522 fromMessage(message.indexed_values_set(), issues);
542 using Ptr = std::shared_ptr<MatrixSignal>;
543 using ConstPtr = std::shared_ptr<const MatrixSignal>;
551 bool isEmpty()
const {
return _matrix.rows() == 0 && _matrix.cols() == 0; }
567 const Eigen::MatrixXd&
getMatrix()
const {
return _matrix; }
572 const std::string&
getLabel()
const {
return _label; }
576 #ifdef MESSAGE_SUPPORT 580 void toMessage(corbo::messages::Signal& message)
const override 582 header.toMessage(*message.mutable_header());
583 toMessage(*message.mutable_matrix());
586 void fromMessage(
const corbo::messages::Signal& message, std::stringstream* issues =
nullptr)
override 588 header.fromMessage(message.header());
589 fromMessage(message.matrix(), issues);
610 using Ptr = std::shared_ptr<MatrixSetSignal>;
611 using ConstPtr = std::shared_ptr<const MatrixSetSignal>;
612 using Map = std::map<int, std::vector<double>>;
618 bool isEmpty()
const {
return _matrix_set.empty(); }
629 const std::vector<MatrixSignal::Ptr>&
getData()
const {
return _matrix_set; }
631 std::vector<MatrixSignal::Ptr>&
getDataRef() {
return _matrix_set; }
633 void clear() { _matrix_set.clear(); }
635 #ifdef MESSAGE_SUPPORT 639 void toMessage(corbo::messages::Signal& message)
const override 641 header.toMessage(*message.mutable_header());
642 toMessage(*message.mutable_matrix_set());
645 void fromMessage(
const corbo::messages::Signal& message, std::stringstream* issues =
nullptr)
override 647 header.fromMessage(message.header());
648 fromMessage(message.matrix_set(), issues);
658 #endif // SRC_CORE_INCLUDE_CORBO_CORE_SIGNALS_H_ std::vector< double > & getValuesRef()
Write access to the underlying values data (use with care)
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
Signal for a sequence of time series objects.
TimeSeriesSequence::Ptr getSequencePtr() const
Return shared pointer of the underlying time series sequence (can be empty if not initialized) ...
Time Series (trajectory resp. sequence of values w.r.t. time)
Measurement(double time, const Eigen::Ref< const Eigen::VectorXd > &values)
Construct measurement with a given time and value vector (Eigen version)
const TimeSeriesSequence * getSequence() const
Read access to the underlying time series sequence (returns null if not initialized) ...
TimeSeriesSignal(TimeSeries::Ptr time_series)
Construct time series signal from a time_series object (avoids copying)
SignalType
Available signal types (must match messages::SignalType enumeration)
IndexedValuesSignal(int index, const Eigen::Ref< const Eigen::VectorXd > &values)
Construct with desired index and value vector (STL version)
void getValueLabels(std::vector< std::string > &sublabels) const override
Return labels for the underlying components of the signal (e.g. axes labels)
std::vector< std::string > _value_labels
labels for value vector components (optional)
int getIndex() const
Return current index.
TimeSeriesSequence * getSequenceRaw()
Raw access to the underlying time series sequence (returns null if not initialized) ...
virtual void getValueLabels(std::vector< std::string > &sublabels) const
Return labels for the underlying components of the signal (e.g. axes labels)
IndexedValuesSignal(int index, const std::vector< double > &values)
Construct with desired index and value vector.
Eigen::MatrixXd & getMatrixRef()
Write access to the underlying matrix (use with care)
Interface class for signals.
SignalType getType() const override
Get the signal type according to enumeration SignalType.
std::vector< double > _values
bool isEmpty() const
Check if the underlying map is empty.
int getRowDimension() const
Map & getDataRef()
Write access to the underlying map (use with care)
const std::string & getLabel() const
Read access to the label.
std::vector< MatrixSignal::Ptr > & getDataRef()
Write access to the underlying map (use with care)
std::vector< double > _values
corresponding value vector
const TimeSeries * getTimeSeries() const
Read access to the underlying time series object (returns null if not initialized) ...
SignalType getType() const override
Get the signal type according to enumeration SignalType.
Sequence of time series objects.
Representation of time stamps.
bool isEmpty() const
Determine if no time series is available.
TimeSeriesSequenceSignal(int value_dim)
Construct empty signal with a desired value vector dimension.
double getTime() const
Retrieve recorded time of the measurement.
MatrixSignal(const Eigen::Ref< const Eigen::MatrixXd > &matrix, const std::string &label="")
Construct with matrix.
Signal containing a set of matrices.
SignalHeader header
The header of the signal.
bool isEmpty() const
Check if the time series is empty.
Signal containing values indexed by a single integer.
std::shared_ptr< SignalInterface > Ptr
TimeSeriesSignal(int value_dim)
Construct empty time series signal with a dresired value vector dimension.
void getValueLabels(std::vector< std::string > &sublabels) const override
Return labels for the underlying components of the signal (e.g. axes labels)
Measurement()
Default constructor.
TimeSeriesSignal()
Default constructor.
bool isEmpty() const
Check if the underlying map is empty.
IndexedValuesSignal(int index)
Construct with desired index.
virtual ~SignalInterface()
Virtual destructor.
bool isEmpty() const
Check if the underlying map is empty.
std::shared_ptr< const SignalInterface > ConstPtr
SignalType getType() const override
Get the signal type according to enumeration SignalType.
void add(double value)
Add value.
int getValueDimension() const
Measurement(double time, const std::vector< double > &values)
Construct measurement with a given time and value vector (Std version)
Measurement signal (value vector recorded at a specific time)
SignalType getType() const override
Get the signal type according to enumeration SignalType.
TimeSeriesSignal(const Measurement &measurment)
Constructs and initializes time series signal and adds a single measurement.
SignalType getType() const override
Get the signal type according to enumeration SignalType.
TimeSeriesSequenceSignal()
Default constructor.
std::shared_ptr< MatrixSignal > Ptr
TimeSeriesSequence::Ptr _ts_sequence
A matrix or vector expression mapping an existing expression.
void getValueLabels(std::vector< std::string > &sublabels) const override
Return labels for the underlying components of the signal (e.g. axes labels)
const std::vector< std::string > & getValueLabels() const
Access labels of signal components (might be empty if not provided) [read-only].
Time Series signal (trajectory resp. sequence of values w.r.t. time)
const std::vector< double > & getValues() const
Read access to the underlying values object.
double toSec() const
Cast time stamp to seconds.
Signal containing a simple matrix.
double _time
measurement time
TimeSeries::Ptr getTimeSeriesPtr() const
Return shared pointer of the underlying time series (can be empty if not initialized) ...
void setIndex(int index)
Set desired index.
TimeSeries::Ptr _time_series
SignalType getType() const override
Get the signal type according to enumeration SignalType.
constexpr const char SIGNAL_NAMESPACE_DELIMITER
const std::vector< MatrixSignal::Ptr > & getData() const
Read access to the underlying map object.
std::shared_ptr< TimeSeriesSequence > Ptr
void fromSec(double t)
Set time stamp from seconds.
IndexedValuesSignal(int index, double value)
Construct with desired index and single value.
int getColDimension() const
std::shared_ptr< TimeSeries > Ptr
const Map & getData() const
Read access to the underlying map object.
std::map< int, std::vector< double > > Map
std::map< int, std::vector< double > > Map
SignalType getType() const override
Get the signal type according to enumeration SignalType.
std::vector< double > & getValuesRef()
Access value vector.
std::vector< MatrixSignal::Ptr > _matrix_set
TimeSeries * getTimeSeriesRaw()
Raw access to the underlying time series object (returns null if not initialized) ...
const std::vector< double > & getValues() const
Access value vector (read-only)
std::vector< std::string > & getValueLabelsRef()
Access labels of signal components (might be empty if not provided, allowed to modify directly) ...
bool isEmpty() const
Check if the underlying map is empty.
Signal containing values indexed by an integer (int to double[] map)
const Eigen::MatrixXd & getMatrix() const
Read access to the underlying matrix object.
std::string & getLabelRef()
Write access to the label.