The rosbot.turn() function is not working

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();
}

Hi @athyobhide30,

Welcome to our community.

Can you tell us the number of the Unit that you are following, and the exercise number, so that we can know better what you are trying to achieve?

We need more context in order to better help you.

Cheers,

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