Skip to content

Commit

Permalink
minor update
Browse files Browse the repository at this point in the history
Signed-off-by: Staschulat Jan <jan.staschulat@de.bosch.com>
  • Loading branch information
JanStaschulat committed Dec 10, 2019
1 parent aef1176 commit d3db310
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
19 changes: 16 additions & 3 deletions rcl_executor/src/let_executor.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
// limitations under the License.

#include "rcl_executor/let_executor.h"
#include "rcutils/time.h"

#include <sys/time.h> // for gettimeofday()
#include <unistd.h> // for usleep()
Expand Down Expand Up @@ -532,7 +533,7 @@ timeval_add(const struct timeval * a, const struct timeval * b)
/// TODO (jst3si) write unit test to validate length of period
*/

// #define unit_test_spin_period // enable this #define only for the Unit Test.
#define unit_test_spin_period 1 // enable this #define only for the Unit Test.

rcl_ret_t
rcle_let_executor_spin_period(rcle_let_executor_t * executor, const uint64_t period)
Expand All @@ -545,18 +546,31 @@ rcle_let_executor_spin_period(rcle_let_executor_t * executor, const uint64_t per
struct timeval period_val;
int64_t secs_wait, micros_wait;

rcutils_time_point_value_t startx;
rcl_ret_t rc;
rc = rcutils_system_time_now(&startx);
const unsigned int TIMEPOINT_STR_SIZE = 32;
char tp_str[TIMEPOINT_STR_SIZE];
rc = rcutils_time_point_value_as_nanoseconds_string(&startx, tp_str, TIMEPOINT_STR_SIZE);
printf("Timepoint: %s\n",tp_str);

if (rc != RCL_RET_OK) {
//sth went wrong
return rc;
}
#ifdef unit_test_spin_period
// variables for statistics
struct timeval prev_start;
int64_t p_secs_used, p_micros_used;
unsigned int period_sum = 0;
unsigned int cnt = 0;
printf("starting unit test\n")
#endif

// conversion from nano-seconds to micro-seconds
uint64_t period_usec = period / 1000;


// convert period to timeval
if (period_usec > 1000000) {
period_val.tv_sec = period_usec / 1000000;
Expand All @@ -565,7 +579,7 @@ rcle_let_executor_spin_period(rcle_let_executor_t * executor, const uint64_t per
period_val.tv_sec = 0;
period_val.tv_usec = period_usec;
}

printf("spin period = %d usec\n" period_val:tv_usec);
// initialization of timepoints
gettimeofday(&start, NULL);

Expand Down Expand Up @@ -594,7 +608,6 @@ rcle_let_executor_spin_period(rcle_let_executor_t * executor, const uint64_t per
gettimeofday(&end, NULL);
secs_wait = (next_time.tv_sec - end.tv_sec); // avoid overflow by subtracting first
micros_wait = ((secs_wait * 1000000) + next_time.tv_usec) - (end.tv_usec);
// printf("micro_wait %d\n", micros_wait);
// sleep until next_time timepoint
if (micros_wait > 0) {
usleep(micros_wait);
Expand Down
8 changes: 4 additions & 4 deletions rcl_executor/test/test_let_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void my_timer_callback(rcl_timer_t * timer, int64_t last_call_time)
// Do timer work...
// Optionally reconfigure, cancel, or reset the timer...
if (timer != NULL) {
printf("Timer: time since last call %d\n", static_cast<int>(last_call_time));
//printf("Timer: time since last call %d\n", static_cast<int>(last_call_time));
}
}

Expand Down Expand Up @@ -1082,7 +1082,7 @@ to run this test case you also need to set the define
execute the unit not with colcon test but direcly with
$>rcl_executor/build/rcl_executor/test_let_executor
test result (24.07.2017 Linux Ubunutu 16.04)
test result (24.07.2019 Linux Ubunutu 16.04)
avarage is computed over 1000 iterations of spin_some()
period 100ms:
Expand Down Expand Up @@ -1139,7 +1139,7 @@ period average 0.999999
period average 0.999971
...
*/
/*

TEST_F(TestDefaultExecutor, spin_period) {
// 27.06.2019, adopted from ros2/rcl/rcl/test/rcl/test_subscriptions.cpp
// by Jan Staschulat, under Apache 2.0 License
Expand All @@ -1165,4 +1165,4 @@ TEST_F(TestDefaultExecutor, spin_period) {
rcle_let_executor_spin_period(&executor, 10);
rcle_let_executor_fini(&executor);
}
*/

0 comments on commit d3db310

Please sign in to comment.