Problem with 4.4 Quiz correction. Checking that you are publishing in /cmd_vel

Hi there!
I’m doing the 4.4 quiz and, although all works fine on gazebo when I launch the program, the auto-corrector detect an error in the information being published to /cmd_vel. Maybe I’m missing something in the process. Here is the code and the log error of ten corrector:

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

float globVar[3] = {0};

void counterCallback(const sensor_msgs::LaserScan::ConstPtr &msg) {
  globVar[0] = msg->ranges[719];
  globVar[1] = msg->ranges[360];
  globVar[2] = msg->ranges[0];
  ROS_INFO("\nIzq:%f \nCent:%f \nDer:%f \n", globVar[0], globVar[1],

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

  ros::init(argc, argv, "topic_quiz_node");
  ros::NodeHandle nh;

  ros::Publisher pub = nh.advertise<geometry_msgs::Twist>("cmd_vel", 1000);

  ros::Subscriber sub =
      nh.subscribe("/kobuki/laser/scan", 1000, counterCallback);

  ros::Rate loop_rate(0.5);
  geometry_msgs::Twist var;
  var.linear.x = 0.5;

  while (ros::ok()) {
    if (globVar[1] < 1) {
      var.angular.z += 0.5;
    } else if (globVar[0] < 1) {
      var.angular.z -= 0.5;
    } else if (globVar[2] < 1) {
      var.angular.z += 0.5;
    } else {
      var.angular.z = 0.0;
  var.linear.x = 0.0;
  var.angular.z = 0.0;

  return 0;
 ✔ [info] Setting up ROS environment (mark: 0)

✔ [info] ROS environment setup is okay (mark: 0)

✔ [assess] topics_quiz package found (mark: 1.0)

✔ [info] compiling package topics_quiz... (mark: 1.0)

✔ [assess] topics_quiz package compiled successfully (mark: 3.0)

✔ [info] Seeing if the package can be launched... (mark: 3.0)

✔ [assess] Can launch topics_quiz package successfully (mark: 4.0)

✔ [info] Checking that the laser scanner is engaged... (mark: 4.0)

✔ [assess] Correctly subscribed to /kobuki/laser/scan (mark: 6.0)

✔ [info] Expecting the robot to move... (mark: 6.0)

✖ [assess] Not publishing to /cmd_vel. Let's fix this before we continue.
Things your can check:
- Did you create a publisher correctly in your source code?
- Is the logic correct, such that the publisher gets to publish?
- Run rostopic echo /cmd_vel and confirm that you have some data there. (mark: 6.0) 

Dis you try putting “/cmd_vel” instead of just “cmd_vel”?
PS: I’m doing it in python

Yep, I tried 3 different variations in code (/cmd_vel, change the values published and original) and same error :frowning:

Did you check it though before getting it corrected? if it worked in your workspace then should work with the grading bot too.

It seems that your code is not moving the robot on time. Could you please check that?

Ideally the robot should start moving almost immediately your package is launched but now it seems it’s taking longer than 10 seconds to move.

1 Like

As @bayodesegun said, the robot didn’t move exactly when you launched the code so I started to test what could be the reason.
I wondered why I put such a small refresh rate here:

 ros::Rate loop_rate(0.5);

So, I changed the value to a rate of 10 Hz. The code works as intended after this and the autocheck goes through the whole process.

1 Like

This topic was automatically closed after 21 hours. New replies are no longer allowed.