Unable to import sensor_msgs in ros2 publisher code ?
I am actually trying to wrap a IMU driver in ROS2 environment . I have the requirement to import sensor_msgs/IMU . However I am not able to import it in my current code.
NOTE:- I have installed foxy in 18.04 by source.
I get the following error
No such file or directory #include "sensor_msgs/msg/Imu.hpp" .
Attaching code for reference.
#include <chrono>
#include <functional>
#include <memory>
#include <string>
#include "master_board_sdk/master_board_interface.h"
#include "master_board_sdk/defines.h"
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"
#include "sensor_msgs/msg/Imu.hpp"
using namespace std::chrono_literals;
/* This example creates a subclass of Node and uses std::bind() to register a
* member function as a callback from the timer. */
class MinimalPublisher : public rclcpp::Node
{
public:
MinimalPublisher()
: Node("minimal_publisher"), count_(0)
{
publisher_ = this->create_publisher<sensor_msgs::msg::Imu>("/imu", 10);
timer_ = this->create_wall_timer(
1ms, std::bind(&MinimalPublisher::timer_callback, this));
}
private:
void timer_callback()
{
auto message = sensor_msgs::msg::Imu();
//message.data = "Hello, world! " + std::to_string(count_++);
//RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", message.data.c_str());
publisher_->publish(message);
}
rclcpp::TimerBase::SharedPtr timer_;
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;
size_t count_;
};
int main(int argc, char * argv[])
{
rclcpp::init(argc, argv);
rclcpp::spin(std::make_shared<MinimalPublisher>());
rclcpp::shutdown();
return 0;
}