fatal error: serial/serial.h: no such file or directory in ros
Hello evrybody,
I'm using ROS kenetic and I'm trying to read data from serial port of my laptop. For this I use the code below and I use the header file serial.h to instantiate my serial object. When I execute Catkin_make it return' me this error :
/home/stage/catkin_ws/src/mon_noeud/src/Imu_node.cpp:2:27: fatal error: serial/serial.h: No such file or directory
compilation terminated.
mon_noeud/CMakeFiles/Imu_node.dir/build.make:62: recipe for target 'mon_noeud/CMakeFiles/Imu_node.dir/src/Imu_node.cpp.o' failed
make[2]: *** [mon_noeud/CMakeFiles/Imu_node.dir/src/Imu_node.cpp.o] Error 1
CMakeFiles/Makefile2:3488: recipe for target 'mon_noeud/CMakeFiles/Imu_node.dir/all' failed
make[1]: *** [mon_noeud/CMakeFiles/Imu_node.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2
I hope someone can help me with this
#include <ros/ros.h>
#include <serial/serial.h>
#include <std_msgs/String.h>
#include <std_msgs/Empty.h>
serial::Serial ser;
int main(int argc, char** argv){
ros::init(argc,argc,"Imu_node");
ros::NodeHandle nh;
ros::Publisher read_port = nh.advertise<std_msgs::String>("read", 1000);
ros::Rate loop_rate(200);
try
{
ser.setPort("/dev/ttyACM0");
ser.setBaudrate(9600);
serial::Timeout to = serial::Timeout::simpleTimeout(1000);
ser.setTimeout(to);
ser.open();
}
catch (serial::IOException& e)
{
ROS_ERROR_STREAM("Unable to open port ");
return -1;
}
if(ser.isOpen()){
ROS_INFO_STREAM("serial port initialized");
}
else{
return -1;
}
while(ros::ok()){
if(ser.available()){
ROS_INFO_STREAM("reading from serial port ");
std_msgs::String result;
result.data = ser.read(ser.available());
ROS_INFO_STREAM("Read: " << result.data);
read_pub.publish(result);
}
ros::spinOnce();
r.sleep();
}
}
Edit:
this first code is the cmakelist :
cmake_minimum_required(VERSION 2.8.3)
project(mon_noeud)
find_package(catkin REQUIRED COMPONENTS
message_generation
message_runtime
roscpp
rospy
serial
)
catkin_package(
# INCLUDE_DIRS include
# LIBRARIES mon_noeud
# CATKIN_DEPENDS message_generation message_runtime roscpp rospy
# DEPENDS system_lib
)
include_directories(include)
set(serial_SRCS serial/src/serial.cc include/serial/serial.h include/serial/v8stdint.h)
if(UNIX)
list(APPEND serial_SRCS src/impl/unix.cc)
else()
list(APPEND serial_SRCS src/impl/win.cc)
endif()
## Add serial library
add_library(serial ${serial_SRCS})
if(UNIX AND NOT APPLE)
target_link_libraries(serial rt)
endif()
add_executable(Imu_node src/Imu_node.cpp)
target_link_libraries(Imu_node serial)
target_link_libraries(Imu_node ${catkin_LIBRARIES})
and this one for the package.xml
<package format="2"><name>mon_noeud</name><version>0.0.0</version><description>The mon_noeud package</description><maintainer email="stage@todo.todo">stage</maintainer><license>TODO</license>
<buildtool_depend>catkin</buildtool_depend><build_depend>message_generation</build_depend><build_depend>message_generation</build_depend><build_depend>roscpp</build_depend><build_depend>rospy</build_depend><build_export_depend>roscpp</build_export_depend><build_export_depend>rospy</build_export_depend><exec_depend>message_runtime</exec_depend><exec_depend>roscpp</exec_depend><exec_depend>rospy</exec_depend><!-- The export tag contains other, unspecified, tags --><export><!----></export></package>
the error after addind the serial object to the package.xml and Cmakelist.txt :
Could not find a package configuration file provided by "serial" with any
of the following names:
serialConfig.cmake
serial-config.cmake
Add the installation prefix of "serial" to CMAKE_PREFIX_PATH or set
"serial_DIR" to a directory containing one of the above files. If "serial"
provides a separate development package or SDK, be sure it has been
installed.
Call Stack (most recent call first):
mon_noeud/CMakeLists.txt:10 (find_package)
-- Could not find the required component 'serial'. The following CMake error indicates that you either need to install ...
For your last question, that should because you didn't install the "serial" package. Install it using " sudo apt install ros-kinetic-serial ". Or install from the source code.
No, I have installed that package but there is a problem in the path to the serial.h file
Please
edit
your question and show us your currentCMakeLists.txt
.The last error message that you've shown ("cannot find pkg cfg file for
serial
") suggests that the package is not (properly) installed.We're not even getting to the point where the path to
serialh.h
is incorrect.The CmakeLists.txt is edited now
Ok, I will search slowly in my directories to see what's wrong with the installation
It's more likely that things weren't working because your
CMakeLists.txt
was not correct.See the latest edit of my answer.
Ok, thank you very much. I will post I comment when I resolve it
Just mark the question as solved by clicking on the checkmark to the left of the answer.