Segmentation fault - c++ for robotics - "Micro project" chapter7

Hello … I am currently suffering from segmentation fault.

I am currently working on “Microrobot”, the final project of C++ for Robotics.
I have actually created, compiled, and executed the original program.
However, I got the error “Segmentation fault” and tried to find the cause on the web, but could not solve the problem.

The code is shown below.

I would like to ask for your advice.

=========================================================================

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

using namespace std;

class RobotMove{
public:
RosbotClass rosbot;
void move_out();
float calc(float x_0,float y_0,float x_1,float y_1);
};

float RobotMove::calc(float x_0,float y_0,float x_1,float y_1){
return sqrt(pow((x_0 - x_1),2) + pow((y_0 - y_1),2));
}

void RobotMove::move_out(){
//ロボットが細い道を抜けるプログラム
while(rosbot.get_laser(0) > 2.0){
rosbot.move_forward(1);
}
rosbot.turn(“clockwise”,3);
rosbot.move_forward(2);
rosbot.turn(“counterclockwise”, 3);

//ドアの前まで移動するプログラム
float x_0 = rosbot.get_position(0);
float y_0 = rosbot.get_position(1);
float x_1 = x_0;
float y_1 = y_0;
while(calc(x_0,y_0,x_1,y_1) < 8.0){
    rosbot.move_forward(1);
    x_1 = rosbot.get_position(0);
    y_1 = rosbot.get_position(1);
}

rosbot.stop_moving();
//ROS_INFO_STREAM("success");

}

int main(int argc, char **argv){
ros::init(argc, argv, “RobotNode”);
RobotMove robomove;
robomove.move_out();
}

Hello @Eimyver3 ,

Isn’t there any extra data besides the Segmentation fault? Any other error message in the logs?

1 Like

Thank you for your reply.
The error message I get is Segmentation fault (core dumped).
I am getting the following error message.

I see,

This is a pretty tricky situation since it’s hard to debug due to the lack of information. I would suggest you start commenting/removing different parts of the code in order to find where this segmentation fault is coming from.

Also, could you share your package so that we can have a look at it?

Thank you for your generous support.

Of course, I have no problem sharing my package.

How can I share my package?