ValueError: Expected the full name of a message, got 'std_msgs/String'

asked 2021-09-17 23:27:41 -0600

Den gravatar image

updated 2021-10-26 09:12:46 -0600

lucasw gravatar image

I tried following the tutorials from the ROS 2 wiki and it is working. The subscriber node is subscribing to the topic published by the publisher node. The message type is std_msgs/String and the topic is "/hello". I am coming from ROS 1 and I used to be able to do rostopic echo /hello.

However, in ROS 2 when I try ros2 topic echo /hello it gives the above ValueError. I can't figure out why though

Here is the sample of the code:

#include <chrono> 
#include <functional> 
#include <memory> 
#include <string> 

// This is the equivalent of #include ros/ros.h
#include "rclcpp/rclcpp.hpp"

// This is the equivalent of #include "std_msgs/String.h"
#include "std_msgs/msg/string.hpp" 

using namespace std::chrono_literals; 

class MinimalPublisher : public rclcpp::Node
{
    public:
        MinimalPublisher()
            : Node("minimal_publisher"), count_(0)
        {
            publisher_ = this->create_publisher<std_msgs::msg::String>("hello", 10); 
            timer_ = this->create_wall_timer(500ms, std::bind(&MinimalPublisher::timer_callback, this)); 
        }
    private:
        void timer_callback()
        {
            auto message = std_msgs::msg::String(); 
            message.data = "Hello Earth!" + 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; 
}

EDIT:

After restarting the PC and sourcing /opt/ros/foxy/setup.bash the ros2 topic echo /hello command is working!

ros2 topic echo /hello


data: Hello Earth!47

edit retag flag offensive close merge delete

Comments

I would suggest to include verbatim copy-pastes of commands and code you're using.

Paraphrasing or selectively showing errors / warnings is not a good idea, as it makes it difficult to understand what's going on.

gvdhoorn gravatar image gvdhoorn  ( 2021-09-18 02:28:47 -0600 )edit

@gvdhoorn alright, have updated the comment with the code. Although for some reason now it is working after restarting the entire PC and sourcing /opt/ros/foxy/setup.bash on start up!

Den gravatar image Den  ( 2021-09-18 04:09:45 -0600 )edit

Please post your last edit as an answer.

gvdhoorn gravatar image gvdhoorn  ( 2021-09-18 04:46:07 -0600 )edit