Even when I use the code given in the answer, the bot is not turning and only moves forward. It also is not printing the get laser values.
This is my code:
#include "rosbot_control/rosbot_class.h"
#include <iostream>
#include <ros/ros.h>
#include <string>
using namespace std;
class Detection {
public:
RosbotClass rosbot;
Detection(string a) { choice_dir = a; }
string choice_dir;
void detect() {
float c_dist = 0.5;
rosbot.move_forward(1);
while (rosbot.get_laser(0) >= c_dist) {
ROS_INFO_STREAM("The distance ahead of the robot is"
<< rosbot.get_laser(0));
rosbot.move_forward(1);
}
if (choice_dir == "left") {
rosbot.turn("counterclockwise", 3);
rosbot.move_forward(5);
} else if (choice_dir == "right") {
rosbot.turn("clockwise", 3);
rosbot.move_forward(5);
} else {
ROS_INFO_STREAM("Specify left or right please.");
}
}
};
int main(int argc, char **argv) {
ros::init(argc, argv, "rosbot_detect_node");
Detection rosbot_left("left");
rosbot_left.detect();
}