time_reset_test.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Open Source Robotics Foundation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <gtest/gtest.h>
33 #include <sys/time.h>
34 #include <rosgraph_msgs/Clock.h>
35 
36 using namespace tf2;
37 
39 {
40  ros::spinOnce();
41  for (uint8_t i = 0; i < 10; ++i)
42  {
43  usleep(100);
44  ros::spinOnce();
45  }
46 }
47 
48 TEST(tf2_ros_transform_listener, time_backwards)
49 {
50 
51  tf2_ros::Buffer buffer;
52  tf2_ros::TransformListener tfl(buffer);
54 
56 
57  ros::Publisher clock = nh.advertise<rosgraph_msgs::Clock>("/clock", 5);
58 
59  rosgraph_msgs::Clock c;
60  c.clock = ros::Time(100);
61  clock.publish(c);
62 
63  // basic test
64  ASSERT_FALSE(buffer.canTransform("foo", "bar", ros::Time(101, 0)));
65 
66  // set the transform
67  geometry_msgs::TransformStamped msg;
68  msg.header.stamp = ros::Time(100, 0);
69  msg.header.frame_id = "foo";
70  msg.child_frame_id = "bar";
71  msg.transform.rotation.x = 1.0;
72  tfb.sendTransform(msg);
73  msg.header.stamp = ros::Time(102, 0);
74  tfb.sendTransform(msg);
75 
76 
77  // make sure it arrives
79 
80  // verify it's been set
81  ASSERT_TRUE(buffer.canTransform("foo", "bar", ros::Time(101, 0)));
82 
83  c.clock = ros::Time(90);
84  clock.publish(c);
85 
86  // make sure it arrives
88 
89  //Send another message to trigger clock test on an unrelated frame
90  msg.header.stamp = ros::Time(110, 0);
91  msg.header.frame_id = "foo2";
92  msg.child_frame_id = "bar2";
93  tfb.sendTransform(msg);
94 
95  // make sure it arrives
97 
98  //verify the data's been cleared
99  ASSERT_FALSE(buffer.canTransform("foo", "bar", ros::Time(101, 0)));
100 
101 }
102 
103 
104 
105 
106 int main(int argc, char **argv){
107  testing::InitGoogleTest(&argc, argv);
108  ros::init(argc, argv, "transform_listener_backwards_reset");
109  return RUN_ALL_TESTS();
110 }
int main(int argc, char **argv)
void publish(const boost::shared_ptr< M > &message) const
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
Standard implementation of the tf2_ros::BufferInterface abstract data type.
Definition: buffer.h:51
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
void sendTransform(const geometry_msgs::TransformStamped &transform)
Send a StampedTransform The stamped data structure includes frame_id, and time, and parent_id already...
This class provides an easy way to request and receive coordinate frame transform information...
This class provides an easy way to publish coordinate frame transform information. It will handle all the messaging and stuffing of messages. And the function prototypes lay out all the necessary data needed for each message.
virtual bool canTransform(const std::string &target_frame, const std::string &source_frame, const ros::Time &target_time, const ros::Duration timeout, std::string *errstr=NULL) const
Test if a transform is possible.
Definition: buffer.cpp:119
TEST(tf2_ros_transform_listener, time_backwards)
ROSCPP_DECL void spinOnce()
void spin_for_a_second()


tf2_ros
Author(s): Eitan Marder-Eppstein, Wim Meeussen
autogenerated on Fri Jun 7 2019 21:45:43