diff --git a/C/Distributed/src/PingPongDistributed.lf b/C/Distributed/src/PingPongDistributed.lf deleted file mode 100644 index cfdfe38..0000000 --- a/C/Distributed/src/PingPongDistributed.lf +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Basic benchmark from the Savina benchmark suite that is intended to measure message-passing - * overhead. This version is distributed, communicating using physical connections over sockets. See - * [Benchmarks wiki page](https://github.com/icyphy/lingua-franca/wiki/Benchmarks). - * - * This is based on https://www.scala-lang.org/old/node/54 See - * https://shamsimam.github.io/papers/2014-agere-savina.pdf. - * - * This is a distributed version, where Ping and Pong run in separate programs and can be run on - * different machines. - * - * There is no parallelism in this application, so it does not benefit from being being distributed. - * - * These measurements are total execution time, including startup and shutdown, of all three - * programs. - * - * @author Edward A. Lee - */ -target C - -import Ping, Pong from "../../Savina/src/micro/PingPong.lf" - -federated reactor(count: int = 10000000) { - ping = new Ping(count=count) - pong = new Pong(expected=count) - ping.send -> pong.receive - pong.send -> ping.receive -} diff --git a/C/Distributed/src/RESULTS.md b/C/Distributed/src/RESULTS.md deleted file mode 100644 index 0e557f6..0000000 --- a/C/Distributed/src/RESULTS.md +++ /dev/null @@ -1,20 +0,0 @@ -## Benchmark results -### Lingua Franca -#### TimeLimitDistributedDecentralized.lf -A simple benchmark with a source reactor called Clock that periodically (with a period of 1us) sends an integer (that is incremented each time) to a Destination reactor. The benchmark will end by federates calling stop after 10 seconds has passed in logical time. At the end, the elapsed physical time is divided by the number of messages received to get an approximated time spent per reaction. - - Approx. time per reaction: 5428n -#### TimeLimitDistributedDecentralizedClockSync.lf -This benchmark is a variant of `TimeLimitDistributedDecentralized.lf` that enables clock synchronization. - - Approx. time per reaction: 5511ns -#### TimeLimitDistributedPhysical.lf -This benchmark is a variant of `TimeLimitDistributedDecentralized.lf` that uses physical connections between Clock and Destination. - - Approx. time per reaction: 3132ns -#### TimeLimitROS.lf -This benchmark uses ROS to communicate between Clock and Destination (non-federated, not threaded) - - 100 usec period spin timer: Approx. time per reaction: 43654997ns Dropped messages: 570924 - - 10 usec period spin timer: Approx. time per reaction: 43446746ns Dropped messages: 573300 - - 1 usec period spin timer: Approx. time per reaction: 44510507ns Dropped messages: 564984 -### ROS -#### TimeLimitROSNative -The TimeLimit benchmark (see [TimeLimitDistributedDecentralized.lf](#TimeLimitDistributedDecentralized.lf)) implemented in pure ROS. There is a 10 second timeout in physical time for both the Clock and Dest nodes. An approximated time per message received is printed when the benchmark ends. - - Approx. time per message: 66884ns Dropped messages: 0 diff --git a/C/Distributed/src/TimeLimitDistributed.lf b/C/Distributed/src/TimeLimitDistributed.lf deleted file mode 100644 index b8e770c..0000000 --- a/C/Distributed/src/TimeLimitDistributed.lf +++ /dev/null @@ -1,51 +0,0 @@ -// This is used to test the performance of the federated runtime (number of reactions per second). -// See [Benchmarks wiki page](https://github.com/icyphy/lingua-franca/wiki/Benchmarks). -// Correct output for this 1, 2, 3, 4. -// Failure for this test is failing to halt or getting the wrong data. -// On a 2.6 GHz Intel Core i7 running MacOS Mojave, using a single core, -// this executes 10,000,000 cycles (two reactions in each cycle) in 0.6 seconds, -// for over 32 million reactions per second. -// This translates to 31 nanoseconds per reaction invocation. -target C { - coordination: centralized, - timeout: 10 secs -} - -reactor Clock(offset: time = 0, period: time = 1 sec) { - output y: int - timer t(offset, period) - state count: int = 0 - - reaction(t) -> y {= - (self->count)++; - lf_set(y, self->count); - =} -} - -reactor Destination { - input x: int - state s: int = 1 - - reaction(x) {= - // printf("%d\n", x->value); - if (x->value != self->s) { - printf("Error: Expected %d and got %d.\n", self->s, x->value); - exit(1); - } - self->s++; - =} - - reaction(shutdown) {= - lf_print("**** shutdown reaction invoked."); - if (self->s != 10000002) { - lf_print_warning("Expected 10000002 but got %d.", self->s); - } - lf_print("Approx. time per reaction: " PRINTF_TIME " ns", lf_time_physical_elapsed()/(self->s+1)); - =} -} - -federated reactor TimeLimitDistributed(period: time = 700 usec) { - c = new Clock(period=period) - d = new Destination() - c.y -> d.x -} diff --git a/C/Distributed/src/TimeLimitDistributedDecentralized.lf b/C/Distributed/src/TimeLimitDistributedDecentralized.lf deleted file mode 100644 index 15ae881..0000000 --- a/C/Distributed/src/TimeLimitDistributedDecentralized.lf +++ /dev/null @@ -1,47 +0,0 @@ -// This is used to test the performance of the federated runtime in decentralized mode -// (number of reactions per second). -// See [Benchmarks wiki page](https://github.com/icyphy/lingua-franca/wiki/Benchmarks). -// Correct output for this 1, 2, 3, 4. -// Failure for this test is failing to halt or getting the wrong data. -target C { - coordination: decentralized, - timeout: 4 sec -} - -reactor Clock(offset: time = 0, period: time = 1 sec) { - output y: int - timer t(0, period) - state count: int = 0 - - reaction(t) -> y {= - (self->count)++; - lf_set(y, self->count); - =} -} - -reactor Destination { - input x: int - state s: int = 1 - - reaction(x) {= - // lf_print("%d", x->value); - if (x->value != self->s) { - lf_print_warning("Expected %d and got %d.", self->s, x->value); - } - self->s++; - =} - - reaction(shutdown) {= - lf_print("**** shutdown reaction invoked."); - if (self->s != 10000002) { - lf_print_warning("Expected 10000002 but got %d.", self->s); - } - lf_print("Approx. time per reaction: " PRINTF_TIME " ns", lf_time_physical_elapsed()/(self->s+1)); - =} -} - -federated reactor(period: time = 3 usec) { - c = new Clock(period=period) - d = new Destination() - c.y -> d.x after period -} diff --git a/C/Distributed/src/TimeLimitDistributedDecentralized2.lf b/C/Distributed/src/TimeLimitDistributedDecentralized2.lf deleted file mode 100644 index 7f673d3..0000000 --- a/C/Distributed/src/TimeLimitDistributedDecentralized2.lf +++ /dev/null @@ -1,55 +0,0 @@ -// This is used to test the performance of the federated runtime in decentralized mode -// (number of reactions per second). -// In this test, the Source reactor sends a large number of messages one -// microstep apart (so that there is no waiting for physical time to elapse, -// which would distort the statistics). -target C { - coordination: decentralized, - timeout: 1 sec -} - -reactor Source(num_messages: int = 10) { - output y: int - logical action a - state count: int = 0 - - reaction(startup, a) -> y {= - (self->count)++; - if (self->count < self->num_messages) { - tag_t tag = lf_tag(); - lf_print("Source sending %d at tag " PRINTF_TAG, - self->count, - tag.time - lf_time_start(), tag.microstep - ); - lf_set(y, self->count); - lf_schedule(a, 0); - } - =} -} - -reactor Destination(num_messages: int = 10) { - input x: int - state s: int = 1 - - reaction(x) {= - lf_print("Destination received: %d", x->value); - if (x->value != self->s) { - lf_print_error_and_exit("Expected %d and got %d.", self->s, x->value); - } - self->s++; - =} - - reaction(shutdown) {= - lf_print("**** shutdown reaction invoked."); - if (self->s != self->num_messages) { - lf_print_error_and_exit("Expected %d but got %d.", self->num_messages, self->s); - } - lf_print("Approximate time per reaction: " PRINTF_TIME " ns", lf_time_physical_elapsed()/(self->s+1)); - =} -} - -federated reactor(period: time = 1 usec) { - c = new Source() - d = new Destination() - c.y -> d.x after 1 usec -} diff --git a/C/Distributed/src/TimeLimitDistributedDecentralizedClockSync.lf b/C/Distributed/src/TimeLimitDistributedDecentralizedClockSync.lf deleted file mode 100644 index d1f4d47..0000000 --- a/C/Distributed/src/TimeLimitDistributedDecentralizedClockSync.lf +++ /dev/null @@ -1,61 +0,0 @@ -// This is used to test the performance of the federated runtime in decentralized mode -// with clock synchronization enabled at runtime (number of reactions per second). -// See [Benchmarks wiki page](https://github.com/icyphy/lingua-franca/wiki/Benchmarks). -// Correct output for this 1, 2, 3, 4. -// Failure for this test is failing to halt or getting the wrong data. -target C { - coordination: decentralized, - timeout: 10 secs, - clock-sync: on, // Turn on runtime clock synchronization. - clock-sync-options: { - local-federates-on: true, // Forces all federates to perform clock sync. - collect-stats: true, // Collect useful statistics like average network delay - // and the standard deviation for the network delay over - // one clock synchronization cycle. Generates a warning - // if the standard deviation is higher than the clock sync - // guard. - // Artificially offsets clocks by multiples of 200 msec. - test-offset: 200 msec, - period: 5 msec, // Period with which runtime clock sync is performed. - trials: 10, // Number of messages exchanged to perform clock sync. - attenuation: 10 // Attenuation applied to runtime clock sync adjustments. - } -} - -reactor Clock(offset: time = 0, period: time = 1 sec) { - output y: int - timer t(offset, period) - state count: int = 0 - - reaction(t) -> y {= - (self->count)++; - lf_set(y, self->count); - =} -} - -reactor Destination { - input x: int - state s: int = 1 - - reaction(x) {= - // printf("%d\n", x->value); - if (x->value != self->s) { - lf_print_warning("Expected %d and got %d.", self->s, x->value); - } - self->s++; - =} - - reaction(shutdown) {= - lf_print("**** shutdown reaction invoked."); - if (self->s != 10000002) { - lf_print_warning("Expected 10000002 but got %d.", self->s); - } - lf_print("Approx. time per reaction: " PRINTF_TIME " ns", lf_time_physical_elapsed()/(self->s+1)); - =} -} - -federated reactor(period: time = 1 usec) { - c = new Clock(period=period) - d = new Destination() - c.y -> d.x after 1 usec -} diff --git a/C/Distributed/src/TimeLimitDistributedPhysical.lf b/C/Distributed/src/TimeLimitDistributedPhysical.lf deleted file mode 100644 index 1a251ea..0000000 --- a/C/Distributed/src/TimeLimitDistributedPhysical.lf +++ /dev/null @@ -1,47 +0,0 @@ -// This is used to test the performance of the federated runtime in decentralized mode -// using physical connections (number of reactions per second). -// See [Benchmarks wiki page](https://github.com/icyphy/lingua-franca/wiki/Benchmarks). -// Correct output for this 1, 2, 3, 4. -// Failure for this test is failing to halt or getting the wrong data. -target C { - coordination: decentralized, - timeout: 10 secs -} - -reactor Clock(offset: time = 0, period: time = 1 sec) { - output y: int - timer t(offset, period) - state count: int = 0 - - reaction(t) -> y {= - (self->count)++; - lf_set(y, self->count); - =} -} - -reactor Destination { - input x: int - state s: int = 1 - - reaction(x) {= - // printf("%d\n", x->value); - if (x->value != self->s) { - lf_print_warning("Expected %d and got %d.", self->s, x->value); - } - self->s++; - =} - - reaction(shutdown) {= - lf_print("**** shutdown reaction invoked."); - if (self->s != 10000002) { - lf_print_warning("Expected 10000002 but got %d.", self->s); - } - lf_print("Approx. time per reaction: %lldns", lf_time_physical_elapsed()/(self->s+1)); - =} -} - -federated reactor TimeLimitDistributedPhysical(period: time = 1 usec) { - c = new Clock(period=period) - d = new Destination() - c.y ~> d.x -} diff --git a/C/Distributed/src/TimeLimitDistributedROSSerialization.lf b/C/Distributed/src/TimeLimitDistributedROSSerialization.lf deleted file mode 100644 index d136c00..0000000 --- a/C/Distributed/src/TimeLimitDistributedROSSerialization.lf +++ /dev/null @@ -1,64 +0,0 @@ -/** - * This is used to test the performance of the federated runtime in decentralized mode (number of - * reactions per second) when message types are ROS2 messages. The rclcpp serialization framework is - * used to serialize and deserialize messages. - * - * Failure for this benchmark is failing to halt or getting the wrong data. - * - * Note: the terminal must be properly sourced for ROS2. See - * https://docs.ros.org/en/foxy/Tutorials/Configuring-ROS2-Environment.html. - */ -target CCpp { - coordination: decentralized, - timeout: 10 sec, - cmake-include: "include/CMakeListsExtension.txt" -} - -preamble {= - #include "std_msgs/msg/int32.hpp" -=} - -reactor Clock(offset: time = 0, period: time = 1 sec) { - output y: std::shared_ptr - - timer t(0, period) - state count: int = 0 - state serialized_msg: rclcpp::SerializedMessage = {= 0u =} - - reaction(t) -> y {= - (self->count)++; - - auto msg = std::make_shared(); - msg->data = self->count; - - lf_set(y, msg); - =} -} - -reactor Destination { - input x: std::shared_ptr - - state s: int = 1 - - reaction(x) {= - // lf_print("Received %d.", int_msg.data); - if (x->value->data != self->s) { - lf_print_warning("Expected %d and got %d.", self->s, x->value->data); - } - self->s++; - =} - - reaction(shutdown) {= - lf_print("**** shutdown reaction invoked."); - if (self->s != 10000002) { - lf_print_warning("Expected 10000002 but got %d.", self->s); - } - lf_print("Approx. time per reaction: %lldns", get_elapsed_physical_time()/(self->s+1)); - =} -} - -federated reactor(period: time = 17 usec) { - c = new Clock(period=period) - d = new Destination() - c.y -> d.x serializer "ros2" -} diff --git a/C/Distributed/src/build-ROS-node.sh b/C/Distributed/src/build-ROS-node.sh deleted file mode 100644 index d11a3ba..0000000 --- a/C/Distributed/src/build-ROS-node.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -# usage: ./build-ROS-node name-of-lf-file-without-.lf name-of-ROS-package -lfc -r -n $1.lf -cp -R src-gen/$1/* $2/src/ -mv $2/src/$1.c $2/src/$1.cpp -pushd $2 -colcon build --packages-select $2 -popd diff --git a/C/Distributed/src/include/CMakeListsExtension.txt b/C/Distributed/src/include/CMakeListsExtension.txt deleted file mode 100644 index d461d4d..0000000 --- a/C/Distributed/src/include/CMakeListsExtension.txt +++ /dev/null @@ -1,5 +0,0 @@ -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-write-strings -O2") - -find_package(std_msgs REQUIRED) - -ament_target_dependencies( ${LF_MAIN_TARGET} std_msgs) \ No newline at end of file diff --git a/C/Distributed/src/timelimit-ros.lf b/C/Distributed/src/timelimit-ros.lf deleted file mode 100644 index 770998e..0000000 --- a/C/Distributed/src/timelimit-ros.lf +++ /dev/null @@ -1,162 +0,0 @@ -/** - * This is used to test the performance of using ROS as a communication method between reactors - * (number of reactions per second). - * - * 1- To get this example working, install full ROS 2 desktop - * ('https://index.ros.org/doc/ros2/Installation/Foxy/'). - * - * Please note that 'colcon' should also be installed. See - * 'https://index.ros.org/doc/ros2/Tutorials/Colcon-Tutorial/' for more details. - * - * 2- Follow the instruction in - * https://index.ros.org/doc/ros2/Tutorials/Writing-A-Simple-Cpp-Publisher-And-Subscriber/ - * **section 1** to create a 'timelimit-ros' package in the current (example/Distributed) folder. - * - * 3- Follow section 2.2 and 2.3 to modify the CMakeLists.txt and package.xml. - * - * 4- Replace the default C++14 standard in CMakeLists.txt (i.e., set(CMAKE_CXX_STANDARD 14)) with: - * - * # Default to C++20 if(NOT CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 20) endif() - * - * and rename the source in 'add_executable' to reflect - * - * add_executable(timelimit-ros src/timelimit-ros.cpp) - * - * 5- Use lfc (in bin/) to compile the provided .lf file - * - * lfc timelimit-ros.lf - * - * 6- Run the provided build-ROS-node.sh: - * - * ./build-ROS-node.sh timelimit-ros timelimit-ros - * - * This will create a 'timelimit-ros' node in the package timelimit-ros (these names can be changed - * in CMakeLists.txt and in the argument to build-ROS-node.sh). - * - * 7- Source the appropriate setup.bash and run the node: - * - * source timelimit-ros/install/setup.bash ros2 run timelimit-ros timelimit-ros - */ -target C { - keepalive: true, - no-compile: true, - timeout: 10 secs -} - -preamble {= - #include - #include - #include - #include - - #include "rclcpp/rclcpp.hpp" - #include "std_msgs/msg/int32.hpp" - - #define QUEUE_DEPTH 1000 -=} - -reactor Clock(offset: time = 0, period: time = 1 sec) { - preamble {= - class TimeLimitClock : public rclcpp::Node { - public: - TimeLimitClock() - : Node("LF_TimeLimit_Clock") - { - clock_ = this->create_publisher("LF_TimeLimit_y", QUEUE_DEPTH); - } - - rclcpp::Publisher::SharedPtr clock_; - }; - =} - state timelimit_clock: {= std::shared_ptr =} - timer t(offset, period) - state count: int = 0 - - reaction(startup) {= - // std::cout << "Executing startup." << std::endl; - char *argv[] = {(char*)"LF_TimeLimit_Clock", NULL}; - rclcpp::init(1, argv); - self->timelimit_clock = std::make_shared(); - =} - - reaction(t) {= - auto message = std_msgs::msg::Int32(); - message.data = ++(self->count); - // printf("Reacting at time %ld.\n", get_elapsed_logical_time()); - self->timelimit_clock->clock_->publish(message); - rclcpp::spin_some(self->timelimit_clock); - =} - - reaction(shutdown) {= - // std::cout << "Executing shutdown reaction." << std::endl; - rclcpp::shutdown(); - =} -} - -reactor Destination(period: time = 1 sec) { - preamble {= - class TimeLimitDestination : public rclcpp::Node { - public: - TimeLimitDestination(void* physical_action) - : Node("LF_TimeLimit_Destination"), physical_action_(physical_action) { - destination_ = this->create_subscription("LF_TimeLimit_y", - QUEUE_DEPTH, std::bind(&TimeLimitDestination::x_callback, - this, std::placeholders::_1)); - } - - private: - void x_callback(const std_msgs::msg::Int32::SharedPtr msg) const { - lf_schedule_int(physical_action_, 0, msg->data); - } - rclcpp::Subscription::SharedPtr destination_; - void* physical_action_; - }; - =} - physical action ros_message_x: int - state destination: {= std::shared_ptr =} - state s: int = 1 - state received_messages: int = 0 - state dropped_messages: int = 0 - - timer t(0, period) // Keep spinning for new messages - - reaction(startup) ros_message_x {= - // std::cout << "Executing startup." << std::endl; - self->destination = std::make_shared(ros_message_x); - =} - - reaction(ros_message_x) {= - // printf("%d\n", ros_message_x->value); - self->received_messages++; - if (ros_message_x->value != self->s) { - /* lf_print_warning("Expected %d and got %d. " - "Jumping my expectation to %d in order to catch up with the sender.", - self->s, ros_message_x->value, ros_message_x->value); */ - self->dropped_messages += ros_message_x->value - self->s; - self->s = ros_message_x->value; - } - self->s++; - =} - - reaction(t) {= - rclcpp::spin_some(self->destination); - // std::cout << "Timer triggered." << std::endl; - =} - - reaction(shutdown) {= - lf_print("**** shutdown reaction invoked."); - if (self->s != 10000002) { - lf_print_warning("Expected 10000002 but got %d.", self->s); - } - lf_print("Approx. time per reaction: %lldns" - " Dropped messages: %d", - get_elapsed_physical_time()/(self->received_messages+1), - self->dropped_messages); - rclcpp::shutdown(); - =} -} - -main reactor(period: time = 1 usec) { - c = new Clock(period=period) - d = new Destination(period=period) -} diff --git a/C/Distributed/src/timelimitros-native/CMakeLists.txt b/C/Distributed/src/timelimitros-native/CMakeLists.txt deleted file mode 100644 index 1abbccc..0000000 --- a/C/Distributed/src/timelimitros-native/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -cmake_minimum_required(VERSION 3.5) -project(timelimitros-native) - -# Default to C++17 -if(NOT CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) -endif() - -if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") - add_compile_options(-Wall -Wextra -Wpedantic) -endif() - -# find dependencies -find_package(ament_cmake REQUIRED) -find_package(rclcpp REQUIRED) -find_package(std_msgs REQUIRED) - -add_executable(timelimitros-native-clock src/timelimitros-native-clock.cpp) -ament_target_dependencies(timelimitros-native-clock rclcpp std_msgs) - -add_executable(timelimitros-native-dest src/timelimitros-native-dest.cpp) -ament_target_dependencies(timelimitros-native-dest rclcpp std_msgs) - -install(TARGETS - timelimitros-native-clock - timelimitros-native-dest - DESTINATION lib/${PROJECT_NAME}) - -# Install launch files. -install(DIRECTORY - launch - DESTINATION share/${PROJECT_NAME}) - -ament_package() diff --git a/C/Distributed/src/timelimitros-native/README.md b/C/Distributed/src/timelimitros-native/README.md deleted file mode 100644 index cc1663c..0000000 --- a/C/Distributed/src/timelimitros-native/README.md +++ /dev/null @@ -1,20 +0,0 @@ -A pure ROS implementation of TimeLimit. - -To try, use colcon to build the ROS nodes -``` -colcon build -``` -Then source the appropriate setup file. For example, for bash: -``` -source install/setup.bash -``` - -There is a launch file provided in the launch folder that launches the following two nodes: -``` -TimeLimit-Clock -TimeLimit-Dest -``` -To use the launcher, you can run: -``` -ros2 launch launch/TimeLimitROSNative.launch.py -``` \ No newline at end of file diff --git a/C/Distributed/src/timelimitros-native/launch/timelimitros-native.launch.py b/C/Distributed/src/timelimitros-native/launch/timelimitros-native.launch.py deleted file mode 100644 index ce4969f..0000000 --- a/C/Distributed/src/timelimitros-native/launch/timelimitros-native.launch.py +++ /dev/null @@ -1,19 +0,0 @@ -import launch -import launch.actions -import launch.substitutions -import launch_ros.actions - - -def generate_launch_description(): - return launch.LaunchDescription([ - launch_ros.actions.Node( - package='timelimitros-native', - executable='timelimitros-native-dest', - output='screen' - ), - launch_ros.actions.Node( - package='timelimitros-native', - executable='timelimitros-native-clock', - output='screen' - ) - ]) diff --git a/C/Distributed/src/timelimitros-native/package.xml b/C/Distributed/src/timelimitros-native/package.xml deleted file mode 100644 index 8ae6478..0000000 --- a/C/Distributed/src/timelimitros-native/package.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - timelimitros-native - 0.0.0 - TODO: Package description - soroush - TODO: License declaration - - ament_cmake - rclcpp - std_msgs - - ament_lint_auto - ament_lint_common - - - ament_cmake - - diff --git a/C/Distributed/src/timelimitros-native/src/timelimitros-native-clock.cpp b/C/Distributed/src/timelimitros-native/src/timelimitros-native-clock.cpp deleted file mode 100644 index 01d89ee..0000000 --- a/C/Distributed/src/timelimitros-native/src/timelimitros-native-clock.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include -#include -#include -#include - -#include "rclcpp/rclcpp.hpp" -#include "std_msgs/msg/int32.hpp" - -#define QUEUE_DEPTH 1000 - -using namespace std::chrono_literals; - -class TimeLimitClock : public rclcpp::Node { - public: - TimeLimitClock() - : Node("TimeLimit_Clock") { - clock_ = this->create_publisher("TimeLimit_y", QUEUE_DEPTH); - timer_ = this->create_wall_timer(15us, std::bind(&TimeLimitClock::timer_callback, this)); - count_ = 0; - } - - private: - void timer_callback() { - auto message = std_msgs::msg::Int32(); - message.data = ++count_; - clock_->publish(message); - } - rclcpp::TimerBase::SharedPtr timer_; - rclcpp::Publisher::SharedPtr clock_; - int count_; -}; - -int main(int argc, char * argv[]) { - rclcpp::init(argc, argv); - std::chrono::duration ten_seconds = 10s; // Timeout to be enforced if the following promise is not fullfilled - std::promise false_promise; // Never fullfilled - rclcpp::spin_until_future_complete(std::make_shared(), - false_promise.get_future().share(), - ten_seconds); - rclcpp::shutdown(); - return 0; -} \ No newline at end of file diff --git a/C/Distributed/src/timelimitros-native/src/timelimitros-native-dest.cpp b/C/Distributed/src/timelimitros-native/src/timelimitros-native-dest.cpp deleted file mode 100644 index 1d906d5..0000000 --- a/C/Distributed/src/timelimitros-native/src/timelimitros-native-dest.cpp +++ /dev/null @@ -1,81 +0,0 @@ -#include -#include -#include -#include -#include - -#include "rclcpp/rclcpp.hpp" -#include "std_msgs/msg/int32.hpp" - -#define QUEUE_DEPTH 1000 - -using namespace std::chrono_literals; - -class TimeLimitDestination; - -std::shared_ptr destination; - -class TimeLimitDestination : public rclcpp::Node { - public: - TimeLimitDestination() - : Node("TimeLimit_Destination") { - destination_ = this->create_subscription("TimeLimit_y", - QUEUE_DEPTH, - std::bind(&TimeLimitDestination::x_callback, - this, - std::placeholders::_1)); - start_time = std::chrono::high_resolution_clock::now(); - s_ = 1; - received_messages_ = 0; - dropped_messages_ = 0; - } - - void shutdown() { - RCLCPP_INFO(this->get_logger(), "**** shutdown invoked."); - if (s_ != 10000002) { - RCLCPP_INFO(this->get_logger(), "Expected 10000002 but got %d.", s_); - } - auto physical_time = std::chrono::high_resolution_clock::now(); - auto elapsed_time = physical_time.time_since_epoch() - start_time.time_since_epoch(); - RCLCPP_INFO(this->get_logger(), "Approx. time per message: %lldns" - " Dropped messages: %d", - elapsed_time/(received_messages_+1), - dropped_messages_); - } - - private: - void x_callback(const std_msgs::msg::Int32::SharedPtr msg) const { - destination->update(msg->data); - } - - void update(int data) { - received_messages_++; - if (data != s_) { - RCLCPP_INFO(this->get_logger(), "Expected %d and got %d. " - "Jumping my expectation to %d in order to catch up with the sender.", - s_, data, data); - dropped_messages_ += data - s_; - s_ = data; - } - s_++; - } - - rclcpp::Subscription::SharedPtr destination_; - int s_; - int received_messages_; - int dropped_messages_; - std::chrono::time_point start_time; -}; - -int main(int argc, char * argv[]) { - rclcpp::init(argc, argv); - destination = std::make_shared(); - std::chrono::duration ten_seconds = 10s; // Timeout to be enforced if the following promise is not fullfilled - std::promise false_promise; // Never fullfilled - rclcpp::spin_until_future_complete(destination, - false_promise.get_future().share(), - ten_seconds); - destination->shutdown(); - rclcpp::shutdown(); - return 0; - } \ No newline at end of file