Segmentation Fault: exercise 5.1

I got this error, but have no idea how to figure out. The code below is pretty similar to the sample solution.
Still, the problem occurs.

#include “rosbot_control/rosbot_class.h”
#include <ros/ros.h>

#include

using namespace std;

class RosbotMove {

public:
RosbotMove(string turn) { this->left_or_right = turn; };
string left_or_right;
RosbotClass rosbot;
void avoid_wall();
};
void RosbotMove::avoid_wall() {

while (rosbot.get_laser(0) > 1.5) {
rosbot.move();
}
if (left_or_right == “left”) {

rosbot.turn("counterclockwise", 2);

} else {
rosbot.turn(“clockwise”, 2);
}
}

int main(int argc, char **argv) {
ros::init(argc, argv, “Rosbot_move_node”);
RosbotMove a(“left”);
a.avoid_wall();
}

Please let me know if I have missed something here.

The code you posted contains several syntax errors that need to be corrected in order to be compiled and run successfully.

List item

  1. The “#include” statement at line 6 is not needed and can be removed.

  2. The quotes used in the code are not valid and should be changed from “ to ":
    Change “left”” to “left”
    Change “clockwise”” to “clockwise”
    Change “counterclockwise” to “counterclockwise”
    Change “Rosbot_move_node” to “Rosbot_move_node”
    (basicly change quates to " " shape)

  3. The constructor of the RosbotMove class has a string argument that is not being used(at the end of code)
    you can have it like that:

RosbotMove a;
a.avoid_wall();

2 Likes