ROS Basics in 5 days (C++) 4.4 Topics Quiz Not subscribed to /kobuki/laser/scan

I don’t understand what I am doing wrong. The robot avoids an obstacle. The node name is correct (“topics_quiz_node”). No other programs are running.

#include <ros/ros.h>
#include <geometry_msgs/Twist.h>
#include <sensor_msgs/LaserScan.h>

float angVel = 0;

void laserCallback(const sensor_msgs::LaserScan::ConstPtr& laserScan)
  angVel = 0.0;

  ROS_INFO("Forward: %f", laserScan->ranges[360]);
  ROS_INFO("Left: %f", laserScan->ranges[719]);
  ROS_INFO("Right: %f", laserScan->ranges[719]);

  if (laserScan->ranges[360]<1.0) angVel = 0.5;
  if (laserScan->ranges[0]<1.0) angVel = 0.5;
  if (laserScan->ranges[719]<1.0) angVel = -0.5;

int main(int argc, char** argv) {

    ros::init(argc, argv, "topics_quiz_node");
    ros::NodeHandle nh;
    ros::Publisher pub = nh.advertise<geometry_msgs::Twist>("/cmd_vel", 1000);
    ros::Rate loop_rate(20);
    ros::Subscriber sub = nh.subscribe("/kobuki/laser/scan", 1000, laserCallback);
    geometry_msgs::Twist vel;

    vel.linear.x = 0.1;
    vel.angular.z = 0.0;
      while (ros::ok())
        vel.angular.z = angVel;

    return 0;

Hi @shatodor ,

Welcome to this Community!

Could you please explain briefly about your problem? What should happen and what is happening instead?

Since you seem to be working on topics_quiz_node, are you having issues getting your program graded? If so, could you post the GradeBot output / feedback as an image?


Hello @girishkumar.kannan

What is the node name you are using in your launch file? That would override the one defined in the C++ source. Can you paste your launch file here?

Hello @bayodesegun

Thanks, problem was in launch file. Mabe it worth adding this moment in Quiz checklist ?

    <node pkg="topics_quiz" type="topics_quiz" name="TP"  output="screen">

It should already be in the quiz checklist and was also mentioned by gradebot.


Don’t worry, it’s a common point of conflict in ROS. One would expect that the name defined in the source code would be respected, but ROS decided otherwise.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.