I need help, I have a basic error with kabuki and cmd_vel
I want to make the robot move towards a wall. When approaching the wall, the robot must turn left to avoid it. Please see the code below. The build has no errors, but it doesn't run.
topics_quiz_node.cpp
#include "geometry_msgs/Twist.h"
#include "ros/init.h"
#include "ros/node_handle.h"
#include "ros/publisher.h"
#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>
// float vel_pub;
void FuncCall(const sensor_msgs::LaserScan::ConstPtr &msg) {
ROS_INFO("LaserScan (val,angle)=(%f,%f", msg->range_min, msg->angle_min);
}
int main(int argc, char **argv) {
ros::init(argc, argv, "topics_quiz_node");
ros::NodeHandle robot;
ros::Publisher vel_pub =
robot.advertise<geometry_msgs::Twist>("/cmd_vel", 100);
ros::Subscriber laser_sub =
robot.subscribe("/kobuki/laser/scan", 10, FuncCall);
while (ros::ok()) {
geometry_msgs::Twist msg;
sensor_msgs::LaserScan lsr;
msg.linear.x = 0;
msg.angular.x = 0;
if (lsr.ranges[0] < 1.0) {
msg.linear.x = 0;
msg.angular.x = 0.5;
} else {
msg.linear.x = 0.5;
msg.angular.x = 0;
}
msg.linear.y = 0;
msg.linear.z = 0;
msg.angular.y = 0;
msg.angular.z = 0;
vel_pub.publish(msg);
ros::spin();
}
return 0;
}
topics_quiz.launch
<launch>
<!--topics quiz launch file-->
<node pkg="topics_quiz" type="topics_quiz_node" name="topics_quiz_node">
</node>
</launch>
use:
roslaunch topics_quiz topics_quiz.launch
Error :
user:~/catkin_ws$ roslaunch topics_quiz topics_quiz.launch
... logging to /home/user/.ros/log/331fdf62-27a0-11ed-af3f-0242ac150008/roslaunch-2_xterm-8759.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://2_xterm:41403/
SUMMARY
========
PARAMETERS
* /rosdistro: noetic
* /rosversion: 1.15.9
NODES
/
topics_quiz_node (topics_quiz/topics_quiz_node)
ROS_MASTER_URI=http://2_simulation:11311
process[topics_quiz_node-1]: started with pid [8767]
[topics_quiz_node-1] process has died [pid 8767, exit code -11, cmd /home/user/catkin_ws/devel/lib/topics_quiz/topics_quiz_node __name:=topics_quiz_node __log:=/home/user/.ros/log/331fdf62-27a0-11ed-af3f-0242ac150008/topics_quiz_node-1.log].
log file: /home/user/.ros/log/331fdf62-27a0-11ed-af3f-0242ac150008/topics_quiz_node-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done
Compilation shows no error as shown below:
user:~/catkin_ws$ catkin_make
Base path: /home/user/catkin_ws
Source space: /home/user/catkin_ws/src
Build space: /home/user/catkin_ws/build
Devel space: /home/user/catkin_ws/devel
Install space: /home/user/catkin_ws/install
####
#### Running command: "cmake /home/user/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/user/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/user/catkin_ws/install -G Unix Makefiles" in "/home/user/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/user/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/user/catkin_ws/devel;/home/simulations/public_sim_ws/devel;/opt/ros/noetic
-- This workspace overlays: /home/user/catkin_ws/devel;/home/simulations/public_sim_ws/devel;/opt/ros/noetic
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.5", minimum required is "3")
-- Using PYTHON_EXECUTABLE: /usr/bin/python3
-- Using Debian Python package layout
-- Using empy: /usr/lib/python3/dist-packages/em.py
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/user/catkin_ws/build/test_results
-- Forcing gtest/gmock from source, though one was otherwise available.
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built ...