Skip to content

Commit

Permalink
Fixes linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ngxingyu committed Jun 12, 2024
1 parent 5a5272e commit bb0dc5d
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions scripts/timereference_fake.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
#!/usr/bin/env python3

"""Copyright (c) 2014-2021 Vladimir Ermakov. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
"""
import time
import rclpy
from rclpy.node import Node
from sensor_msgs.msg import TimeReference
import time


class FakeTimePublisher(Node):
Expand All @@ -25,21 +54,17 @@ def publish_time(self):
# Increment the current time by 1 second
self.current_time += 1

# Convert the current time to a human-readable format
readable_time = time.strftime(
"%Y-%m-%d %H:%M:%S", time.localtime(self.current_time)
)

# Create a message and publish it
msg = TimeReference()
msg.header.stamp = self.get_clock().now().to_msg()
msg.source = "fake_time_publisher"
msg.time_ref.sec = int(self.current_time)
msg.time_ref.nanosec = int((self.current_time - int(self.current_time)) * 1e9)
msg.time_ref.nanosec = int((
self.current_time - int(self.current_time)) * 1e9)
self.publisher_.publish(msg)

# Log the published time
self.get_logger().info('Publishing: "%s"' % msg)
self.get_logger().info(f'Publishing: {msg}')


def main(args=None):
Expand Down

0 comments on commit bb0dc5d

Please sign in to comment.