-
Notifications
You must be signed in to change notification settings - Fork 0
/
robot_time_python.cc
44 lines (38 loc) · 1.48 KB
/
robot_time_python.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iomanip>
#include <sstream>
#include "common/time/robot_time.hh"
#include "pybind11/chrono.h"
#include "pybind11/operators.h"
#include "pybind11/pybind11.h"
namespace py = pybind11;
namespace robot::time {
PYBIND11_MODULE(robot_time_python, m) {
m.doc() = "robot time";
m.def("current_robot_time", ¤t_robot_time);
m.def("as_duration", &as_duration);
py::class_<RobotTimestamp>(m, "RobotTimestamp")
.def(py::init<>())
.def("time_since_epoch", &RobotTimestamp::time_since_epoch)
.def_property_readonly_static("MIN", &RobotTimestamp::min)
.def_property_readonly_static("MAX", &RobotTimestamp::max)
.def(py::self - py::self)
.def(py::self - RobotTimestamp::duration())
.def(py::self + RobotTimestamp::duration())
.def(RobotTimestamp::duration() + py::self)
.def(RobotTimestamp::duration() - py::self)
.def(py::self -= RobotTimestamp::duration())
.def(py::self += RobotTimestamp::duration())
.def(py::self == py::self)
.def(py::self != py::self)
.def(py::self < py::self)
.def(py::self > py::self)
.def(py::self <= py::self)
.def(py::self >= py::self)
.def("__repr__", [](const RobotTimestamp &time) {
std::ostringstream ss;
ss << std::fixed << std::setprecision(9)
<< std::chrono::duration<double>(time.time_since_epoch()).count();
return ss.str();
});
}
} // namespace robot::time