ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Error while running obstacle avoidance script for turtlebot3 in ROS2

asked 2022-11-01 15:58:18 -0600

Robo_guy gravatar image

updated 2022-11-01 23:02:22 -0600

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()
edit retag flag offensive close merge delete

Comments

can you please paste your node to debug .

Davies Ogunsina gravatar image Davies Ogunsina  ( 2022-11-01 17:17:36 -0600 )edit

Hi @Davies Ogunsina, I have updated my question with the code I have written.

Robo_guy gravatar image Robo_guy  ( 2022-11-01 23:03:45 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-11-02 02:08:27 -0600

nils_iseke gravatar image

You need to change the QoS policies of the scan topic in RViz. image description

edit flag offensive delete link more

Comments

Ok thank you @nils_iseke, I was actually simulating in gazebo and not rviz and also doing this using The Construct Platform, although while going through the turtlebot3 tutorial files I came across one script where they have imported QoS and assigned value to it as can be seen here - https://github.com/ROBOTIS-GIT/turtle... After doing this in my code, it works fine. I guess I had to import QoS in the code and also make the changes told by you in rviz2 to get it working properly, thanks for your answer.

Robo_guy gravatar image Robo_guy  ( 2022-11-02 21:52:12 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2022-11-01 15:58:18 -0600

Seen: 210 times

Last updated: Nov 02 '22