SMACC2
basic_publisher.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2
3# Copyright 2021 RobosoftAI Inc.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import rclpy
18from rclpy.node import Node
19from std_msgs.msg import Int16
20import random
21
22
24 def __init__(self):
25 super().__init__("temperature_sensor")
26 self.temperature_publisher_ = self.create_publisher(Int16, "temperature", 10)
27 self.temperature_timer_ = self.create_timer(0.05, self.publish_temperature)
28
30 temperature = random.randint(20, 30)
31 msg = Int16()
32 msg.data = temperature
33 self.temperature_publisher_.publish(msg)
34
35
36def main(args=None):
37 rclpy.init(args=args)
39 rclpy.spin(node)
40 rclpy.shutdown()
41
42
43if __name__ == "__main__":
44 main()
def main(args=None)