Hi, i’m doing the 4.4 Topics Quiz about avoiding the wall using Turtlebot.
If i got it right i have to write the whole publisher-subscriber behaviour in the same node aka .cpp script so i’m trying something like this.
int main(int argc, char **argv) {
ros::init(argc, argv, "topics_quiz_node");
ros::NodeHandle nh;
ros::Subscriber sub = nh.subscribe("/kobuki/laser/scan", 1000, wallAvoiderCallback);
ros::spin();
return 0;
}
while in my wallAvoiderCallback i’m trying to publish the velocity command based on the distance i sense.
void wallAvoiderCallback(const sensor_msgs::LaserScan::ConstPtr &msg) {
// ROS_INFO("Received %f", msg->ranges[360]); // it works
// defining the command object
geometry_msgs::Twist forward_command;
if (msg->ranges[360] > 1) {
forward_command.linear.x = 0.1;
}
ros::NodeHandle nh;
ros::Publisher pub = nh.advertise<geometry_msgs::Twist>("/cmd_vel", 1000);
ros::Rate loop_rate(2);
pub.publish(forward_command);
ros::spinOnce();
loop_rate.sleep();
}
it works for the first 5 seconds and then i get this error which terminates the node.
[topics_quiz_node-1] process has died [pid 38458, exit code -11, cmd /home/user/catkin_ws/devel/lib/topics_quiz/wall_avoider __name:=topics_quiz_node __log:=/home/user/.ros/log/3baf523a-f159-11eb-b55f-0242ac170008/topics_quiz_node-1.log].
log file: /home/user/.ros/log/3baf523a-f159-11eb-b55f-0242ac170008/topics_quiz_node-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done
Anybody has suggestion about how to complete the quiz? Thank you.