#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from time import sleep
import rclpy
from std_msgs.msg import String
# We do not recommend this style as ROS 2 provides timers for this purpose,
# and it is recommended that all nodes call a variation of spin.
# This example is only included for completeness because it is similar to examples in ROS 1.
# For periodic publication please see the other examples using timers.
def main(args=None):
rclpy.init(args=args)
node = rclpy.create_node('rtcm_publisher')
publisher = node.create_publisher(String, 'topic')
msg = String()
i = 0
while rclpy.ok():
msg.data = 'Hello World: %d' % i
i += 1
node.get_logger().info('Publishing: "%s"' % msg.data)
publisher.publish(msg)
sleep(0.5) # seconds
# Destroy the node explicitly
# (optional - otherwise it will be done automatically
# when the garbage collector destroys the node object)
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()

You didn’t mention what exact command you invoked when you got this error message.

If you are trying to call ros2 run ... that won’t work since that command expects the executable to be in the path <install-prefix>/lib/<pkgname>. Your script rtcm_publisher_old is likely being installed into <install-prefix>/bin and is therefore already on the PATH. You should be able to invoke the executable directly using just the name.