User Tools

Site Tools


for_developers:signal_probe_block

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
for_developers:signal_probe_block [2016/08/17 11:12] – [How to implement the //signalProbeBlock//] gehrigfor_developers:signal_probe_block [2017/09/24 15:36] (current) – removed graf
Line 1: Line 1:
-====== Signal probe block ====== 
  
-===== How the signal probe block works ===== 
-The //signalProbeBlock// can be connected to signals like every other block. The //signalProbeBlock// saves the value and the timestamp of each connected signal after each call in a buffer. If the buffer is full, the oldest value will be overridden. The size of the buffer is about 10'000 values, which holds about 10 seconds of data. The size of the buffer can be defined at the declaration of the //signalProbeBlock//. 
- 
-The measurement stops when the application is terminated or it can be stopped, when a certain safety level is reached. At the end, the measurements are written in a file with a csv compatible format. 
- 
-The measured data is written in a buffer in RAM because writing in a file would influence the real time performance of the system. 
- 
-===== How to implement the signalProbeBlock ===== 
-To use the //signalProbeBlock// code has to be implemented at three different places. If the measurement should be stopped by a level change of the safety system, some lines of code have to be added to the safety system. 
- 
-==== Declaration ==== 
-Because only single signals and not vectors can be connected to the block, a //DeMux// block is also used in this example. For each signal type a different block has to be declared. In this example a block for 10 float-signals is declared. 
- 
-In ControlSystem.hpp: 
-<code cpp> 
-... 
- 
-eeros::control::DeMux<2,double> demux_SPB; 
-parallelscara::SignalProbeBlock<10, double, bufferSize> signalProbeDouble; 
- 
-... 
-</code> 
- 
-==== Connection with signals ==== 
-The //signalProbeBlock// can be connected like every other block. If a vector signal should be probed, a //DeMux// block is needed. 
- 
-In ControlSystem.cpp: 
-<code cpp> 
-.. 
- 
-// connect the signal to the DeMux 
-demux_SPB.getIn().connect(robotController.get_dacOut()); 
- 
-// connect the DeMux to the signalProbeBlock 
-signalProbeDouble.getIn(0).connect(demux_SPB.getOut(0)); 
-signalProbeDouble.getIn(1).connect(demux_SPB.getOut(1)); 
- 
-// name the signals 
-signalProbeDouble.setName(0, "Robot Controller DAC 0"); 
-signalProbeDouble.setName(1, "Robot Controller DAC 1"); 
- 
-... 
- 
-// run the blocks 
-timedomain.addBlock(&demux_SPB); 
-timedomain.addBlock(&signalProbeDouble); 
-</code> 
- 
-==== Write the buffered data to a file ==== 
-When the application is terminated, the data has to be written to a file. 
- 
-In Main.cpp 
- 
-<code cpp> 
-... 
- 
- std::cout << "start writing file 'signalProbePC.csv'" << std::endl; 
- std::ofstream fileSPPC; 
- fileSPPC.open("/tmp/signalProbePC.csv"); 
- fileSPPC << controlSystem.pendulumController.signalProbePC.getMetaInfoStr(); 
- fileSPPC << controlSystem.pendulumController.signalProbePC.getDataStr(); 
- fileSPPC.close(); 
- std::cout << "file 'signalProbePC' written" << std::endl; 
-  
- while(safetySystem.getCurrentLevel().getId() ==  off) usleep(100000); 
- log.trace() << "SCARA Robot Control Application finished"; 
- return 0; 
-} 
-</code> 
- 
-If the //signalProbeBlock// is contained in an other block, following lines can be used: 
-<code cpp> 
-... 
- 
-fileSPPC << controlSystem.pendulumController.signalProbePC.getMetaInfoStr(); 
-fileSPPC << controlSystem.pendulumController.signalProbePC.getDataStr(); 
- 
-... 
-</code> 
- 
-==== Stop measurement in case of a level change ==== 
-The measurement can be stopped, when a certain safety level is reached. This can be useful, to find a reason for a emergency stop. In this example 1'000 additional measuring points are safed, after the safety level //emergency// is called. 
- 
-In SafetyProporties.cpp: 
-<code cpp> 
-... 
- 
- level(emergency).setLevelAction([this](SafetyContext* privateContext) {  
- static bool firstCall = true; 
- if (firstCall) { 
- firstCall = false; 
- controlSys->signalProbeDouble.stopLogging(1000); // nrOfMeasurementsAfterStop = 1'000 
- } 
- } 
- 
-... 
-</code> 
- 
-===== The csv file ===== 
-The csv file is saved in a style, which easily can be opened with Excel or Matlab. 
- 
-This is an example for two signals: 
-<code> 
-TS: Signal 0,Value: Signal 0,TS: Signal 0,Value: Signal 0, 
-1.0,3.66,1.0,5.812, 
-1.1002,3.72,1.1002,5.92, 
- 
-... 
-</code> 
for_developers/signal_probe_block.1471425133.txt.gz · Last modified: 2016/08/17 11:12 (external edit)