Skip to content

Commit 5e762f4

Browse files
author
Kei
authored
Merge pull request #25 from ROBOTIS-GIT/node_name_add_function
Node name add function
2 parents f5bbe2d + 07e785d commit 5e762f4

File tree

15 files changed

+95
-67
lines changed

15 files changed

+95
-67
lines changed

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Arduino library for communicating with ROS2(DDS)
99

1010
|ros2arduino|ROS2|Micro-XRCE-DDS Agent|
1111
|:-:|:-:|:-:|
12-
|0.1.0|[Dashing Diademata](https://github.com/ros2/ros2/releases/tag/release-dashing-20190531)|[1.1.0](https://github.com/eProsima/Micro-XRCE-DDS-Agent/releases/tag/v1.1.0)|
12+
|0.1.1|[Dashing Diademata](https://github.com/ros2/ros2/releases/tag/release-dashing-20190531)|[1.1.0](https://github.com/eProsima/Micro-XRCE-DDS-Agent/releases/tag/v1.1.0)|
1313

1414
For the Micro-XRCE-DDS Agent, please install it using following commands.
1515
```bash
@@ -26,7 +26,7 @@ $ sudo ldconfig /usr/local/lib/
2626

2727
|ros2arduino|ROS2|Micro-XRCE-DDS Agent|
2828
|:-:|:-:|:-:|
29-
|0.1.0|[Dashing Diademata](https://github.com/ros2/ros2/releases/tag/release-dashing-20190531)|[1.1.0](https://github.com/eProsima/Micro-XRCE-DDS-Agent/releases/tag/v1.1.0)|
29+
|0.1.1|[Dashing Diademata](https://github.com/ros2/ros2/releases/tag/release-dashing-20190531)|[1.1.0](https://github.com/eProsima/Micro-XRCE-DDS-Agent/releases/tag/v1.1.0)|
3030
|0.0.9|[Crystal Clemmys](https://github.com/ros2/ros2/releases/tag/release-crystal-20181214)|[1.0.1](https://github.com/eProsima/Micro-XRCE-DDS-Agent/releases/tag/v1.0.1)|
3131

3232
<br>
@@ -109,10 +109,15 @@ You must install ROS2 and XRCE-DDS Agent. (The version should be the same as the
109109
$ ros2 topic echo /arduino_chatter
110110
```
111111

112-
#### Appendix: How to configure entities from reference file. (available at 0.1.0 or above)
112+
#### Appendix: How to configure entities from reference file. (available at 0.1.1 or above)
113113
- Use the reference method supported by Client and Agent. Please refer to [eProsima manual](https://micro-xrce-dds.readthedocs.io/en/latest/agent.html#run-an-agent) for detailed usage.
114-
- In addition, you need to change the settings in ros2arduino.
115-
- In the [user_config.h](https://github.com/ROBOTIS-GIT/ros2arduino/blob/master/src/user_config.h) file, you must comment out `#define UXR_CREATE_ENTITIES_USING_XML` to use the reference method.
114+
- For this feature, You need to change the settings(code) in ros2arduino library.
115+
- In the [user_config.h](https://github.com/ROBOTIS-GIT/ros2arduino/blob/master/src/user_config.h) file, you must set the value of UXR_CREATE_ENTITIES_USING_REF to 1 like below.
116+
```cpp
117+
#define UXR_CREATE_ENTITIES_USING_REF 1
118+
#define USER_ROS2_PUBLISHER_MAX 10
119+
#define USER_ROS2_SUBSCRIBER_MAX 10
120+
```
116121

117122
For example, create .refs file(in XML format) and run the Agent with the following options:
118123
```bash
@@ -121,9 +126,9 @@ $ MicroXRCEAgent serial --dev /dev/ttyACM0 -b 115200 -r ros2arduino.refs
121126
- ros2arduino.refs
122127
```xml
123128
<profiles>
124-
<participant profile_name="ros2_xrcedds_participant">
129+
<participant profile_name="ros2arduino_xml_node">
125130
<rtps>
126-
<name>ros2_xrcedds_participant</name>
131+
<name>ros2arduino_basic_node</name>
127132
<builtin>
128133
<domainId>0</domainId>
129134
</builtin>

examples/publisher/publisher.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class StringPub : public ros2::Node
1616
{
1717
public:
1818
StringPub()
19-
: Node()
19+
: Node("ros2arduino_pub_node")
2020
{
2121
ros2::Publisher<std_msgs::String>* publisher_ = this->createPublisher<std_msgs::String>("arduino_chatter");
2222
this->createWallFreq(PUBLISH_FREQUENCY, (ros2::CallbackFunc)publishString, nullptr, publisher_);

examples/publisher_ethernet_tcp/publisher_ethernet_tcp.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class StringPub : public ros2::Node
2424
{
2525
public:
2626
StringPub()
27-
: Node()
27+
: Node("ros2arduino_pub_node")
2828
{
2929
ros2::Publisher<std_msgs::String>* publisher_ = this->createPublisher<std_msgs::String>("arduino_chatter");
3030
this->createWallFreq(PUBLISH_FREQUENCY, (ros2::CallbackFunc)publishString, nullptr, publisher_);

examples/publisher_ethernet_udp/publisher_ethernet_udp.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class StringPub : public ros2::Node
2424
{
2525
public:
2626
StringPub()
27-
: Node()
27+
: Node("ros2arduino_pub_node")
2828
{
2929
ros2::Publisher<std_msgs::String>* publisher_ = this->createPublisher<std_msgs::String>("arduino_chatter");
3030
this->createWallFreq(PUBLISH_FREQUENCY, (ros2::CallbackFunc)publishString, nullptr, publisher_);

examples/publisher_wifi_tcp/publisher_wifi_tcp.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class StringPub : public ros2::Node
2121
{
2222
public:
2323
StringPub()
24-
: Node()
24+
: Node("ros2arduino_pub_node")
2525
{
2626
ros2::Publisher<std_msgs::String>* publisher_ = this->createPublisher<std_msgs::String>("arduino_chatter");
2727
this->createWallFreq(PUBLISH_FREQUENCY, (ros2::CallbackFunc)publishString, nullptr, publisher_);

examples/publisher_wifi_udp/publisher_wifi_udp.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class StringPub : public ros2::Node
2121
{
2222
public:
2323
StringPub()
24-
: Node()
24+
: Node("ros2arduino_pub_node")
2525
{
2626
ros2::Publisher<std_msgs::String>* publisher_ = this->createPublisher<std_msgs::String>("arduino_chatter");
2727
this->createWallFreq(PUBLISH_FREQUENCY, (ros2::CallbackFunc)publishString, nullptr, publisher_);

examples/subscriber/subscriber.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class LedSub : public ros2::Node
1313
{
1414
public:
1515
LedSub()
16-
: Node()
16+
: Node("ros2arduino_sub_node")
1717
{
1818
this->createSubscriber<std_msgs::Bool>("arduino_led", (ros2::CallbackFunc)subscribeLed, nullptr);
1919
}

src/ros2/publisher.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ class Publisher:public PublisherHandle
5757

5858
void recreate()
5959
{
60-
#ifdef UXR_CREATE_ENTITIES_USING_XML
60+
#if (UXR_CREATE_ENTITIES_USING_REF)
61+
is_registered_ = xrcedds::createDataWriter(publisher_, &data_writer_, (char*)name_, topic_.type_);
62+
#else
6163
char writer_name[64];
6264
sprintf(writer_name, "%s/%s", getPrefixString(TOPICS_PUBLISH), name_);
63-
is_registered_ = xrcedds::createDataWriter(publisher_, &data_writer_, writer_name, topic_.type_);
64-
#else
65-
is_registered_ = xrcedds::createDataWriter(publisher_, &data_writer_, (char*)name_, topic_.type_);
65+
is_registered_ = xrcedds::createDataWriter(publisher_, &data_writer_, writer_name, topic_.type_);
6666
#endif
6767
}
6868

src/ros2/ros2.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void ros2::runNodeSubUserCallback(uint16_t id, void* msgs, void* args)
125125

126126

127127
/* Node class */
128-
ros2::Node::Node()
128+
ros2::Node::Node(const char* node_name)
129129
{
130130
pub_cnt_ = 0, sub_cnt_ = 0, node_register_state_ = false;
131131
for(size_t i = 0; i < ROS2_PUBLISHER_MAX; i++)
@@ -136,10 +136,10 @@ ros2::Node::Node()
136136
{
137137
sub_list_[i] = nullptr;
138138
}
139-
this->recreate();
139+
this->recreate(node_name);
140140
}
141141

142-
void ros2::Node::recreate()
142+
void ros2::Node::recreate(const char* node_name)
143143
{
144144
xrcedds_participant_.is_created = false;
145145
xrcedds_transport_.type = g_client_communication_method;
@@ -165,8 +165,7 @@ void ros2::Node::recreate()
165165
xrcedds::initTransportAndSession(&xrcedds_transport_,
166166
(void*) runNodeSubUserCallback, (void*) this);
167167

168-
node_register_state_ = xrcedds::createParticipant(&this->xrcedds_participant_,
169-
"ros2_xrcedds_participant");
168+
node_register_state_ = xrcedds::createParticipant(&this->xrcedds_participant_, node_name);
170169

171170
xrcedds::createPublisher(&this->xrcedds_participant_,
172171
&this->xrcedds_publisher_);

src/ros2/ros2.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include "topic.hpp"
1515
#include "msg_list.hpp"
1616

17-
#include <user_config.h>
18-
1917
#define ROS2_PUBLISHER_MAX USER_ROS2_PUBLISHER_MAX
2018
#define ROS2_SUBSCRIBER_MAX USER_ROS2_SUBSCRIBER_MAX
2119

@@ -26,10 +24,10 @@ void runNodeSubUserCallback(uint16_t id, void* msgs, void* args);
2624
class Node
2725
{
2826
public:
29-
Node();
27+
Node(const char* node_name = "ros2_xrcedds_participant");
3028
virtual ~Node(){};
3129

32-
void recreate();
30+
void recreate(const char* node_name = "ros2_xrcedds_participant");
3331
void createWallTimer(uint32_t msec, CallbackFunc callback, void* callback_arg, PublisherHandle* pub);
3432
void createWallFreq(uint32_t hz, CallbackFunc callback, void* callback_arg, PublisherHandle* pub);
3533
void runPubCallback();

src/ros2/subscriber.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ class Subscriber:public SubscriberHandle
5757

5858
void recreate()
5959
{
60-
#ifdef UXR_CREATE_ENTITIES_USING_XML
60+
#if (UXR_CREATE_ENTITIES_USING_REF)
61+
is_registered_ = xrcedds::createDataReader(subscriber_, &data_reader_, (char*)name_, topic_.type_);
62+
#else
6163
char reader_name[64];
6264
sprintf(reader_name, "%s/%s", getPrefixString(TOPICS_SUBSCRIBE), name_);
63-
is_registered_ = xrcedds::createDataReader(subscriber_, &data_reader_, reader_name, topic_.type_);
64-
#else
65-
is_registered_ = xrcedds::createDataReader(subscriber_, &data_reader_, (char*)name_, topic_.type_);
65+
is_registered_ = xrcedds::createDataReader(subscriber_, &data_reader_, reader_name, topic_.type_);
6666
#endif
6767
this->reader_id_ = data_reader_.id;
6868
};

src/ros2/xrcedds/micro_xrce_dds/micro_xrce_dds_xml.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <stdio.h>
1212
#include <uxr/client/config.h>
1313

14-
#ifdef UXR_CREATE_ENTITIES_USING_XML
14+
#if (UXR_CREATE_ENTITIES_USING_REF == 0)
1515
#define UXR_PARTICIPANT_XML "<dds><participant><rtps><name>%s</name></rtps></participant></dds>"
1616
#define UXR_WRITER_XML "<dds><data_writer><topic><kind>NO_KEY</kind><name>%s</name><dataType>%s</dataType></topic></data_writer></dds>"
1717
#define UXR_READER_XML "<dds><data_reader><topic><kind>NO_KEY</kind><name>%s</name><dataType>%s</dataType></topic></data_reader></dds>"

src/ros2/xrcedds/xrcedds.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#define BUFFER_SIZE 4096
2020
static uint8_t output_best_effort_stream_buffer[BUFFER_SIZE * UXR_CONFIG_MAX_OUTPUT_BEST_EFFORT_STREAMS];
2121
#else
22-
#define STREAM_HISTORY 1
23-
#define BUFFER_SIZE 4096 * STREAM_HISTORY
22+
#define STREAM_HISTORY 4
23+
#define BUFFER_SIZE 2048 * STREAM_HISTORY
2424
static uint8_t output_reliable_stream_buffer[BUFFER_SIZE * UXR_CONFIG_MAX_OUTPUT_RELIABLE_STREAMS];
2525
static uint8_t input_reliable_stream_buffer[BUFFER_SIZE * UXR_CONFIG_MAX_INPUT_RELIABLE_STREAMS];
2626
#endif
@@ -167,12 +167,12 @@ bool xrcedds::createParticipant(xrcedds::Participant_t* participant, const char*
167167
participant->id = participant_id++;
168168
uxrObjectId part_object_id = uxr_object_id(participant->id, UXR_PARTICIPANT_ID);
169169

170-
#ifdef UXR_CREATE_ENTITIES_USING_XML
170+
#if (UXR_CREATE_ENTITIES_USING_REF)
171+
participant_req = uxr_buffer_create_participant_ref(&g_uxr_session.session, getOutputStreamInfo(), part_object_id, 0, participant_name, UXR_REPLACE);
172+
#else
171173
char participant_profile[256];
172174
sprintf(participant_profile, UXR_PARTICIPANT_XML, participant_name);
173175
participant_req = uxr_buffer_create_participant_xml(&g_uxr_session.session, getOutputStreamInfo(), part_object_id, 0, participant_profile, UXR_REPLACE);
174-
#else
175-
participant_req = uxr_buffer_create_participant_ref(&g_uxr_session.session, getOutputStreamInfo(), part_object_id, 0, participant_name, UXR_REPLACE);
176176
#endif
177177

178178
participant->is_created = uxr_run_session_until_all_status(&g_uxr_session.session, 1000, &participant_req, &status, 1);
@@ -194,13 +194,14 @@ bool xrcedds::registerTopic(xrcedds::Participant_t* participant, const char* top
194194
uxrObjectId part_object_id = uxr_object_id(participant->id, UXR_PARTICIPANT_ID);
195195
uxrObjectId topic_object_id = uxr_object_id(topic_id, UXR_TOPIC_ID);
196196

197-
#ifdef UXR_CREATE_ENTITIES_USING_XML
197+
#if (UXR_CREATE_ENTITIES_USING_REF)
198+
topic_req = uxr_buffer_create_topic_ref(&g_uxr_session.session, getOutputStreamInfo(), topic_object_id, part_object_id, topic_name, UXR_REUSE);
199+
#else
198200
char topic_profile[256];
199201
sprintf(topic_profile, UXR_TOPIC_XML, topic_name, topic_type);
200202
topic_req = uxr_buffer_create_topic_xml(&g_uxr_session.session, getOutputStreamInfo(), topic_object_id, part_object_id, topic_profile, UXR_REUSE);
201-
#else
202-
topic_req = uxr_buffer_create_topic_ref(&g_uxr_session.session, getOutputStreamInfo(), topic_object_id, part_object_id, topic_name, UXR_REUSE);
203-
#endif
203+
#endif
204+
204205
ret = uxr_run_session_until_all_status(&g_uxr_session.session, 1000, &topic_req, &status, 1);
205206
if(ret == false && status == UXR_STATUS_ERR_ALREADY_EXISTS)
206207
{
@@ -250,12 +251,12 @@ bool xrcedds::createDataWriter(xrcedds::Publisher_t* publisher, xrcedds::DataWri
250251
uxrObjectId pub_object_id = uxr_object_id(publisher->id, UXR_PUBLISHER_ID);
251252
uxrObjectId writer_object_id = uxr_object_id(data_writer->id, UXR_DATAWRITER_ID);
252253

253-
#ifdef UXR_CREATE_ENTITIES_USING_XML
254+
#if (UXR_CREATE_ENTITIES_USING_REF)
255+
datawriter_req = uxr_buffer_create_datawriter_ref(&g_uxr_session.session, getOutputStreamInfo(), writer_object_id, pub_object_id, writer_name, UXR_REPLACE);
256+
#else
254257
char writer_profile[256];
255258
sprintf(writer_profile, UXR_WRITER_XML, writer_name, topic_type);
256-
datawriter_req = uxr_buffer_create_datawriter_xml(&g_uxr_session.session, getOutputStreamInfo(), writer_object_id, pub_object_id, writer_profile, UXR_REPLACE);
257-
#else
258-
datawriter_req = uxr_buffer_create_datawriter_ref(&g_uxr_session.session, getOutputStreamInfo(), writer_object_id, pub_object_id, writer_name, UXR_REPLACE);
259+
datawriter_req = uxr_buffer_create_datawriter_xml(&g_uxr_session.session, getOutputStreamInfo(), writer_object_id, pub_object_id, writer_profile, UXR_REPLACE);
259260
#endif
260261

261262
data_writer->is_created = uxr_run_session_until_all_status(&g_uxr_session.session, 1000, &datawriter_req, &status, 1);
@@ -303,12 +304,12 @@ bool xrcedds::createDataReader(xrcedds::Subscriber_t* subscriber, xrcedds::DataR
303304
uxrObjectId sub_object_id = uxr_object_id(subscriber->id, UXR_SUBSCRIBER_ID);
304305
uxrObjectId reader_object_id = uxr_object_id(data_reader->id, UXR_DATAREADER_ID);
305306

306-
#ifdef UXR_CREATE_ENTITIES_USING_XML
307+
#if (UXR_CREATE_ENTITIES_USING_REF)
308+
datareader_req = uxr_buffer_create_datareader_ref(&g_uxr_session.session, getOutputStreamInfo(), reader_object_id, sub_object_id, reader_name, UXR_REPLACE);
309+
#else
307310
char reader_profile[256];
308311
sprintf(reader_profile, UXR_READER_XML, reader_name, topic_type);
309-
datareader_req = uxr_buffer_create_datareader_xml(&g_uxr_session.session, getOutputStreamInfo(), reader_object_id, sub_object_id, reader_profile, UXR_REPLACE);
310-
#else
311-
datareader_req = uxr_buffer_create_datareader_ref(&g_uxr_session.session, getOutputStreamInfo(), reader_object_id, sub_object_id, reader_name, UXR_REPLACE);
312+
datareader_req = uxr_buffer_create_datareader_xml(&g_uxr_session.session, getOutputStreamInfo(), reader_object_id, sub_object_id, reader_profile, UXR_REPLACE);
312313
#endif
313314

314315
data_reader->is_created = uxr_run_session_until_all_status(&g_uxr_session.session, 1000, &datareader_req, &status, 1);

src/user_config.h

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
/*
2-
* user_config.h
3-
*
4-
* Created on: Jan 29, 2019
5-
* Author: kei
6-
*/
7-
8-
#ifndef ROS2ARDUINO_USER_CONFIG_H_
9-
#define ROS2ARDUINO_USER_CONFIG_H_
10-
11-
12-
#define USER_ROS2_PUBLISHER_MAX 5
13-
#define USER_ROS2_SUBSCRIBER_MAX 5
14-
15-
//external define (only ros2xrce)
16-
#define UXR_CREATE_ENTITIES_USING_XML
17-
18-
19-
#endif /* ROS2ARDUINO_USER_CONFIG_H_ */
1+
#ifndef ROS2ARDUINO_USER_CONFIG_H_
2+
#define ROS2ARDUINO_USER_CONFIG_H_
3+
4+
//#define USER_DISABLE_UDP_TRANSPORT
5+
//#define USER_DISABLE_TCP_TRANSPORT
6+
//#define USER_DISABLE_SERIAL_TRANSPORT
7+
8+
#define UXR_CREATE_ENTITIES_USING_REF 0
9+
#define USER_ROS2_PUBLISHER_MAX 5
10+
#define USER_ROS2_SUBSCRIBER_MAX 5
11+
12+
13+
#endif /* ROS2ARDUINO_USER_CONFIG_H_ */

src/uxr/client/config.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,35 @@
6161
#define UXR_CONFIG_TCP_TRANSPORT_MTU 0
6262
#endif
6363

64+
65+
66+
67+
// related to user_config.h
68+
69+
#ifdef USER_DISABLE_UDP_TRANSPORT
70+
#undef PROFILE_UDP_TRANSPORT
71+
#endif
72+
73+
#ifdef USER_DISABLE_TCP_TRANSPORT
74+
#undef PROFILE_TCP_TRANSPORT
75+
#endif
76+
77+
#ifdef USER_DISABLE_SERIAL_TRANSPORT
78+
#undef PROFILE_SERIAL_TRANSPORT
79+
#endif
80+
81+
82+
#if !defined(UXR_CREATE_ENTITIES_USING_REF)
83+
#define UXR_CREATE_ENTITIES_USING_REF 0
84+
#endif
85+
86+
#if !defined(USER_ROS2_PUBLISHER_MAX)
87+
#define USER_ROS2_PUBLISHER_MAX 5
88+
#endif
89+
90+
#if !defined(USER_ROS2_SUBSCRIBER_MAX)
91+
#define USER_ROS2_SUBSCRIBER_MAX 5
92+
#endif
93+
94+
6495
#endif // _UXR_CLIENT_CONFIG_H_

0 commit comments

Comments
 (0)