Class Sensor#

Defined in Program listing for file control/src/Sensor/Sensor.hpp

class Sensor#

Sensor Base Class.

Abstract class, interface to user-defined sensors.

A Sensor is dedicated to data capture. It gives an interface for User who can implement its own Sensor to clearly define which data he needs to save.

A Sensor handles a TimeDiscretisation, which defines the set of all instants where the sensor must operate (i.e. each times where capture() function will be called). An Event, inserted into the EventsManager of the Simulation, is linked to this TimeDiscretisation.

Moreover, a Sensor is identified thanks to an id and a type (a number associated to the derived class type indeed).


To build a Sensor it is necessary to use the factory. Inputs are a number which identify the derived class type and a TimeDiscretisation:

// Get the registry
SensorFactory::Registry& regSensor(SensorFactory::Registry::get()) ;
// Build a Sensor of type "myType" with t as a TimeDiscretisation.
regSensor.instantiate(myType, t);

The best way is to use the controlManager:

// cm a ControlManager
// or if cm has already been initialized:

The data are saved in a DataSet object named data, a map which associate to each Event another map. This second map links a std::string, used to identify the data, and a SiconosVector. As an example consider the case where you need to save the state vector x of a DynamicalSystem, then you can define a Data object, with “myDS_X” as an id and yourDS->x() as the SiconosVector. For myEvent being an Event where you need to save data, you get: (data[myEvent])[“myDS_X”] = model->nonSmoothDynamicalSystem()->dynamicalSystem()->x()

See users’ manual for details on how to define its own Sensor.

Subclassed by ControlSensor

Public Functions

Sensor(unsigned int type, SP::DynamicalSystem ds)#

Constructor with a TimeDiscretisation.

  • type – the type of the Sensor, which corresponds to the class type.

  • ds – the SP::DynamicalSystem we observe.

virtual ~Sensor()#


inline void setId(const std::string &newId)#

set id of the Sensor


newId – the id of the Sensor

inline const std::string getId() const#

get id of the Sensor


a std::string

inline unsigned int getType() const#

get the type of the Sensor


an int

inline SP::DynamicalSystem getDS() const#

get the DynamicalSystem linked to this Sensor



inline virtual void setTimeDiscretisation(const TimeDiscretisation &td)#

This is derived in child classes if they need to copy the TimeDiscretisation associated with this Sensor.


td – the TimeDiscretisation for this Sensor

inline virtual void initialize(const NonSmoothDynamicalSystem &nsds)#

initialize sensor data.


nsds – the Model

virtual void capture() = 0#

capture data when the SensorEvent is processed => set data[SensorEvent]=…

void display() const#

display the data of the Sensor on the standard output