Main Page
Classes
Files
File List
File Members
time_api
sleep
sleep.cpp
Go to the documentation of this file.
1
// The roscpp_tutorials package tries to show off the roscpp c++ client library
3
//
4
// Copyright (C) 2008, Morgan Quigley
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are met:
8
// * Redistributions of source code must retain the above copyright notice,
9
// 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 Stanford University 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.
29
30
#include <cstdio>
31
#include "
ros/time.h
"
32
33
int
main
(
int
/*argc*/
,
char
**
/*argv*/
)
34
{
35
ros::Time::init
();
36
// ros::Duration objects are constructed with two parameters: the first
37
// is the number of seconds in the duration, and the second is the number
38
// of nanoseconds.
39
// Once you have this object constructed, you can call its sleep() method
40
// to sleep for its duration. (The underlying implementation is nanosleep)
41
printf(
"sleeping for one second\n"
);
42
ros::Duration
(1, 0).
sleep
();
43
44
// This just shows how you have to have to use a lot of zeros to get a half
45
// second in nanoseconds.
46
printf(
"sleeping for a half second\n"
);
47
ros::Duration
(0, 500000000).
sleep
();
48
49
// This usage constructs a ros::Duration object and keeps it around, calling
50
// the sleep() function repeatedly.
51
ros::Duration
tenth(0, 100000000);
// 0.1 seconds
52
for
(
int
i = 0; i < 5; i++)
53
{
54
printf(
"sleeping for a tenth of a second\n"
);
55
tenth.
sleep
();
56
}
57
58
59
return
0;
60
}
61
time.h
ros::Duration::sleep
bool sleep() const
ros::Time::init
static void init()
ros::Duration
main
int main(int, char **)
Definition:
sleep.cpp:33
roscpp_tutorials
Author(s): Morgan Quigley
autogenerated on Fri Jun 7 2019 22:01:43