GCC Code Coverage Report | |||||||||||||||||||||
|
|||||||||||||||||||||
Line | Branch | Exec | Source |
1 |
/** |
||
2 |
* Copyright 2019 Max Planck Society. All rights reserved. |
||
3 |
* Julian Viereck |
||
4 |
*/ |
||
5 |
|||
6 |
#include "dg_tools/data/upsampler.hpp" |
||
7 |
|||
8 |
/* --------------------------------------------------------------------- */ |
||
9 |
/* --------------------------------------------------------------------- */ |
||
10 |
/* --------------------------------------------------------------------- */ |
||
11 |
#include <sot/core/debug.hh> |
||
12 |
#include <dynamic-graph/factory.h> |
||
13 |
#include <dynamic-graph/all-commands.h> |
||
14 |
|||
15 |
using namespace dg_tools; |
||
16 |
|||
17 |
✓✗✓✗ ✓✗✓✗ |
4 |
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(Upsampler, "Upsampler"); |
18 |
|||
19 |
/* --------------------------------------------------------------------- */ |
||
20 |
/* --------------------------------------------------------------------- */ |
||
21 |
/* --------------------------------------------------------------------- */ |
||
22 |
|||
23 |
2 |
Upsampler::Upsampler( const std::string & name ) |
|
24 |
:Entity(name) |
||
25 |
,upsampling_factor_(1) |
||
26 |
,is_initialized_(false) |
||
27 |
✓✗✓✗ |
4 |
,data_inputSIN(NULL,"Upsampler("+name+")::input(vector)::sin") |
28 |
,data_outSOUT( boost::bind(&Upsampler::data_out_callback,this,_1,_2), |
||
29 |
data_inputSIN, |
||
30 |
✓✗✓✗ ✓✗✓✗ ✓✗✓✗ ✓✗✓✗ |
6 |
"Upsampler("+name+")::output(vector)::sout" ) |
31 |
{ |
||
32 |
✓✗✓✗ |
2 |
Entity::signalRegistration(data_inputSIN << data_outSOUT); |
33 |
|||
34 |
✓✗ | 6 |
addCommand ( |
35 |
"init", |
||
36 |
✓✗ | 2 |
dynamicgraph::command::makeCommandVoid1( |
37 |
*this, |
||
38 |
&Upsampler::init, |
||
39 |
✓✗✓✗ ✓✗ |
4 |
dynamicgraph::command::docCommandVoid1( |
40 |
"Init the upsampler", |
||
41 |
"int: upsampling factor (how often to repeat the previous input signal)") |
||
42 |
) |
||
43 |
✓✗ | 2 |
); |
44 |
2 |
} |
|
45 |
|||
46 |
1 |
void Upsampler::init(const int& upsampling_factor) |
|
47 |
{ |
||
48 |
1 |
upsampling_factor_ = upsampling_factor; |
|
49 |
1 |
} |
|
50 |
|||
51 |
|||
52 |
/* --------------------------------------------------------------------- */ |
||
53 |
/* --------------------------------------------------------------------- */ |
||
54 |
/* --------------------------------------------------------------------- */ |
||
55 |
|||
56 |
6 |
dg::Vector& Upsampler::data_out_callback(dg::Vector& out, int time) |
|
57 |
{ |
||
58 |
✓✓ | 6 |
if (!is_initialized_) { |
59 |
1 |
is_initialized_ = true; |
|
60 |
1 |
first_time_ = time; |
|
61 |
} |
||
62 |
|||
63 |
✓✓ | 6 |
if ((time - first_time_) % upsampling_factor_ == 0) { |
64 |
// We use the time relative to the first time. |
||
65 |
✓✗✓✗ |
2 |
last_input_ = data_inputSIN((time - first_time_) / upsampling_factor_); |
66 |
} |
||
67 |
|||
68 |
6 |
out = last_input_; |
|
69 |
6 |
return out; |
|
70 |
✓✗✓✗ |
6 |
} |
Generated by: GCOVR (Version 4.2) |