Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ on:
branches: [master]

jobs:
build_ros1:
uses: ros-misc-utilities/ros_build_scripts/.github/workflows/ros1_ci.yml@master
with:
repo: ${{ github.event.repository.name }}
vcs_url: https://raw.githubusercontent.com/${{ github.repository }}/master/${{ github.event.repository.name }}.repos
build_ros2:
uses: ros-misc-utilities/ros_build_scripts/.github/workflows/ros2_recent_ci.yml@master
with:
Expand Down
11 changes: 9 additions & 2 deletions include/event_camera_py/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
#include <event_camera_py/event_ext_trig.h>
#include <pybind11/numpy.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <string>
#include <tuple>
#include <variant>
#include <vector>

template <class A>
Expand Down Expand Up @@ -68,7 +70,7 @@ class Decoder
return (std::tuple<bool, uint64_t>({reachedTimeLimit, nextTime}));
}

std::tuple<bool, uint64_t> find_first_sensor_time(pybind11::object msg)
std::variant<uint64_t, pybind11::none> find_first_sensor_time(pybind11::object msg)
{
auto decoder = initialize_decoder(
get_attr<std::string>(msg, "encoding"), get_attr<uint32_t>(msg, "width"),
Expand All @@ -79,11 +81,16 @@ class Decoder
if (PyObject_GetBuffer(eventsObj.ptr(), &view, PyBUF_CONTIG_RO) != 0) {
throw std::runtime_error("cannot convert events to byte buffer");
}
decoder->setTimeBase(get_attr<uint64_t>(msg, "time_base"));
uint64_t firstTime{0};
const bool foundTime = decoder->findFirstSensorTime(
reinterpret_cast<const uint8_t *>(view.buf), view.len, &firstTime);
PyBuffer_Release(&view);
return (std::tuple<bool, uint64_t>({foundTime, firstTime}));
if (foundTime) {
return (firstTime);
} else {
return (pybind11::cast<pybind11::none>(Py_None));
}
}

void decode_bytes(
Expand Down
6 changes: 3 additions & 3 deletions src/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void declare_decoder(pybind11::module & m, std::string typestr)
:rtype: tuple[boolean, uint64_t]
)pbdoc")
.def("find_first_sensor_time", &MyDecoder::find_first_sensor_time, R"pbdoc(
find_first_sensor_time(msg) -> tuple[Boolean, uint64_t]
find_first_sensor_time(msg) -> uint64|None

Peeks into encoded message to find first event sensor time stamp. The
boolean return flag indicates whether any time stamp was detected.
Expand All @@ -105,8 +105,8 @@ void declare_decoder(pybind11::module & m, std::string typestr)

:param msg: event packet message to decode
:type msg: event_camera_msgs/msgs/EventPacket
:return: tuple with flag (true if event sensor time was found) and the sensor time
:rtype: tuple[boolean, uint64_t]
:return: sensor time
:rtype: uint64_t or None if not found
)pbdoc")
.def("get_start_time", &MyDecoder::get_start_time, R"pbdoc(
get_start_time() -> uint64
Expand Down
4 changes: 2 additions & 2 deletions tests/test_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ def test_find_first_sensor_time(verbose=True):
print('Testing find_first_time_stamp')
decoder = Decoder()
for _, msg, _ in bag.read_messages(topics=['/event_camera/events']):
found_ts, ts = decoder.find_first_sensor_time(msg)
assert found_ts
ts = decoder.find_first_sensor_time(msg)
assert ts is not None
if verbose:
print('first sensor time stamp: ', ts)
assert ts == 7139840
Expand Down