forked from cocomr/coco
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d40a74
commit c395481
Showing
10 changed files
with
259 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<package> | ||
<log> | ||
<levels>0 1 2 3 4</levels> | ||
<types>debug err log</types> | ||
</log> | ||
<paths> | ||
<path>/home/pippo/Libraries/coco/build/lib/</path> | ||
<path>/home/pippo/Libraries/coco/samples</path> | ||
</paths> | ||
<components> | ||
<component> | ||
<task>TaskLatStart</task> | ||
<library>component_latency</library> | ||
<attributes> | ||
<attribute name="sleep_time" value="10" /> | ||
</attributes> | ||
</component> | ||
<component> | ||
<task>TaskLatMiddle</task> | ||
<name>middle_1</name> | ||
<library>component_latency</library> | ||
<attributes> | ||
<attribute name="sleep_time" value="100" /> | ||
</attributes> | ||
</component> | ||
<component> | ||
<task>TaskLatMiddle</task> | ||
<name>middle_2</name> | ||
<library>component_latency</library> | ||
<attributes> | ||
<attribute name="sleep_time" value="100" /> | ||
</attributes> | ||
</component> | ||
<component> | ||
<task>TaskLatMiddle</task> | ||
<name>middle_3</name> | ||
<library>component_latency</library> | ||
<attributes> | ||
<attribute name="sleep_time" value="100" /> | ||
</attributes> | ||
</component> | ||
<component> | ||
<task>TaskLatSink</task> | ||
<library>component_latency</library> | ||
<attributes> | ||
<attribute name="sleep_time" value="100" /> | ||
</attributes> | ||
</component> | ||
</components> | ||
|
||
<activities> | ||
<activity> | ||
<schedule activity="parallel" type="periodic" period="50"/> | ||
<components> | ||
<component name="TaskLatStart" /> | ||
</components> | ||
</activity> | ||
<activity> | ||
<schedule activity="parallel" type="triggered"/> | ||
<components> | ||
<component name="middle_1" /> | ||
</components> | ||
</activity> | ||
<activity> | ||
<schedule activity="parallel" type="triggered"/> | ||
<components> | ||
<component name="middle_2" /> | ||
</components> | ||
</activity> | ||
<activity> | ||
<schedule activity="parallel" type="triggered"/> | ||
<components> | ||
<component name="middle_3" /> | ||
</components> | ||
</activity> | ||
<activity> | ||
<schedule activity="parallel" type="triggered"/> | ||
<components> | ||
<component name="TaskLatSink" /> | ||
</components> | ||
</activity> | ||
</activities> | ||
|
||
<connections> | ||
<connection data="DATA" policy="LOCKED" transport="LOCAL" buffersize="10"> | ||
<src task="TaskLatStart" port="time_OUT"/> | ||
<dest task="middle_1" port="time_IN"/> | ||
</connection> | ||
<connection data="DATA" policy="LOCKED" transport="LOCAL" buffersize="1"> | ||
<src task="middle_1" port="time_OUT"/> | ||
<dest task="middle_2" port="time_IN"/> | ||
</connection> | ||
<connection data="DATA" policy="LOCKED" transport="LOCAL" buffersize="1"> | ||
<src task="middle_2" port="time_OUT"/> | ||
<dest task="middle_3" port="time_IN"/> | ||
</connection> | ||
<connection data="DATA" policy="LOCKED" transport="LOCAL" buffersize="1"> | ||
<src task="middle_3" port="time_OUT"/> | ||
<dest task="TaskLatSink" port="time_IN"/> | ||
</connection> | ||
</connections> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include <chrono> | ||
#include <thread> | ||
#include <coco/coco.h> | ||
|
||
class TaskLatStart : public coco::TaskContext | ||
{ | ||
public: | ||
coco::OutputPort<double> out_time_ = {this, "time_OUT"}; | ||
coco::Attribute<int long> asleep_time_ = {this, "sleep_time", sleep_time_}; | ||
|
||
void init() {} | ||
void onConfig() {} | ||
|
||
void onUpdate() | ||
{ | ||
auto time = coco::util::time(); | ||
std::this_thread::sleep_for(std::chrono::milliseconds(sleep_time_)); | ||
|
||
out_time_.write(time); | ||
} | ||
private: | ||
int long sleep_time_ = 10; | ||
}; | ||
|
||
COCO_REGISTER(TaskLatStart) | ||
|
||
class TaskLatMiddle : public coco::TaskContext | ||
{ | ||
public: | ||
coco::InputPort<double> in_time_ = {this, "time_IN", true}; | ||
coco::OutputPort<double> out_time_ = {this, "time_OUT"}; | ||
|
||
coco::Attribute<int long> asleep_time_ = {this, "sleep_time", sleep_time_}; | ||
|
||
void init() {} | ||
void onConfig() {} | ||
|
||
void onUpdate() | ||
{ | ||
//if (this->instantiationName() == "middle_2") | ||
std::cout << "Executing start" << std::endl; | ||
double time; | ||
in_time_.read(time); | ||
std::this_thread::sleep_for(std::chrono::milliseconds(sleep_time_)); | ||
|
||
out_time_.write(time); | ||
|
||
//if (this->instantiationName() == "middle_2") | ||
std::cout << "Executing end" << std::endl; | ||
} | ||
private: | ||
int long sleep_time_ = 10; | ||
}; | ||
|
||
COCO_REGISTER(TaskLatMiddle) | ||
|
||
|
||
class TaskLatSink : public coco::TaskContext | ||
{ | ||
public: | ||
coco::InputPort<double> in_time_ = {this, "time_IN", true}; | ||
coco::OutputPort<double> out_time_ = {this, "time_OUT"}; | ||
coco::Attribute<int long> asleep_time_ = {this, "sleep_time", sleep_time_}; | ||
|
||
void init() {} | ||
void onConfig() {} | ||
|
||
void onUpdate() | ||
{ | ||
double time; | ||
in_time_.read(time); | ||
|
||
std::this_thread::sleep_for(std::chrono::milliseconds(sleep_time_)); | ||
|
||
times_.push_back(coco::util::time() - time); | ||
out_time_.write(time); | ||
|
||
static int count = 1; | ||
if (count++ % 10 == 0) | ||
{ | ||
double sum = std::accumulate(times_.begin(), times_.end(), 0); | ||
COCO_LOG(1) << "Latency: " << sum / times_.size(); | ||
} | ||
} | ||
private: | ||
std::vector<double> times_; | ||
int long sleep_time_ = 10; | ||
}; | ||
|
||
COCO_REGISTER(TaskLatSink) |