-
Notifications
You must be signed in to change notification settings - Fork 775
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
Correct the timestamp used by the camera (kinetic-devel) #540
Changes from all commits
7fb4290
1e18ac0
901f2fc
83b6d97
401c3b1
d2e1e44
edee42d
d73588c
7552b33
ca8b05e
191f38a
0d7e9f2
eb81646
cde71ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,7 +76,11 @@ void GazeboRosCamera::OnNewFrame(const unsigned char *_image, | |
unsigned int _width, unsigned int _height, unsigned int _depth, | ||
const std::string &_format) | ||
{ | ||
this->sensor_update_time_ = this->parentSensor_->LastUpdateTime(); | ||
# if GAZEBO_MAJOR_VERSION >= 7 | ||
common::Time sensor_update_time = this->parentSensor_->LastMeasurementTime(); | ||
# else | ||
common::Time sensor_update_time = this->parentSensor_->GetLastMeasurementTime(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a use case when the kinetic-devel branch will be used with a version of Gazebo less than 7? Seems this compiler directive can be removed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm ok with removing support for gazebo < 7 in the kinetic branch but let's do it a single PR and do not spread removals all over the place to keep PRs clean. |
||
# endif | ||
|
||
if (!this->parentSensor->IsActive()) | ||
{ | ||
|
@@ -88,12 +92,18 @@ void GazeboRosCamera::OnNewFrame(const unsigned char *_image, | |
{ | ||
if ((*this->image_connect_count_) > 0) | ||
{ | ||
common::Time cur_time = this->world_->GetSimTime(); | ||
if (cur_time - this->last_update_time_ >= this->update_period_) | ||
// OnNewFrame is triggered at the gazebo sensor <update_rate> | ||
// while there is also a plugin <updateRate> that can throttle the | ||
// rate down further (but then why not reduce the sensor rate? | ||
// what is the use case?). | ||
// Setting the <updateRate> to zero will make this plugin | ||
// update at the gazebo sensor <update_rate>, update_period_ will be | ||
// zero and the conditional always will be true. | ||
if (sensor_update_time - this->last_update_time_ >= this->update_period_) | ||
{ | ||
this->PutCameraData(_image); | ||
this->PublishCameraInfo(); | ||
this->last_update_time_ = cur_time; | ||
this->PutCameraData(_image, sensor_update_time); | ||
this->PublishCameraInfo(sensor_update_time); | ||
this->last_update_time_ = sensor_update_time; | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <gtest/gtest.h> | ||
#include <image_transport/image_transport.h> | ||
#include <ros/ros.h> | ||
|
||
class CameraTest : public testing::Test | ||
{ | ||
protected: | ||
virtual void SetUp() | ||
{ | ||
has_new_image_ = false; | ||
} | ||
|
||
ros::NodeHandle nh_; | ||
image_transport::Subscriber cam_sub_; | ||
bool has_new_image_; | ||
ros::Time image_stamp_; | ||
public: | ||
void imageCallback(const sensor_msgs::ImageConstPtr& msg) | ||
{ | ||
image_stamp_ = msg->header.stamp; | ||
has_new_image_ = true; | ||
} | ||
}; | ||
|
||
// Test if the camera image is published at all, and that the timestamp | ||
// is not too long in the past. | ||
TEST_F(CameraTest, cameraSubscribeTest) | ||
{ | ||
image_transport::ImageTransport it(nh_); | ||
cam_sub_ = it.subscribe("camera1/image_raw", 1, | ||
&CameraTest::imageCallback, | ||
dynamic_cast<CameraTest*>(this)); | ||
|
||
#if 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. explain when this test should be re-enabled (link to issue) or remove this commented out code |
||
// wait for gazebo to start publishing | ||
// TODO(lucasw) this isn't really necessary since this test | ||
// is purely passive | ||
bool wait_for_topic = true; | ||
while (wait_for_topic) | ||
{ | ||
// @todo this fails without the additional 0.5 second sleep after the | ||
// publisher comes online, which means on a slower or more heavily | ||
// loaded system it may take longer than 0.5 seconds, and the test | ||
// would hang until the timeout is reached and fail. | ||
if (cam_sub_.getNumPublishers() > 0) | ||
wait_for_topic = false; | ||
ros::Duration(0.5).sleep(); | ||
} | ||
#endif | ||
|
||
while (!has_new_image_) | ||
{ | ||
ros::spinOnce(); | ||
ros::Duration(0.1).sleep(); | ||
} | ||
|
||
// This check depends on the update period being much longer | ||
// than the expected difference between now and the received image time | ||
// TODO(lucasw) | ||
// this likely isn't that robust - what if the testing system is really slow? | ||
double time_diff = (ros::Time::now() - image_stamp_).toSec(); | ||
ROS_INFO_STREAM(time_diff); | ||
EXPECT_LT(time_diff, 1.0); | ||
cam_sub_.shutdown(); | ||
} | ||
|
||
int main(int argc, char** argv) | ||
{ | ||
ros::init(argc, argv, "gazebo_camera_test"); | ||
testing::InitGoogleTest(&argc, argv); | ||
return RUN_ALL_TESTS(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0"?> | ||
<launch> | ||
<arg name="gui" default="false" /> | ||
|
||
<param name="/use_sim_time" value="true" /> | ||
|
||
<node name="gazebo" pkg="gazebo_ros" type="gzserver" | ||
respawn="false" output="screen" | ||
args="-r $(find gazebo_plugins)/test/camera/camera.world" /> | ||
|
||
<group if="$(arg gui)"> | ||
<node name="gazebo_gui" pkg="gazebo_ros" type="gzclient" respawn="false" output="screen"/> | ||
</group> | ||
|
||
<test test-name="camera" pkg="gazebo_plugins" type="camera-test" | ||
clear_params="true" time-limit="30.0" /> | ||
</launch> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome tests!