ValueError: Expected the full name of a message, got 'std_msgs/String'
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
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 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!
Please post your last edit as an answer.