ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

can't locate node [my_imu] in package [imu_localisation]

asked 2019-07-26 10:03:55 -0500

Aerugo2272 gravatar image

updated 2019-07-27 12:24:53 -0500

jayess gravatar image

I've been trying to make a simple cpp code that does the double integration for an IMU to return the estimated position. The package imu_localisation is listed in rospack list, and roslaunch finds the package and the launch file as well. However when I try to launch it I am hit with:

ERROR: cannot launch node of type [imu_localisation/my_imu]: can't locate node [my_imu] in package [imu_localisation]

I've tried catkin_make and source devel/setup.bash in that order multiple times to no avail. The error occurs when I run

roslaunch imu_localisation localise.launch

The following is the my_imu.cpp code.

#include "ros/ros.h"
#include "std_msgs/String.h"
#include "sensor_msgs/Imu.h"
#include "geometry_msgs/Vector3.h"
#include "nav_msgs/Odometry.h"

sensor_msgs::Imu prev_imu;

void imuCallback(const sensor_msgs::Imu::ConstPtr& imu){
  prev_imu.linear_acceleration.x = imu->linear_acceleration.x;
  prev_imu.linear_acceleration.y = imu->linear_acceleration.y;
  prev_imu.linear_acceleration.z = imu->linear_acceleration.z;

}

int main(int argc, char **argv){
  ros::init(argc, argv, "my_imu");
  double samplePeriod = 0.02;
  ros::NodeHandle nh;
  geometry_msgs::Vector3 vel,prev_vel,pos,prev_pos;
  ros::Publisher pos_pub=nh.advertise<nav_msgs::Odometry>("/odom",1);
  ros::Subscriber imu_sub=nh.subscribe("/imu/data" , 50, imuCallback);
  ros::Rate loop_rate(50);

  while(ros::ok()){
    std_msgs::String msgs;
    if(prev_vel.x == 0){
      prev_vel.x = prev_imu.linear_acceleration.x * samplePeriod;
      prev_vel.y = prev_imu.linear_acceleration.y * samplePeriod;
      prev_vel.z = prev_imu.linear_acceleration.z * samplePeriod;
    }
    //
    vel.x = prev_vel.x + prev_imu.linear_acceleration.x * samplePeriod;
    vel.y = prev_vel.y + prev_imu.linear_acceleration.y * samplePeriod;
    vel.z = prev_vel.z + prev_imu.linear_acceleration.z * samplePeriod;
    ROS_INFO("vel x : %f", vel.x);
    pos.x = prev_pos.x + vel.x * samplePeriod;
    pos.y = prev_pos.y + vel.y * samplePeriod;
    pos.z = prev_pos.z + vel.z * samplePeriod;
    ROS_INFO("pos x : %f", pos.x);

    prev_vel = vel;
    prev_pos = pos;
    loop_rate.sleep();
  }

}

And here is my launch file localise.launch

<launch>

  <node pkg="imu_localisation" name="my_imu" type="my_imu" output="screen">
  </node>
</launch>

And the CMakeLists.txt

cmake_minimum_required(VERSION 2.8.3)
project(imu_localisation)

find_package(catkin REQUIRED COMPONENTS
  geometry_msgs
  roscpp
  rospy
  sensor_msgs
  std_msgs
)

catkin_package()

include_directories(
  ${catkin_INCLUDE_DIRS}
)

add_executable(imu_localisation src/my_imu.cpp)
add_dependencies(imu_localisation ${imu_localisation_EXPORTED_TARGETS} ${catkin_EXPORTED_TARGETS})

target_link_libraries(imu_localisation
  ${catkin_LIBRARIES}
)

Any pointers? I'm sure I'm missing something dead simple here.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-07-27 05:01:55 -0500

There is a small error in your CMakeLists.txt file:

## Declare a C++ executable
## With catkin_make all packages are built within a single CMake context
## The recommended prefix ensures that target names across packages don't collide
add_executable(imu_localisation src/my_imu.cpp)

This section is telling catkin_make to build the src/my_imu.cpp code into a node called imu_localisation, you're launch file is looking for a node called my_imu which is never being created.

If you update this line as shown below and rebuild your package this should start working.

add_executable(my_imu src/my_imu.cpp)

Hope this helps.

edit flag offensive delete link more

Comments

Thanks that worked! Small note, had to change the name in "add_dependencies" and "target_link_libraries" as well to my node name rather than the package name catkin_create_package gives it by default.

Aerugo2272 gravatar image Aerugo2272  ( 2019-07-29 03:38:43 -0500 )edit

That is very true, I missed that one.

Glad it's fixed.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2019-07-30 02:56:24 -0500 )edit

Question Tools

Stats

Asked: 2019-07-26 10:03:55 -0500

Seen: 699 times

Last updated: Jul 27 '19