Error while running obstacle avoidance script for turtlebot3 in ROS2
Hello, I am trying to run an obstacle avoidance script and test it in gazebo simulation using turtlebot 3 in ROS2 but I am getting the following error - [WARN] [1667317780.806097773] [obstacle_avoidance]: New publisher discovered on topic '/scan', offering incompatible QoS. No messages will be received from it. Last incompatible policy:RELIABILITY
Please help me in solving this issue, thank you.
Here is the code I have written -
import rclpy
from rclpy.node import Node
from sensor_msgs.msg import LaserScan
from geometry_msgs.msg import Twist
distToObstacle = 1
class ObstacleAvoidance(Node):
def __init__(self):
super().__init__('obstacle_avoidance')
self.sub = self.create_subscription(LaserScan, '/scan', self.obstacle_callback, 10)
self.pub = self.create_publisher(Twist, '/cmd_vel', 10)
def obstacle_callback(self, msg):
self.get_logger().info('The distance to obstacle is %s ' % msg.ranges[300])
move = Twist()
if msg.ranges[300] > distToObstacle:
move.linear.x = 0.5
move.angular.z = 0.0
if msg.ranges[300] <= distToObstacle:
move.linear.x = 0.5
move.angular.z = 1.5
self.pub.publish(move)
def main(args=None):
rclpy.init(args=args)
obstacle_avoidance = ObstacleAvoidance()
rclpy.spin(obstacle_avoidance)
obstacle_avoidance.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
can you please paste your node to debug .
Hi @Davies Ogunsina, I have updated my question with the code I have written.