'Subscriber for ros2arduino publisher example?
I want to establish a WiFi-connection between an arduino wifi-board and a computer with ROS2. For the arduino-side I found the ros2arduino library, which has some examples for publisher nodes. Unfortunately I could not find the correponding subscriber part for the subscriber. Because I am new to ros2, I don't know how to implement the corresponding subscriber.
My first idea to echo the publisher with this command:
ros2 topic echo /arduino_chatter
does not find the publisher. This is the error message:
WARNING: topic [/arduino_chatter] does not appear to be published yet
Could not determine the type for the passed topic
How has the subscriber to be implemented in ros2?
Thank you!
Here is the example code included in the arduino library:
#include <ros2arduino.h>
#include <WiFi.h>
#include <WiFiClient.h>
#define SSID "xxx"
#define SSID_PW "yyy"
#define AGENT_IP "192.168.1.0"
#define AGENT_PORT 2018 //AGENT port number
#define PUBLISH_FREQUENCY 2 //hz
void publishString(std_msgs::String* msg, void* arg)
{
(void)(arg);
static int cnt = 0;
sprintf(msg->data, "Hello ros2arduino %d", cnt++);
}
class StringPub : public ros2::Node
{
public:
StringPub()
: Node("ros2arduino_pub_node")
{
ros2::Publisher<std_msgs::String>* publisher_ = this->createPublisher<std_msgs::String>("arduino_chatter");
this->createWallFreq(PUBLISH_FREQUENCY, (ros2::CallbackFunc)publishString, nullptr, publisher_);
}
};
WiFiClient client;
void setup()
{
WiFi.begin(SSID, SSID_PW);
while(WiFi.status() != WL_CONNECTED);
ros2::init(&client, AGENT_IP, AGENT_PORT);
}
void loop()
{
static StringPub StringNode;
ros2::spin(&StringNode);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
