Skip to content

Commit

Permalink
fix rate initialized by duration
Browse files Browse the repository at this point in the history
When constructing a Rate object with a duration as argument, it is the expected period duration, not a frequency.
  • Loading branch information
lgerardSRI authored and dirk-thomas committed Jul 22, 2014
1 parent ec54971 commit 9198a8c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rostime/src/rate.cpp
Expand Up @@ -47,7 +47,7 @@ Rate::Rate(double frequency)

Rate::Rate(const Duration& d)
: start_(Time::now())
, expected_cycle_time_(1.0 / d.toSec())
, expected_cycle_time_(d.sec, d.nsec)
, actual_cycle_time_(0.0)
{ }

Expand Down
7 changes: 7 additions & 0 deletions rostime/test/time.cpp
Expand Up @@ -30,6 +30,7 @@
#include <vector>

#include <gtest/gtest.h>
#include <ros/rate.h>
#include <ros/time.h>
#include <sys/time.h>

Expand Down Expand Up @@ -409,6 +410,12 @@ TEST(Duration, sleepWithSignal)
ASSERT_GT(end - start, d);
}

TEST(Rate, constructFromDuration){
Duration d(4, 0);
Rate r(d);
EXPECT_EQ(r.expectedCycleTime(), d);
}

///////////////////////////////////////////////////////////////////////////////////
// WallTime/WallDuration
///////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 9198a8c

Please sign in to comment.