Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

atis-yarp-bridge optional throughput limit #175

Merged
merged 1 commit into from
Aug 9, 2023
Merged
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
13 changes: 11 additions & 2 deletions cpp_tools/atis3-bridge/atis-bridge-sdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class atis3Bridge : public RFModule, public Thread {
int buffer_size{0};
int buffer_used{0};
int b_sel{0};
double limit{-1};
static constexpr void switch_buffer(int &buf_i) {buf_i = (buf_i + 1) % 2;};

public:
Expand All @@ -76,6 +77,7 @@ class atis3Bridge : public RFModule, public Thread {
yInfo() << "--name <str>\t: internal port name prefix";
yInfo() << "--buffer_size <int>\t: set initial maximum buffer size";
yInfo() << "--file <str>\t: (optional) provide file path otherwise search for camera to connect";
yInfo() << "--limit <int>\t: (optional) provide a hard limit on event rate (in 10^6 events/s)";
return false;
}

Expand Down Expand Up @@ -115,6 +117,10 @@ class atis3Bridge : public RFModule, public Thread {
record_mode = rf.check("record_mode") &&
rf.check("record_mode", Value(true)).asBool();

limit = rf.check("limit", Value(-1)).asFloat64();
if(limit < 0) limit = DBL_MAX;
else limit *= 1e6;

//yarp::os::Network::connect(getName("/AE:o"), "/vPreProcess/AE:i", "fast_tcp");

buffer.emplace_back();
Expand Down Expand Up @@ -289,8 +295,11 @@ class atis3Bridge : public RFModule, public Thread {
current_buffer.duration(yarp::os::Time::now() - tic);
tic += current_buffer.duration();
yarpstamp.update();
output_port.setEnvelope(yarpstamp);
output_port.write(current_buffer);
if(current_buffer.size() / current_buffer.duration() < limit)
{
output_port.setEnvelope(yarpstamp);
output_port.write(current_buffer);
}
counter_packets++;
counter_events += current_buffer.size();
current_buffer.clear();
Expand Down