Skip to content

Commit e0877ea

Browse files
authored
Merge pull request #43 from ethz-asl/cleanup/overall
Cleanup/overall
2 parents 76b8e96 + 4a80c21 commit e0877ea

File tree

17 files changed

+151
-132
lines changed

17 files changed

+151
-132
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,21 @@ Howevere, this step is beyond this repository. If you need that the following re
2020
* [ethz-asl/kalibr](https://github.com/ethz-asl/kalibr/)
2121
* [ethz-asl/oomact](https://github.com/ethz-asl/oomact/)
2222

23+
2324
### Why call it translation rather than synchronization?
2425
Because **synchronization** refers to what one does to clocks to make them run at the same speed and yield similar times when read at the same time (as for instance NTP and PTP do to computer clocks), whereas the algorithms in this repository are trying to only **translate** the time of one clock for a given event into the another clock's time for the *same* event and not touch the clocks at all.
2526

2627

28+
### Dependencies
29+
* [caktin_simple](https://github.com/catkin/catkin_simple)
30+
* ros-*-cmake-modules
31+
* ros-*-rosconsole-bridge
32+
* ros-*-dynamic-reconfigure
33+
34+
2735
### Examples for how to use it in a ROS sensor driver:
2836
See [usage examples](https://github.com/ethz-asl/cuckoo_time_translator/wiki#usage-examples-ros-sensor-drivers).
2937

3038

31-
3239
## Acknowledgments
3340
This work is supported in part by the European Union's Seventh Framework Programme (FP7/2007-2013) under grant #610603 (EUROPA2) and the European Union's Horizon 2020 research and innovation programme under grant agreement No 644227 (FLOURISH).

cuckoo_time_translator/test/TestDefaults.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ TEST(Defaults, KalmanDefaults) {
1515
ASSERT_TRUE(k);
1616

1717
KalmanOwtConfig kc;
18-
EXPECT_EQ(kc.updateRate, k->getConfig().updateRate);
18+
EXPECT_EQ(kc.updateCooldownSecs, k->getConfig().updateCooldownSecs);
1919

20-
kc.updateRate += 1.0;
20+
kc.updateCooldownSecs += 1.0;
2121

2222
d.setFilterConfig(kc);
2323

@@ -26,5 +26,5 @@ TEST(Defaults, KalmanDefaults) {
2626
k = dynamic_cast<KalmanOwt*>(uk.get());
2727
ASSERT_TRUE(k);
2828

29-
EXPECT_EQ(kc.updateRate, k->getConfig().updateRate);
29+
EXPECT_EQ(kc.updateCooldownSecs, k->getConfig().updateCooldownSecs);
3030
}

cuckoo_time_translator_algorithms/include/cuckoo_time_translator/KalmanOwt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct KalmanOwtConfig {
1515
double sigmaInitSkew = 1e-3;
1616
double sigmaOffset = 2e-3;
1717
double sigmaSkew = 2e-6;
18-
double updateRate = 0.5;
18+
double updateCooldownSecs = 0.5;
1919
double outlierThreshold = 1.0;
2020
};
2121

@@ -51,7 +51,7 @@ class KalmanOwt : public OneWayTranslator
5151
Eigen::Matrix<double, 1, 2> H_;
5252
bool isInitialized_;
5353
double lastUpdateDeviceTime_;
54-
double dt_;
54+
double lastUpdateDt_;
5555
};
5656

5757
}

cuckoo_time_translator_algorithms/src/KalmanOwt.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ KalmanOwt::KalmanOwt(Config config) :
1212
R_ (0),
1313
isInitialized_(false),
1414
lastUpdateDeviceTime_(0),
15-
dt_(0)
15+
lastUpdateDt_(0)
1616
{
1717
}
1818

@@ -27,7 +27,7 @@ LocalTime KalmanOwt::translateToLocalTimestamp(const RemoteTime remoteTimeTics)
2727

2828
void KalmanOwt::printNameAndConfig(std::ostream & out) const {
2929
out << "Kalman("
30-
<< "updateRate=" << config.updateRate
30+
<< "updateCooldownSecs=" << config.updateCooldownSecs
3131
<< ", "
3232
<< "sigmaSkew=" << config.sigmaSkew
3333
<< ", "
@@ -41,7 +41,7 @@ void KalmanOwt::printNameAndConfig(std::ostream & out) const {
4141
<< ")";
4242
}
4343
void KalmanOwt::printState(std::ostream & out) const {
44-
out << "offset=" << std::fixed << x_(0) << ", skew=" << x_(1) << ", dt=" << dt_;
44+
out << "offset=" << std::fixed << x_(0) << ", skew=" << x_(1) << ", dt=" << lastUpdateDt_;
4545
}
4646

4747
void KalmanOwt::reset() {
@@ -56,15 +56,16 @@ LocalTime KalmanOwt::updateAndTranslateToLocalTimestamp(const RemoteTime remoteT
5656

5757
const double dt = remoteTimeTics - lastUpdateDeviceTime_;
5858

59-
if(dt >= config.updateRate){
60-
dt_=dt;
61-
Eigen::Matrix2d F;
62-
F << 1, dt_, 0, 1;
59+
if(dt >= config.updateCooldownSecs){
60+
// Save some values for later usage
61+
lastUpdateDeviceTime_ = remoteTimeTics;
62+
lastUpdateDt_ = dt;
6363

6464
// Prediction
65+
Eigen::Matrix2d F;
66+
F << 1, dt, 0, 1;
6567
x_ = F * x_;
66-
P_ = F * P_ * F.transpose() + dt_ * Q_;
67-
lastUpdateDeviceTime_ = remoteTimeTics;
68+
P_ = F * P_ * F.transpose() + dt * Q_;
6869

6970
// Update
7071
const double S = H_ * P_ * H_.transpose() + R_;

cuckoo_time_translator_python/CMakeLists.txt

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,33 @@ find_package(Boost REQUIRED COMPONENTS python)
2929
include_directories(${PYTHON_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
3030

3131
catkin_python_setup()
32+
3233
cs_add_library(${PROJECT_NAME}
3334
src/module.cpp
3435
)
36+
3537
string(REGEX REPLACE "_python$" "" LIB_OUTPUT_DIR ${CATKIN_PACKAGE_PYTHON_DESTINATION})
36-
set_target_properties(${PROJECT_NAME}
37-
PROPERTIES
38-
LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${LIB_OUTPUT_DIR}
38+
set_target_properties(${PROJECT_NAME} PROPERTIES
39+
LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${LIB_OUTPUT_DIR}
3940
)
4041

4142
if (APPLE)
42-
set_target_properties(${PROJECT_NAME}
43-
PROPERTIES
44-
SUFFIX ".so" # This is apparently needed for Darvin. But why?
45-
)
43+
set_target_properties(${PROJECT_NAME} PROPERTIES
44+
SUFFIX ".so" # This is apparently needed for Darvin. But why
45+
)
4646
endif ()
4747

4848
target_link_libraries(${PROJECT_NAME} ${PYTHON_LIBRARY} ${Boost_LIBRARIES})
4949

50-
cs_install()
50+
install(FILES ${CATKIN_DEVEL_PREFIX}/${LIB_OUTPUT_DIR}/lib${PROJECT_NAME}.so
51+
DESTINATION ${LIB_OUTPUT_DIR}
52+
)
53+
5154
cs_export()
5255

5356
if(CATKIN_ENABLE_TESTING)
54-
catkin_add_nosetests(
55-
test/Test.py
56-
DEPENDENCIES ${PROJECT_NAME}
57-
)
57+
catkin_add_nosetests(
58+
test/Test.py
59+
DEPENDENCIES ${PROJECT_NAME}
60+
)
5861
endif()
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
from libcuckoo_time_translator_python import *
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .libcuckoo_time_translator_python import *

cuckoo_time_translator_python/python/cuckoo_time_translator/batch_algo.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,26 @@
33
import numpy as np
44
import sys
55

6+
67
def chunks(l, n):
78
"""Yield successive n-sized chunks from l."""
89
for i in range(0, len(l), n):
910
yield l[i:i + n]
1011

11-
def printDelayStat(delays, name, outlierLimit = None, file = None, chunkSizes = ()):
12+
13+
def printDelayStat(delays, name, outlierLimit=None, file=None, chunkSizes=()):
1214
if delays is not None and len(delays):
1315
if outlierLimit:
1416
delays = delays[delays < outlierLimit]
15-
16-
delays = np.array(delays) * 1e3 # convert to ms
17-
17+
18+
delays = np.array(delays) * 1e3 # convert to ms
19+
1820
files = [sys.stdout]
1921
if file: files.append(file)
2022
for f in files:
21-
print("%s: mean=%f ms, std=%f ms" % (name, np.mean(delays), np.std(delays)), file = f)
23+
print("%s: mean=%f ms, std=%f ms" % (name, np.mean(delays), np.std(delays)), file=f)
2224
for n in chunkSizes:
23-
print("std(%s over %d chunks) = %g ms" %(name, n, np.std([ np.mean(c) for c in chunks(delays, n)])), file = f)
25+
print("std(%s over %d chunks) = %g ms" % (name, n, np.std([ np.mean(c) for c in chunks(delays, n)])), file=f)
2426

2527
else :
2628
print("No %s data!" % name)

cuckoo_time_translator_python/python/cuckoo_time_translator/device_time_bags.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from __future__ import print_function
2-
31
import os
4-
import sys
52

63
import pickle
74
import rosbag
@@ -12,6 +9,7 @@
129

1310
DefaultTopic = '/device_time'
1411

12+
1513
def guessTopics(bagFile):
1614
with rosbag.Bag(bagFile) as bag:
1715
found = []
@@ -21,8 +19,10 @@ def guessTopics(bagFile):
2119

2220
return found
2321

22+
2423
class DeviceTimeStream():
25-
def __init__(self, bagFile, topic, invalidate = False):
24+
25+
def __init__(self, bagFile, topic, invalidate=False):
2626
eventsFile = os.path.realpath(bagFile) + topic.replace("/", "_") + ".p"
2727
if os.path.exists(eventsFile):
2828
if invalidate:
@@ -31,14 +31,14 @@ def __init__(self, bagFile, topic, invalidate = False):
3131
verbose("Loading from " + eventsFile)
3232
self.__dict__ = pickle.load(open(eventsFile, "rb"))
3333
return
34-
34+
3535
bag = rosbag.Bag(bagFile)
3636

37-
self.filtered_hw_times = TimestampSeries()
37+
self.translated_hw_times = TimestampSeries()
3838
self.receive_times = TimestampSeries()
3939
self.raw_hw_times = TimestampSeries()
4040
for topic, msg, t in bag.read_messages(topics=[topic]):
41-
self.filtered_hw_times.append(msg.header.stamp.to_sec())
41+
self.translated_hw_times.append(msg.header.stamp.to_sec())
4242
self.receive_times.append(msg.receive_time.to_sec())
4343
self.raw_hw_times.append(float(msg.event_stamp))
4444

cuckoo_time_translator_python/python/cuckoo_time_translator/plotting.py

100755100644
Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from __future__ import print_function
44

5-
import sys
65
import os
76
import numpy as np
87
import matplotlib
@@ -11,10 +10,12 @@
1110

1211
from tools import *
1312

14-
def show(block = True):
13+
14+
def show(block=True):
1515
plt.show(block)
1616

17-
def save(fig, legend, fileName, fileFormat = 'pdf', overwrite = False):
17+
18+
def save(fig, legend, fileName, fileFormat='pdf', overwrite=False):
1819
fullFileName = fileName + '.' + fileFormat if not fileName.endswith(fileFormat) else fileName
1920
if not overwrite and os.path.exists(fullFileName):
2021
warn("Output file %s exists already! Not overwriting!" % fullFileName)
@@ -24,19 +25,19 @@ def save(fig, legend, fileName, fileFormat = 'pdf', overwrite = False):
2425
extra = ()
2526
if legend:
2627
extra = (legend,)
27-
28+
2829
fig.savefig(fullFileName, bbox_inches='tight', format=fileFormat)
2930

3031

31-
def plotMultiDelays(x, delays, xLabel, labels = None, title = None, markersize = 1.5, fileName = None, overwrite = None, colors = None, block = False, show = False):
32+
def plotMultiDelays(x, delays, xLabel, labels=None, title=None, markersize=1.5, fileName=None, overwrite=None, colors=None, block=False, show=False):
3233
if not colors:
3334
defaultColors = ['r', 'g', 'b']
3435
colors = list(reversed(defaultColors[:len(delays)]))
35-
36+
3637
yLabel = "offset [msec]"
37-
38+
3839
import matplotlib.gridspec as gridspec
39-
40+
4041
figsize = (5, 2.5)
4142

4243
breakX = False
@@ -47,28 +48,27 @@ def plotMyDelays(ax):
4748
if labels:
4849
for i, (d, l) in enumerate(zip(delays, labels)):
4950
assert(len(xA) == len(d))
50-
ax.plot(xA, np.asarray(d) * 1000, linestyle='-', marker='.', markersize= markersize, label = l, color = colors[i])
51+
ax.plot(xA, np.asarray(d) * 1000, linestyle='-', marker='.', markersize=markersize, label=l, color=colors[i])
5152
else:
5253
for i, d in enumerate(delays):
5354
assert(len(xA) == len(d))
54-
ax.plot(xA, np.asarray(d) * 1000, linestyle='-', marker='.', markersize= markersize, color = colors[i])
55+
ax.plot(xA, np.asarray(d) * 1000, linestyle='-', marker='.', markersize=markersize, color=colors[i])
5556

56-
fig, ax = plt.subplots(1, 1, figsize= figsize)
57+
fig, ax = plt.subplots(1, 1, figsize=figsize)
5758
plotMyDelays(ax)
5859
ax.set_xlabel(xLabel)
5960
ax.set_ylabel(yLabel)
6061

6162
if title:
6263
ax.set_title(title)
63-
64+
6465
legend = None
6566
if labels:
6667
legend = ax.legend(loc='upper right', shadow=False)
6768

68-
6969
if fileName:
70-
save(fig, legend, fileName, overwrite = overwrite)
71-
70+
save(fig, legend, fileName, overwrite=overwrite)
71+
7272
if show:
7373
show(block)
7474
return fig

0 commit comments

Comments
 (0)