Class: ROS::Time
Overview
ROS Time object. This is used as msg object for time
Constant Summary
- SIM_TIME_PARAMETER =
parameter name for switching sim/wall time.
'/use_sim_time'
- @@use_sim_time =
use simulated time?
false
- @@current_sim_time =
current simulated time
nil
- @@clock_subscriber =
subscriber for /clock
nil
Instance Attribute Summary
Attributes inherited from TimeValue
Class Method Summary (collapse)
-
+ (ROS::Time) get_simtime
get the simulated time.
-
+ (ROS::Time) get_walltime
get the system real time.
-
+ (Object) initialize_with_sim_or_wall(node)
initialize Time.
-
+ (Object) now
initialize with current time.
Instance Method Summary (collapse)
-
- (Time) +(duration)
add time value.
-
- (Duration) -(other)
subtract time value.
-
- (Time) initialize(time = nil)
constructor
A new instance of Time.
-
- (Time) to_time
returns ruby Time object.
Methods inherited from TimeValue
#<=>, #canonicalize, #to_nsec, #to_sec
Constructor Details
Class Method Details
+ (ROS::Time) get_simtime
get the simulated time
121 122 123 |
# File 'lib/ros/time.rb', line 121 def self.get_simtime @@current_sim_time end |
+ (ROS::Time) get_walltime
get the system real time
114 115 116 |
# File 'lib/ros/time.rb', line 114 def self.get_walltime self.new(::Time::now) end |
+ (Object) initialize_with_sim_or_wall(node)
initialize Time
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ros/time.rb', line 88 def self.initialize_with_sim_or_wall(node) @@use_sim_time = node.get_param(SIM_TIME_PARAMETER, false) if @@use_sim_time and not @@clock_subscriber puts 'initializing simulated clock (/clock)' @@clock_subscriber = node.subscribe('/clock', Rosgraph_msgs::Clock) do |msg| @@current_sim_time = msg.clock end @@sim_thread = Thread.new do while node.ok? @@clock_subscriber.process_queue end end elsif not @@use_sim_time and @@clock_subscriber begin @@clock_subscriber.shutdown rescue => e # even if node is already shutdown, do nothing. end @@current_sim_time = nil end end |
+ (Object) now
initialize with current time
126 127 128 129 130 131 132 |
# File 'lib/ros/time.rb', line 126 def self.now if @@current_sim_time @@current_sim_time else self.new(::Time::now) end end |
Instance Method Details
- (Time) +(duration)
add time value
151 152 153 154 155 156 |
# File 'lib/ros/time.rb', line 151 def +(duration) tm = ::ROS::Time.new tm.secs = @secs + duration.secs tm.nsecs = @nsecs + duration.nsecs tm.canonicalize end |
- (Duration) -(other)
subtract time value.
161 162 163 164 165 166 |
# File 'lib/ros/time.rb', line 161 def -(other) d = ::ROS::Duration.new d.secs = @secs - other.secs d.nsecs = @nsecs - other.nsecs d.canonicalize end |
- (Time) to_time
returns ruby Time object.
170 171 172 |
# File 'lib/ros/time.rb', line 170 def to_time ::Time.at(@secs, @nsecs) end |