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