Skip to content

Commit 17748ae

Browse files
authored
Merge branch 'master' into fix/wrong_parameter_name_in_default
2 parents b038a17 + a68218e commit 17748ae

File tree

10 files changed

+106
-34
lines changed

10 files changed

+106
-34
lines changed

cuckoo_time_translator/cfg/DeviceTimeTranslator.cfg

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ gen.add("switch_time", double_t, 0,
1010
0, 0.0, 36000)
1111

1212
algo_enum = gen.enum([
13-
gen.const("ReceiveTimeOnly", int_t, 0, "No device time. Receive time only is used."),
14-
gen.const("ConvexHull", int_t, 1, "Convex hull"),
15-
gen.const("Kalman", int_t, 2, "Kalman filter"),
13+
gen.const("ReceiveTimePassThrough",
14+
int_t, 0,
15+
"Receive time is passed through as translated time. Device time is ignored."),
16+
gen.const("ConvexHull",
17+
int_t, 1,
18+
"Convex hull translator"),
19+
gen.const("Kalman",
20+
int_t, 2,
21+
"Kalman filter based translator"),
22+
gen.const("DeviceTimePassThrough",
23+
int_t, 3,
24+
"Device time is passed through as translated time. Receive time is ignored."),
1625
],
1726
"Device timestamp filter algorithm")
1827

19-
gen.add("filter_algo", int_t, 0, "The filter algorithm used for device timestamps", 0, 0, 3, edit_method=algo_enum)
28+
gen.add("filter_algo", int_t, 0, "The translation algorithm used for device timestamps", 0, 0, 3, edit_method=algo_enum)
2029

2130
exit(gen.generate(PACKAGE, "dynamic_reconfigure_node", "DeviceTimeTranslator"))

cuckoo_time_translator/include/cuckoo_time_translator/DeviceTimeTranslator.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@ class DeviceTimeTranslatorConfig;
1818
//TODO (c++11) use enum class
1919
struct FilterAlgorithm {
2020
enum Type {
21-
ReceiveTimeOnly,
21+
ReceiveTimeOnly = 0, // for backwards compatibility
22+
ReceiveTimePassThrough = 0,
2223
ConvexHull,
2324
Kalman,
25+
DeviceTimePassThrough
2426
} type;
2527

2628
FilterAlgorithm(Type t) : type(t) {}

cuckoo_time_translator/include/cuckoo_time_translator/OwtFactory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class OwtFactoryImpl : public OwtFactory, public Config {
3232

3333
typedef OwtFactoryImpl<FilterAlgorithm::Kalman, KalmanOwt, KalmanOwt::Config> KalmanOwtFactory;
3434
typedef OwtFactoryImpl<FilterAlgorithm::ConvexHull, ConvexHullOwt> ConvexHullOwtFactory;
35-
typedef OwtFactoryImpl<FilterAlgorithm::ReceiveTimeOnly, NopOwt> ReceiveTimeOnlyOwtFactory;
35+
typedef OwtFactoryImpl<FilterAlgorithm::ReceiveTimePassThrough, ReceiveTimePassThroughOwt> ReceiveTimePassThroughOwtFactory;
36+
typedef OwtFactoryImpl<FilterAlgorithm::DeviceTimePassThrough, DeviceTimePassThroughOwt> DeviceTimePassThroughOwtFactory;
3637
}
3738

3839
#endif /* HA1414207_EF1A_4368_BD21_A56BFFA7D0BB */

cuckoo_time_translator/src/DeviceTimeTranslator.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ NS::NS(const char* nameSpace, bool appendDeviceTimeSubnamespace)
5757
class Defaults::Impl {
5858
public:
5959
Impl(){
60-
regOwtFactory(new ReceiveTimeOnlyOwtFactory);
60+
regOwtFactory(new ReceiveTimePassThroughOwtFactory);
6161
regOwtFactory(new KalmanOwtFactory);
6262
regOwtFactory(new ConvexHullOwtFactory);
63+
regOwtFactory(new DeviceTimePassThroughOwtFactory);
6364
}
6465

6566
Impl(const Impl& other){
@@ -143,8 +144,8 @@ std::unique_ptr<OneWayTranslator> Defaults::Impl::createOwt(FilterAlgorithm fa)
143144
if(e != owtFactoryReg_.end()){
144145
return e->second->createOwt();
145146
} else {
146-
ROS_ERROR("Unknown device time filter algorithm : %u. Falling back to no filter (NopOwt).", static_cast<unsigned>(fa));
147-
return std::unique_ptr<OneWayTranslator>(new NopOwt);
147+
ROS_ERROR("Unknown device time filter algorithm : %u. Falling back to default translator (ReceiveTimePassThroughOwt).", static_cast<unsigned>(fa));
148+
return std::unique_ptr<OneWayTranslator>(new ReceiveTimePassThroughOwt);
148149
}
149150
}
150151

@@ -225,7 +226,9 @@ class DeviceTimeTranslator::Impl {
225226
switchingTimeSeconds_ = expectedSwitchingTimeSeconds;
226227
somethingWasUpdated = true;
227228
timeTranslator_ = defaults_.createOwt(expectedAlgo_);
228-
if(dynamic_cast<NopOwt*>(timeTranslator_.get()) == nullptr && shouldSwitch(expectedSwitchingTimeSeconds)){
229+
if(dynamic_cast<ReceiveTimePassThroughOwtFactory*>(timeTranslator_.get()) == nullptr
230+
&& dynamic_cast<DeviceTimePassThroughOwtFactory*>(timeTranslator_.get()) == nullptr
231+
&& shouldSwitch(expectedSwitchingTimeSeconds)){
229232
timeTranslator_ = std::unique_ptr<OneWayTranslator>(new SwitchingOwt(expectedSwitchingTimeSeconds, [this]() { return defaults_.createOwt(expectedAlgo_); }));
230233
}
231234
switchingTimeSeconds_ = expectedSwitchingTimeSeconds;
@@ -252,7 +255,8 @@ class DeviceTimeTranslator::Impl {
252255
}
253256

254257
std::unique_ptr<OneWayTranslator> timeTranslator_;
255-
FilterAlgorithm currentAlgo_ = FilterAlgorithm::ReceiveTimeOnly, expectedAlgo_ = FilterAlgorithm::ReceiveTimeOnly;
258+
FilterAlgorithm currentAlgo_ = FilterAlgorithm::ReceiveTimePassThrough;
259+
FilterAlgorithm expectedAlgo_ = FilterAlgorithm::ReceiveTimePassThrough;
256260
Defaults defaults_;
257261
ros::Publisher deviceTimePub_;
258262
ros::NodeHandle nh_;
@@ -282,8 +286,11 @@ DeviceTimeTranslator::DeviceTimeTranslator(const NS & nameSpace, const Defaults
282286
pImpl_->getDeviceTimePub() = pImpl_->getNh().advertise<DeviceTimestamp>("", 5);
283287
pImpl_->getConfigSrv().setCallback(boost::bind(&DeviceTimeTranslator::configCallback, this, _1, _2));
284288

285-
if(pImpl_->getExpectedAlgo() == FilterAlgorithm::ReceiveTimeOnly){
286-
ROS_WARN("Current %s/filterAlgo setting (=%u ~ ReceiveTimeOnly) causes the sensor's hardware clock to be ignore. Instead the receive time in the driver is used as timestamp.", nameSpace.toString().c_str(), unsigned(FilterAlgorithm::ReceiveTimeOnly));
289+
if(pImpl_->getExpectedAlgo() == FilterAlgorithm::ReceiveTimePassThrough){
290+
ROS_WARN("Current %s/filterAlgo setting (=%u ~ ReceiveTimePassThrough) causes the sensor's hardware clock to be ignore. Instead the receive time in the driver is used as translated timestamp.", nameSpace.toString().c_str(), unsigned(FilterAlgorithm::ReceiveTimePassThrough));
291+
}
292+
if(pImpl_->getExpectedAlgo() == FilterAlgorithm::DeviceTimePassThrough){
293+
ROS_WARN("Current %s/filterAlgo setting (=%u ~ DeviceTimePassThrough) causes the receive time to be ignore. Instead the device time is passed through as translated timestamp.", nameSpace.toString().c_str(), unsigned(FilterAlgorithm::DeviceTimePassThrough));
287294
}
288295
}
289296

cuckoo_time_translator/src/OwtFactory.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Defaults & Defaults::setFilterConfig(const KalmanOwtConfig& c) {
4949
}
5050

5151
template class OwtFactoryImpl<FilterAlgorithm::ConvexHull, ConvexHullOwt>;
52-
template class OwtFactoryImpl<FilterAlgorithm::ReceiveTimeOnly, NopOwt>;
52+
template class OwtFactoryImpl<FilterAlgorithm::ReceiveTimePassThrough, ReceiveTimePassThroughOwt>;
53+
template class OwtFactoryImpl<FilterAlgorithm::DeviceTimePassThrough, DeviceTimePassThroughOwt>;
5354

5455
}

cuckoo_time_translator/test/TestDeviceTimeTranslator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ TEST(DeviceTimeTranslator, DefaultDeviceTimeUnwrapperAndTranslatorWithTransmitTi
3030

3131
TEST(DeviceTimeTranslator, UnwrappedDeviceTimeTranslatorNoTranslation) {
3232
UnwrappedDeviceTimeTranslator translator({100.0}, "");
33-
translator.setFilterAlgorithm(FilterAlgorithm::ReceiveTimeOnly);
33+
translator.setFilterAlgorithm(FilterAlgorithm::ReceiveTimePassThrough);
3434
EXPECT_EQ(10.0, translator.update(100ul, ros::Time(10.0)).toSec());
3535
EXPECT_EQ(110.0, translator.update(1000ul, ros::Time(110.0)).toSec());
3636
EXPECT_EQ(120.0, translator.update(0ul, ros::Time(120.0)).toSec());

cuckoo_time_translator/test/TestDeviceTimeTranslatorNode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ TEST(DeviceTimeTranslator, ReceiveStamps) {
7777
for(auto & m : msgs){
7878
owt.updateAndTranslateToLocalTimestamp(RemoteTime(m.timePair.remote / MockCuckooDeviceDriver::kFreq), m.timePair.local);
7979
}
80-
EXPECT_NEAR(expectedOffset.toSec(), owt.getOffset(), 0.5);
80+
EXPECT_NEAR(expectedOffset.toSec(), owt.getOffset(), 0.8);
8181
EXPECT_NEAR(MockCuckooDeviceDriver::kSkew, owt.getSkew(), 0.01);
8282

83-
EXPECT_EQ(FilterAlgorithm::ReceiveTimeOnly, msgs.back().filterAlgo.type);
83+
EXPECT_EQ(FilterAlgorithm::ReceiveTimePassThrough, msgs.back().filterAlgo.type);
8484

8585
clear();
8686
ASSERT_EQ(msgs.size(), 0);

cuckoo_time_translator_algorithms/include/cuckoo_time_translator/OneWayTranslator.h

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,34 @@ class OneWayTranslator {
4141
virtual OneWayTranslator* cloneImpl() const = 0;
4242
};
4343

44+
45+
/**
46+
* The receive time pass through One Way Translator does ignore the device time and yields the receive time.
47+
* This implies that translateToLocalTimestamp is not implemented (throws) because no receive time is available.
48+
*/
49+
class ReceiveTimePassThroughOwt : public OneWayTranslator {
50+
public:
51+
virtual ~ReceiveTimePassThroughOwt();
52+
virtual LocalTime translateToLocalTimestamp(RemoteTime remoteTimeTics) const override;
53+
virtual LocalTime updateAndTranslateToLocalTimestamp(RemoteTime remoteTimeTics, LocalTime localTimeSecs) override;
54+
virtual bool isReadyToTranslate() const override;
55+
virtual void reset() override;
56+
57+
virtual void printNameAndConfig(std::ostream & o) const override;
58+
virtual void printState(std::ostream & o) const override;
59+
protected:
60+
virtual ReceiveTimePassThroughOwt* cloneImpl() const override;
61+
};
62+
63+
//TODO cleanup: remove all traces of NopOwt.
64+
typedef ReceiveTimePassThroughOwt NopOwt; // For backwards compatibility
65+
4466
/**
45-
* The No Operation One Way Translator does no translation at all.
46-
* I.e. it passes the receive time through.
67+
* The device time pass through One Way Translator does ignore the receive time and yields the device time.
4768
*/
48-
class NopOwt : public OneWayTranslator {
69+
class DeviceTimePassThroughOwt : public OneWayTranslator {
4970
public:
50-
virtual ~NopOwt();
71+
virtual ~DeviceTimePassThroughOwt();
5172
virtual LocalTime translateToLocalTimestamp(RemoteTime remoteTimeTics) const override;
5273
virtual LocalTime updateAndTranslateToLocalTimestamp(RemoteTime remoteTimeTics, LocalTime localTimeSecs) override;
5374
virtual bool isReadyToTranslate() const override;
@@ -56,9 +77,10 @@ class NopOwt : public OneWayTranslator {
5677
virtual void printNameAndConfig(std::ostream & o) const override;
5778
virtual void printState(std::ostream & o) const override;
5879
protected:
59-
virtual NopOwt* cloneImpl() const override;
80+
virtual DeviceTimePassThroughOwt* cloneImpl() const override;
6081
};
6182

83+
6284
} /* namespace cuckoo_time_translator */
6385

6486
#endif /* H3A613172_9ECF_45BC_8D47_C711DE333A50 */

cuckoo_time_translator_algorithms/src/OneWayTranslator.cpp

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,64 @@ std::unique_ptr<OneWayTranslator> OneWayTranslator::clone() const {
1818
return std::unique_ptr<OneWayTranslator>(cloneImpl());
1919
}
2020

21-
NopOwt::~NopOwt() {
21+
ReceiveTimePassThroughOwt::~ReceiveTimePassThroughOwt() {
2222
}
2323

24-
LocalTime NopOwt::translateToLocalTimestamp(RemoteTime /*remoteTimeTics*/) const {
25-
AASSERT(false, "translateToLocalTimestamp is not implemented in NopOwt!");
24+
LocalTime ReceiveTimePassThroughOwt::translateToLocalTimestamp(RemoteTime /*remoteTimeTics*/) const {
25+
AASSERT(false, "translateToLocalTimestamp is not implemented in ReceiveTimePassThroughOwt!");
2626
throw ""; // dummy;
2727
}
2828

29-
LocalTime NopOwt::updateAndTranslateToLocalTimestamp(RemoteTime /*remoteTimeTics*/, LocalTime localTimeSecs) {
29+
LocalTime ReceiveTimePassThroughOwt::updateAndTranslateToLocalTimestamp(RemoteTime /*remoteTimeTics*/, LocalTime localTimeSecs) {
3030
return localTimeSecs;
3131
}
3232

33-
bool NopOwt::isReadyToTranslate() const {
33+
bool ReceiveTimePassThroughOwt::isReadyToTranslate() const {
3434
return true;
3535
}
3636

37-
void NopOwt::printNameAndConfig(std::ostream& o) const {
38-
o << "NopOwt()";
37+
void ReceiveTimePassThroughOwt::printNameAndConfig(std::ostream& o) const {
38+
o << "ReceiveTimePassThroughOwt()";
3939
}
4040

41-
void NopOwt::printState(std::ostream& /*o*/) const {
41+
void ReceiveTimePassThroughOwt::printState(std::ostream& /*o*/) const {
4242
}
4343

44-
void NopOwt::reset() {
44+
void ReceiveTimePassThroughOwt::reset() {
4545
}
4646

47-
NopOwt* NopOwt::cloneImpl() const {
48-
return new NopOwt();
47+
ReceiveTimePassThroughOwt* ReceiveTimePassThroughOwt::cloneImpl() const {
48+
return new ReceiveTimePassThroughOwt();
4949
}
5050

51+
DeviceTimePassThroughOwt::~DeviceTimePassThroughOwt() {
52+
}
53+
54+
LocalTime DeviceTimePassThroughOwt::translateToLocalTimestamp(RemoteTime remoteTimeTics) const {
55+
return LocalTime(static_cast<double>(remoteTimeTics));
56+
}
57+
58+
LocalTime DeviceTimePassThroughOwt::updateAndTranslateToLocalTimestamp(RemoteTime /*remoteTimeTics*/, LocalTime localTimeSecs) {
59+
return localTimeSecs;
60+
}
61+
62+
bool DeviceTimePassThroughOwt::isReadyToTranslate() const {
63+
return true;
64+
}
65+
66+
void DeviceTimePassThroughOwt::printNameAndConfig(std::ostream& o) const {
67+
o << "DeviceTimePassThroughOwt()";
68+
}
69+
70+
void DeviceTimePassThroughOwt::printState(std::ostream& /*o*/) const {
71+
}
72+
73+
void DeviceTimePassThroughOwt::reset() {
74+
}
75+
76+
DeviceTimePassThroughOwt* DeviceTimePassThroughOwt::cloneImpl() const {
77+
return new DeviceTimePassThroughOwt();
78+
}
79+
80+
5181
} /* namespace cuckoo_time_translator */

cuckoo_time_translator_python/scripts/ctt_introspect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
if baselineOwt:
7171
base_times = np.array(baselineOwt.apply(ds.raw_hw_times, ds.receive_times))
72-
info("Baseline owt after translation: " + baselineOwt.getConfigAndStateString())
72+
info("Baseline OWT after translation: " + baselineOwt.getConfigAndStateString())
7373

7474
delaysToPlot = []
7575
labels = []

0 commit comments

Comments
 (0)