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

Getting QoS error on running code [closed]

asked 2023-01-03 20:13:36 -0500

Robo_guy gravatar image

updated 2023-01-03 20:28:29 -0500

Hi everyone, I am trying to run obstacle avoidance cpp code in ROS 2 using turtlebot 3 in gazebo but on running the code I am getting the following error - [WARN] [1672798148.155781828] [obstacle_avoidance]: New publisher discovered on topic '/scan', offering incompatible QoS. No messages will be sent to it. Last incompatible policy: RELIABILITY_QOS_POLICY Here is the entire script -

#include "rclcpp/rclcpp.hpp"
#include "geometry_msgs/msg/twist.hpp"
#include "sensor_msgs/msg/laser_scan.hpp"
using std::placeholders::_1;

class ObstacleAvoidance : public rclcpp::Node
{
    public:
    ObstacleAvoidance() : Node("obstacle_avoidance") {
        velocity_publisher = this->create_publisher<geometry_msgs::msg::Twist>('/cmd_vel', 10);
        auto default_qos = rclcpp::QoS(rclcpp::SystemDefaultsQoS());
        subscription_ = this->create_subscription<sensor_msgs::msg::LaserScan>(
        '/scan', default_qos,
        std::bind(&ObstacleAvoidance::topic_callback, this, _1));
        }

    private:
    void topic_callback(const sensor_msgs::msg::LaserScan::SharedPtr msg) {
        int distToObstacle = 1;
        auto move = geometry_msgs::msg::Twist();

        if(msg->ranges[300] > distToObstacle) {
            move.linear.x = 0.5;
            move.angular.z = 0.0;
            velocity_publisher->publish(move);
        }

        if(msg->ranges[300] <= distToObstacle) {
            move.linear.x = 0.5;
            move.angular.z = 3.5;
            velocity_publisher->publish(move); 
        }  
    }

    rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr velocity_publisher;
    rclcpp::Subscription<sensor_msgs::msg::LaserScan>::SharedPtr subscription_;
};

int main(int argc, char * argv[])
{
  rclcpp::init(argc, argv);
  rclcpp::spin(std::make_shared<ObstacleAvoidance>());
  rclcpp::shutdown();
  return 0;
}

Can anybody tell me what is wrong in this script which is causing the above error?

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Robo_guy
close date 2023-08-07 18:39:19.767616

1 Answer

Sort by » oldest newest most voted
1

answered 2023-01-03 22:22:30 -0500

Davies Ogunsina gravatar image

You didn't initialize your node.

Try doing this in your main function:

rclcpp::init(argv,argc,"node_name");

where you added default_qos remove that and add a specific qos like 10 or 100 .

Recompile the workspace and rerun the node .

If this doesn't work let me know.

edit flag offensive delete link more

Comments

Hi @Davies Ogunsina, thanks for your answer, I tried implementing the steps you mentioned but still I am getting the same error.

Robo_guy gravatar image Robo_guy  ( 2023-01-04 19:38:06 -0500 )edit

Did you recompile the workspace? before running the node .

Davies Ogunsina gravatar image Davies Ogunsina  ( 2023-01-15 07:06:14 -0500 )edit

Yes I did recompile the workspace before running the node but still got the error. Actually I was working on "The Construct rosject" and there I am getting this error. I tried the same on my laptop Ubuntu 20.04 with ros2 Foxy and it is working without any error, not sure why the error comes on "The Construct rosject" only.

Robo_guy gravatar image Robo_guy  ( 2023-01-15 16:27:05 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2023-01-03 20:13:36 -0500

Seen: 355 times

Last updated: Jan 03 '23