Go to the documentation of this file.
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";
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
93 message.set_name(
name);
98 void fromMessage(
const corbo::messages::SignalHeader& message, std::stringstream* issues =
nullptr)
133 class SignalInterface
136 using Ptr = std::shared_ptr<SignalInterface>;
137 using ConstPtr = std::shared_ptr<const SignalInterface>;
146 virtual void getValueLabels(std::vector<std::string>& sublabels)
const {}
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>;
188 void set(
double time,
const std::vector<double>& values)
198 _values.assign(values.data(), values.data() + values.size());
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>;
276 void add(
double time,
const std::vector<double>& values);
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;
333 class TimeSeriesSequenceSignal :
public SignalInterface
336 using Ptr = std::shared_ptr<TimeSeriesSequenceSignal>;
337 using ConstPtr = std::shared_ptr<const TimeSeriesSequenceSignal>;
349 void getValueLabels(std::vector<std::string>& sublabels)
const override
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>;
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);
443 #ifdef MESSAGE_SUPPORT
444 void toMessage(corbo::messages::IndexedValues& message)
const;
445 void fromMessage(
const corbo::messages::IndexedValues& message, std::stringstream* issues =
nullptr);
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>>;
491 void add(
int index,
double value);
493 void add(
const IndexedValuesSignal& indexed_values);
497 void add(
int index,
const std::vector<double>& values);
509 #ifdef MESSAGE_SUPPORT
510 void toMessage(corbo::messages::IndexedValuesSet& message)
const;
511 void fromMessage(
const corbo::messages::IndexedValuesSet& message, std::stringstream* issues =
nullptr);
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>;
576 #ifdef MESSAGE_SUPPORT
577 void toMessage(corbo::messages::Matrix& message)
const;
578 void fromMessage(
const corbo::messages::Matrix& message, std::stringstream* issues =
nullptr);
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>>;
635 #ifdef MESSAGE_SUPPORT
636 void toMessage(corbo::messages::MatrixSet& message)
const;
637 void fromMessage(
const corbo::messages::MatrixSet& message, std::stringstream* issues =
nullptr);
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::shared_ptr< MatrixSignal > Ptr
void setIndex(int index)
Set desired index.
Signal containing values indexed by a single integer.
void set(double time, const std::vector< double > &values)
Set a time and value vector of arbitrary dimension (overrides any existing values)
bool isEmpty() const
Check if the time series is empty.
std::shared_ptr< const MatrixSetSignal > ConstPtr
SignalType getType() const override
Get the signal type according to enumeration SignalType.
Sequence of time series objects.
SignalType
Available signal types (must match messages::SignalType enumeration)
void set(TimeSeriesSequence::Ptr ts_sequence)
Set time series sequence (and override any existing)
std::shared_ptr< SignalInterface > Ptr
Map & getDataRef()
Write access to the underlying map (use with care)
void fromSec(double t)
Set time stamp from seconds.
void setTimeFromStart(double time_from_start)
Set time from start (offset to all time stamps in time())
virtual ~SignalInterface()
Virtual destructor.
const TimeSeries * getTimeSeries() const
Read access to the underlying time series object (returns null if not initialized)
const std::vector< std::string > & getValueLabels() const
Access labels of signal components (might be empty if not provided) [read-only].
bool isEmpty() const
Check if the underlying map is empty.
std::vector< std::string > & getValueLabelsRef()
Access labels of signal components (might be empty if not provided, allowed to modify directly)
std::string & getLabelRef()
Write access to the label.
void add(const Measurement &measurement)
Add measurement (time and value pair)
Map< Matrix< T, Dynamic, Dynamic, ColMajor >, 0, OuterStride<> > matrix(T *data, int rows, int cols, int stride)
bool isEmpty() const
Check if the underlying map is empty.
int getRowDimension() const
std::shared_ptr< MatrixSetSignal > Ptr
Time Series signal (trajectory resp. sequence of values w.r.t. time)
TimeSeriesSignal()
Default constructor.
TimeSeriesSequenceSignal()
Default constructor.
SignalType getType() const override
Get the signal type according to enumeration SignalType.
void set(const Eigen::Ref< const Eigen::MatrixXd > &matrix, const std::string &label="")
Set matrix (overwrites internal matrix)
TimeSeriesSequence::Ptr getSequencePtr() const
Return shared pointer of the underlying time series sequence (can be empty if not initialized)
double toSec() const
Cast time stamp to seconds.
std::vector< double > & getValuesRef()
Access value vector.
Measurement()
Default constructor.
std::shared_ptr< TimeSeriesSequence > Ptr
std::vector< MatrixSignal::Ptr > & getDataRef()
Write access to the underlying map (use with care)
SignalHeader header
The header of the signal.
Signal containing values indexed by an integer (int to double[] map)
IndexedValuesSignal()=default
Default constructor.
virtual SignalType getType() const =0
Get the signal type according to enumeration SignalType.
double getTime() const
Retrieve recorded time of the measurement.
void add(TimeSeries::Ptr ts)
Add a new time serie to the sequence.
MatrixSignal()=default
Default constructor.
bool isEmpty() const
Check if the underlying map is empty.
std::shared_ptr< const IndexedValuesSetSignal > ConstPtr
Signal containing a set of matrices.
const std::vector< MatrixSignal::Ptr > & getData() const
Read access to the underlying map object.
const Map & getData() const
Read access to the underlying map object.
double _time
measurement time
Interface class for signals.
constexpr const char SIGNAL_NAMESPACE_DELIMITER
std::map< int, std::vector< double > > Map
MatrixSetSignal()=default
Default constructor.
TimeSeriesSequence * getSequenceRaw()
Raw access to the underlying time series sequence (returns null if not initialized)
TimeSeriesSequence::Ptr _ts_sequence
std::vector< MatrixSignal::Ptr > _matrix_set
std::vector< double > & getValuesRef()
Write access to the underlying values data (use with care)
std::vector< double > _values
corresponding value vector
const std::vector< double > & getValues() const
Access value vector (read-only)
Time Series (trajectory resp. sequence of values w.r.t. time)
A matrix or vector expression mapping an existing expression.
SignalType getType() const override
Get the signal type according to enumeration SignalType.
TimeSeries::Ptr _time_series
bool isEmpty() const
Check if the underlying map is empty.
int getMaxValueDimension() const
Iterate internal map to find the largest value vector dimension.
SignalType getType() const override
Get the signal type according to enumeration SignalType.
SignalType getType() const override
Get the signal type according to enumeration SignalType.
std::shared_ptr< const SignalInterface > ConstPtr
int getColDimension() const
std::vector< double > _values
const std::vector< double > & getValues() const
Read access to the underlying values object.
SignalType getType() const override
Get the signal type according to enumeration SignalType.
SignalType getType() const override
Get the signal type according to enumeration SignalType.
void add(int index, double value)
Add index value pair.
bool isEmpty() const
Determine if no time series is available.
IndexedValuesSetSignal()=default
Default constructor.
std::shared_ptr< IndexedValuesSetSignal > Ptr
const TimeSeriesSequence * getSequence() const
Read access to the underlying time series sequence (returns null if not initialized)
std::vector< std::string > _value_labels
labels for value vector components (optional)
int getValueDimension() const
std::map< int, std::vector< double > > Map
void set(int index, double value)
Set index value pair (wipes off previous values)
Signal containing a simple matrix.
const Eigen::MatrixXd & getMatrix() const
Read access to the underlying matrix object.
void add(double value)
Add value.
void add(MatrixSignal::Ptr &matrix_signal)
Add matrix signal.
std::shared_ptr< TimeSeries > Ptr
const std::string & getLabel() const
Read access to the label.
virtual void getValueLabels(std::vector< std::string > &sublabels) const
Return labels for the underlying components of the signal (e.g. axes labels)
Eigen::MatrixXd & getMatrixRef()
Write access to the underlying matrix (use with care)
int getIndex() const
Return current index.
void getValueLabels(std::vector< std::string > &sublabels) const override
Return labels for the underlying components of the signal (e.g. axes labels)
Measurement signal (value vector recorded at a specific time)
TimeSeries::Ptr getTimeSeriesPtr() const
Return shared pointer of the underlying time series (can be empty if not initialized)
TimeSeries * getTimeSeriesRaw()
Raw access to the underlying time series object (returns null if not initialized)
void getValueLabels(std::vector< std::string > &sublabels) const override
Return labels for the underlying components of the signal (e.g. axes labels)
void set(TimeSeries::Ptr time_series)
Set time series (and override any existing)
control_box_rst
Author(s): Christoph Rösmann
autogenerated on Wed Mar 2 2022 00:06:12