stg_time.cc
Go to the documentation of this file.
1 /*
2  * Player - One Hell of a Robot Server
3  * Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  */
21 //
22 // Desc: Stage (simulator) time
23 // Author: Richard Vaughan
24 // Date: 7 May 2003
25 // CVS: $Id$
26 //
28 
29 #include <math.h>
30 
31 #include "p_driver.h"
32 using namespace Stg;
33 
34 // Constructor
36 {
37  assert(driver);
38  this->driver = driver;
39  return;
40 }
41 
42 // Destructor
44 {
45  return;
46 }
47 
48 // Get the simulator time
49 int StTime::GetTime(struct timeval* time)
50 {
51  PRINT_DEBUG( "get time" );
52 
53  assert( this->driver );
54 
55  World* world = driver->world;
56 
57  usec_t usec = world->SimTimeNow();
58  time->tv_sec = (int)floor(usec/million);
59  time->tv_usec = (int)rint(fmod(usec,million) * million);
60 
61  PRINT_DEBUG2( "time now %ld sec %ld usec", time->tv_sec, time->tv_usec );
62 
63  return 0;
64 }
65 
66 int StTime::GetTimeDouble(double* time)
67 {
68  PRINT_DEBUG( "get time (double)" );
69 
70  assert( this->driver );
71 
72  World* world = driver->world;
73 
74  *time = world->SimTimeNow() / million;
75 
76  PRINT_DEBUG1( "time now %f sec ", *time);
77 
78  return 0;
79 }
StTime(StgDriver *driver)
Definition: stg_time.cc:35
usec_t SimTimeNow(void) const
Definition: stage.hh:1119
World class
Definition: stage.hh:814
The Stage library uses its own namespace.
Definition: canvas.hh:8
#define PRINT_DEBUG2(m, a, b)
Definition: stage.hh:668
virtual ~StTime()
Definition: stg_time.cc:43
const double million
Definition: stage.hh:142
int GetTime(struct timeval *time)
Definition: stg_time.cc:49
uint64_t usec_t
Definition: stage.hh:186
#define PRINT_DEBUG1(m, a)
Definition: stage.hh:667
#define PRINT_DEBUG(m)
Definition: stage.hh:666
int GetTimeDouble(double *time)
Definition: stg_time.cc:66


stage
Author(s): Richard Vaughan , Brian Gerkey , Reed Hedges , Andrew Howard , Toby Collett , Pooya Karimian , Jeremy Asher , Alex Couture-Beil , Geoff Biggs , Rich Mattes , Abbas Sadat
autogenerated on Mon Jun 10 2019 15:06:10