Unit 4 : fatal error: geometry_msgs/Twist: No such file or directory

Hi !

I am studying ROS1 course. I am stuck with this error message when i build with catkin_make :

fatal error: geometry_msgs/Twist: No such file or directory
1 | #include <geometry_msgs/Twist>

I also have included the dependency in package.xml

image

also i have added the required lines in Cmakelists :

find_package(catkin REQUIRED COMPONENTS
  roscpp
  std_msgs
  geometry_msgs
)

catkin_package(
#  INCLUDE_DIRS include
#  LIBRARIES topic_publisher_pkg
#  CATKIN_DEPENDS roscpp std_msgs
#  DEPENDS system_lib
   CATKIN_DEPENDS roscpp std_msgs geometry_msgs
)
include_directories(
# include
  ${catkin_INCLUDE_DIRS}
)


add_executable(simple_topic_publisher src/simple_topic_publisher.cpp)
add_executable(publisher_1 src/publisher_1.cpp)

add_dependencies(simple_topic_publisher ${simple_topic_publisher_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})
add_dependencies(publisher_1 ${publisher_1_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(simple_topic_publisher
  ${catkin_LIBRARIES}
)
target_link_libraries(publisher_1
  ${catkin_LIBRARIES}
)

I also have confirmed that geometry_msgs is in the system path

here is my code :

#include <geometry_msgs/Twist>
#include <ros/ros.h>
#include <std_msgs/float64.h>
// Import all the necessary ROS libraries and import the Int32 message from the
// std_msgs package

int main(int argc, char **argv) {

  ros::init(
      argc, argv,
      "velocity_publisher_node"); // Initiate a Node named 'topic_publisher'
  ros::NodeHandle nh;

  ros::Publisher pub = nh.advertise<geometry_msgs::Twist>(
      "cmd_vel", 1000);   // Create a Publisher object, that will // publish on
                          // the /counter topic messages of type float64
  ros::Rate loop_rate(2); // Set a publish rate of 2 Hz

  geometry_msgs::Twist velocity; // Create a variable of type Int32
  velocity.linear.x = 0.5;       // Initialize 'velocity' variable
  velocity.angular.z = 0;

  while (ros::ok()) // Create a loop that will go until someone stops the
                    // program execution
  {
    pub.publish(velocity); // Publish the message within the 'count' variable
    ros::spinOnce();
    loop_rate.sleep(); // Make sure the publish rate maintains at 2 Hz
  }

  return 0;
}

Can anyone please guide me :slight_smile:

Best ,
Muhammad

There’s a typo in your include. It should be:

#include <geometry_msgs/Twist.h>

The .h part was missing.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.