Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,35 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List, Optional
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use builtin list


import rclpy
from rclpy.executors import ExternalShutdownException
from rclpy.node import Node
from rclpy.publisher import Publisher
from rclpy.timer import Timer

from std_msgs.msg import String


class MinimalPublisher(Node):

def __init__(self):
def __init__(self) -> None:
super().__init__('minimal_publisher')
self.publisher_ = self.create_publisher(String, 'topic', 10)
self.publisher_: Publisher[String] = self.create_publisher(String, 'topic', 10)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.publisher_: Publisher[String] = self.create_publisher(String, 'topic', 10)
self.publisher_= self.create_publisher(String, 'topic', 10)

timer_period = 0.5 # seconds
self.timer = self.create_timer(timer_period, self.timer_callback)
self.timer: Timer = self.create_timer(timer_period, self.timer_callback)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.timer: Timer = self.create_timer(timer_period, self.timer_callback)
self.timer = self.create_timer(timer_period, self.timer_callback)

self.i = 0

def timer_callback(self):
msg = String()
def timer_callback(self) -> None:
msg: String = String()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
msg: String = String()
msg = String()

msg.data = 'Hello World: %d' % self.i
self.publisher_.publish(msg)
self.get_logger().info('Publishing: "%s"' % msg.data)
self.i += 1


def main(args=None):
def main(args: Optional[List[str]] = None) -> None:
try:
with rclpy.init(args=args):
minimal_publisher = MinimalPublisher()
Expand Down