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],
globVar[2]);
}
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()) {
pub.publish(var);
ros::spinOnce();
loop_rate.sleep();
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)