Renesas Rulz - Japan
Renesas Rulz - Japan
  • User
    Join or sign in
  • Site
  • Search Japan.RenesasRulz.com
  • User
  • Renesas Rulz
  • FAQ
  • パートナー
  • 半導体セミナ
  • eラーニング
  • ヘルプ
  • More
  • Cancel
  • かふぇルネ
  • がじぇるね
  • English Community
  • More
  • Cancel
がじぇっとるねさすコミュニティ
がじぇっとるねさすコミュニティ
GR-ROSE ROS 2 (micro-RTPS) サンプル
  • Forums
  • Blog
  • Files
  • がじぇっとるねさす ゆーざー会 - Wiki
  • Tags
  • More
  • Cancel
  • New

 

 GR-SAKURA

 GR-KURUMI

 GR-COTTON

 GR-CITRUS

 GR-PEACH

 GR-KAEDE

 GR-ADZUKI

 GR-LYCHEE

 GR-ROSE

 GR-MANGO(*)

 SNShield

 Web Compiler

 IDE for GR

 TOPPERS関連

 女子美コラボ

 その他

 ※プロデューサミーティング中

 作り方使い方資料

 イベント関連

 作品記事

 体験記事

 その他

 

 ライブラリ

 ツール

 その他・過去ファイル

  • State Not Answered
  • Replies 18 replies
  • Subscribers 446 subscribers
  • Views 15796 views
  • Users 0 members are here
Options
  • Share
  • More
  • Cancel
Related Tags
  • B3M
  • DDS-XRCE
  • Dynamixel
  • esp8266
  • FIT
  • GR-ROSE
  • HYGRO
  • ICS
  • include
  • JSTK2
  • KYPD
  • MG996R
  • MIC3
  • NAV
  • OLED
  • pin
  • PMOD
  • ROS
  • ROS2
  • rosserial
  • RS-485
  • RX65N
  • Serial2
  • spi
  • Wire
Related

ROS 2 (micro-RTPS) サンプル

Okamiya Yuuki
Okamiya Yuuki over 2 years ago

eSOLさんが動作確認してくださったサンプルを貼り付けます。

※2018/10/01追記:やればやるほどハマるROS 2ですが、自分のRaspberry Pi 3にUbuntu Mate、micro-RTPS-Agentを入れてGR-ROSEをつなげてみましたので手順を追記しました。実際のところ、ClientであるPublisherとSubscriberの両方がいないと動作確認できないため、ROS 2はかなり準備の敷居が高いなと思う今日この頃です。

●Rapberry Pi 3 にmicroRTPS-Agentを入れる手順

(Windows PCで実施します)

Ubuntu Mateを入手
https://ubuntu-mate.org/raspberry-pi/ubuntu-mate-16.04.2-desktop-armhf-raspberry-pi.img.xz
ダウンロードファイルを解凍しWin32DiskImagerでマイクロSDへWrite

(RaspberryPi 3を立ち上げUbuntuで実施します)
ApplicationsからMate Terminalを起動

(Gitをインストール)
sudo apt-get update
sudo apt-get install git-core
git --version

(RTPSをインストール)
sudo git clone --recursive https://github.com/eProsima/micro-RTPS.git
cd micro-RTPS
sudo mkdir build

sudo apt-get install cmake
sudo cmake -DTHIRDPARTY=ON ..
sudo make
sudo make install

(eProsimaのRTPSで、足りないTranspote?があるらしいので一旦Agentをアンインストール)
sudo rm -r micro-RTPS-agent

(eSOLさんで確認済みのちょっと古いmicro-RTPS-Agentをインストール)
sudo git clone https://github.com/GadgetRenesas/micro-RTPS-agent
cd micro-RTPS-agent
sudo mkdir build
cd build
sudo cmake -DTHIRDPARTY=ON ..
sudo make

(Agentを起動、Clientは後から起動する必要あります)

Ethernetの設定で固定IPとして192.168.1.101とする。サブネットマスクは255.255.255.0。

cd micro-RTPS-agent/build
./MicroRTPSAgent udp 2020

(GR-ROSE側のプログラム)

●micro-RTPCをsubscriberとしたときの動作確認

基本的には固定IPでの通信。デフォルトのAgent IPアドレスは192.168.1.101。GR-ROSE(Client)のIPアドレスは192.168.1.123。V0.03のテンプレートでは./freertos/config_files/FreeRTOSConfig.hで設定しているが、ゆくゆくはArduinoライクにsketch.cppで設定できるようにしたいと思ってます。

  

#include <Arduino.h>
extern "C" {
#include "FreeRTOS.h"
#include "task.h"
#include <stdio.h>
#include "micrortps_demo_config.h"
#include "HelloWorld.h"
}

#ifdef demoConfigMICRORTPS_SELECT_SUBSCRIBER
int32_t g_loop_out = 0;
#define swValidate_Connect

int g_subscribe_cnt = 0; /* temporary until support "printf" */
char g_last_rcv_buf[80]; /* temporary until support "printf" */


#define HELLO_WORLD_TOPIC 0x01

static void prvMicrortpsSub(void * pvParameters);

#ifdef demoConfigMICRORTPS_USE_UDP
static const uint8_t agentIPAddress[4] =
{
democonfigMICRORTPS_AGENT_ADDR0,
democonfigMICRORTPS_AGENT_ADDR1,
democonfigMICRORTPS_AGENT_ADDR2,
democonfigMICRORTPS_AGENT_ADDR3
};
static const uint16_t agentPort = democonfigMICRORTPS_AGENT_PORT;
#endif


void check_and_print_error(Session* session, const char* where)
{
if(session->last_status_received)
{
if(session->last_status.status == STATUS_OK)
{
return; //All things go well
}
else
{
configPRINTF( ("Status error (%i)", session->last_status.status) );
}
}
else
{
configPRINTF( ("Connection error") );
}
configPRINTF( (" at %s\n", where) );

/*TODO: When the connection is failed, client should close
* session and reconnect to agent(not implemented yet). */
return;
}

void on_topic(ObjectId id, MicroBuffer* serialized_topic, void* args)
{
(void) args;
if(HELLO_WORLD_TOPIC == id.data[0])
{
HelloWorld topic;
deserialize_HelloWorld_topic(serialized_topic, &topic);

configPRINTF( ("Receive topic: %s, count: %i\n", topic.message, topic.index) );
g_subscribe_cnt++;
if(g_loop_out == 2) {
sprintf(g_last_rcv_buf, "Receive topic: %s, count: %i", topic.message, topic.index);
g_loop_out = 1;
}
}
}



void setup(){

pinMode(PIN_LED0, OUTPUT);
}

void loop(){
Session my_session;
ObjectId datareader_id;
ClientKey key = {{0xBB, 0xBB, 0xBB, 0xBB}};

#ifdef demoConfigMICRORTPS_USE_SERIAL
/* Device name does not need to be set.
* Serial device used by client is dependent on the board revision. */
if(!new_serial_session(&my_session, 0x01, key, " ", on_topic, NULL))
{
configPRINTF( ("Can not create serial connection\n") );
} else {
configPRINTF( ("<< Serial mode >>\n") );
}
#elif defined demoConfigMICRORTPS_USE_UDP
/* Wait for network configuration. */

ms_sleep(10000);
if(!new_udp_session(&my_session, 0x01, key, agentIPAddress, agentPort, on_topic, NULL))
{
configPRINTF( ("Can not create a socket\n") );
} else {
configPRINTF( ("<< UDP mode >>\n") );
}
#endif

/* Init session. */
init_session_sync(&my_session);
check_and_print_error(&my_session, "init_session");

/* Init XRCE objects. */
ObjectId participant_id = {{0x00, OBJK_PARTICIPANT}};
create_participant_sync_by_ref(&my_session, participant_id, "default_participant", false, false);
check_and_print_error(&my_session, "create participant");

const char* topic_xml = {"<dds><topic><name>HelloWorldTopic</name><dataType>micrortps_demo_msgs::msg::dds_::HelloWorld_</dataType></topic></dds>"};
ObjectId topic_id = {{0x00, OBJK_TOPIC}};
create_topic_sync_by_xml(&my_session, topic_id, topic_xml, participant_id, false, false);
check_and_print_error(&my_session, "create topic");

const char* subscriber_xml = {"<subscriber name=\"MySubscriber\""};
ObjectId subscriber_id = {{HELLO_WORLD_TOPIC, OBJK_SUBSCRIBER}};
create_subscriber_sync_by_xml(&my_session, subscriber_id, subscriber_xml, participant_id, false, false);
check_and_print_error(&my_session, "create subscriber");

/* Set partition name of ROS2 topics, "rt" to communicate with ROS2 publisher and subscriber.
* About ROS Specific Namespace, please check following link:
* design.ros2.org/.../topic_and_service_names.html
* When micro RTPS client communicate with FreeRTPS HelloWorld example, partition name should be removed. */
const char* datareader_xml = {"<profiles><subscriber profile_name=\"default_xrce_subscriber_profile\"><topic><kind>NO_KEY</kind><name>HelloWorldTopic</name><dataType>micrortps_demo_msgs::msg::dds_::HelloWorld_</dataType><historyQos><kind>KEEP_LAST</kind><depth>5</depth></historyQos><durability><kind>TRANSIENT_LOCAL</kind></durability></topic><qos><partition><names><name>rt</name></names></partition></qos></subscriber></profiles>"};
datareader_id = {{HELLO_WORLD_TOPIC, OBJK_DATAREADER}};
create_datareader_sync_by_xml(&my_session, datareader_id, datareader_xml, subscriber_id, false, false);
check_and_print_error(&my_session, "create datareader");

/* Main loop */
for( ; ; )
{
/* Request data */
read_data_sync(&my_session, datareader_id, democonfigMICRORTPS_SELECT_STREAM);
check_and_print_error(&my_session, "read_data");

run_communication(&my_session);

ms_sleep(democonfigMICRORTPS_SUB_TASK_DELAY);
}

close_session_sync(&my_session);
check_and_print_error(&my_session, "close session");

free_session(&my_session);

digitalWrite(PIN_LED0, !digitalRead(PIN_LED0));
vTaskDelay(500);
}
#endif /* demoConfigMICRORTPS_SELECT_SUBSCRIBER */


#ifdef demoConfigMICRORTPS_SELECT_PUBLISHER

static void prvMicrortpsPub(void * pvParameters);

#ifdef demoConfigMICRORTPS_USE_UDP
static const uint8_t agentIPAddress[4] =
{
democonfigMICRORTPS_AGENT_ADDR0,
democonfigMICRORTPS_AGENT_ADDR1,
democonfigMICRORTPS_AGENT_ADDR2,
democonfigMICRORTPS_AGENT_ADDR3
};
static const uint16_t agentPort = democonfigMICRORTPS_AGENT_PORT;
#endif

void check_and_print_error(Session* session, const char* where)
{
if(session->last_status_received)
{
if(session->last_status.status == STATUS_OK)
{
return; //All things go well
}
else
{
configPRINTF( ("Status error (%i)", session->last_status.status) );
}
}
else
{
configPRINTF( ("Connection error") );
}
configPRINTF( (" at %s\n", where) );

/*TODO: When the connection is failed, client should close
* session and reconnect to agent(not implemented yet). */
return;
}

void setup(){

pinMode(PIN_LED0, OUTPUT);
}

void loop(){
Session my_session;
ObjectId datawriter_id;

ClientKey key = {{0xAA, 0xAA, 0xAA, 0xAA}};

#ifdef demoConfigMICRORTPS_USE_SERIAL
/* Device name does not need to be set.
* Serial device used by client is dependent on the board revision. */
if(!new_serial_session(&my_session, 0x01, key, " ", NULL, NULL))
{
configPRINTF( ("Can not create serial connection\n") );
} else {
configPRINTF( ("<< Serial mode >>\n") );
}
#elif defined demoConfigMICRORTPS_USE_UDP
/* Wait for network configuration. */
ms_sleep(15000);
#ifdef swValidate_Connect
while(g_loop_out == 0) {
ms_sleep(5000);
}
#endif

if(!new_udp_session(&my_session, 0x01, key, agentIPAddress, agentPort, NULL, NULL))
{
configPRINTF( ("Can not create a socket\n") );
} else {
configPRINTF( ("<< UDP mode >>\n") );
}
#endif

/* Init session. */
init_session_sync(&my_session);
check_and_print_error(&my_session, "init session");

/* Init XRCE objects. */
ObjectId participant_id = {{0x00, OBJK_PARTICIPANT}};
create_participant_sync_by_ref(&my_session, participant_id, "default_participant", false, false);
check_and_print_error(&my_session, "create participant");

const char* topic_xml = {"<dds><topic><name>HelloWorldTopic</name><dataType>micrortps_demo_msgs::msg::dds_::HelloWorld_</dataType></topic></dds>"};
ObjectId topic_id = {{0x00, OBJK_TOPIC}};
create_topic_sync_by_xml(&my_session, topic_id, topic_xml, participant_id, false, false);
check_and_print_error(&my_session, "create topic");

const char* publisher_xml = {"<publisher name=\"MyPublisher\""};
ObjectId publisher_id = {{0x00, OBJK_PUBLISHER}};
create_publisher_sync_by_xml(&my_session, publisher_id, publisher_xml, participant_id, false, false);
check_and_print_error(&my_session, "create publisher");

/* Set partition name of ROS2 topics, "rt" to communicate with ROS2 publisher and subscriber.
* About ROS Specific Namespace, please check following link:
* design.ros2.org/.../topic_and_service_names.html
* When micro RTPS client communicate with FreeRTPS HelloWorld example, partition name should be removed. */
const char* datawriter_xml = {"<profiles><publisher profile_name=\"default_xrce_publisher_profile\"><topic><kind>NO_KEY</kind><name>HelloWorldTopic</name><dataType>micrortps_demo_msgs::msg::dds_::HelloWorld_</dataType><historyQos><kind>KEEP_LAST</kind><depth>5</depth></historyQos><durability><kind>TRANSIENT_LOCAL</kind></durability></topic><qos><partition><names><name>rt</name></names></partition></qos></publisher></profiles>"};
datawriter_id = {{0x00, OBJK_DATAWRITER}};
create_datawriter_sync_by_xml(&my_session, datawriter_id, datawriter_xml, publisher_id, false, false);
check_and_print_error(&my_session, "create datawriter");

/* Main loop */
int32_t count = 0;
for( ; ; )
{
/* Write HelloWorld topic */
HelloWorld topic;
topic.index = ++count;
topic.message = "Hello DDS world!";
write_HelloWorld(&my_session, datawriter_id, democonfigMICRORTPS_SELECT_STREAM, &topic);
configPRINTF( ("Send topic: %s, count: %i\n", topic.message, topic.index) );

run_communication(&my_session);

ms_sleep(democonfigMICRORTPS_PUB_TASK_DELAY);
}

close_session_sync(&my_session);
check_and_print_error(&my_session, "close session");

free_session(&my_session);

digitalWrite(PIN_LED0, !digitalRead(PIN_LED0));
vTaskDelay(500);
}

#endif /* demoConfigMICRORTPS_SELECT_PUBLISHER */

  • Reply
  • Cancel
  • Cancel
Parents
  • Yuuichi Akagawa
    0 Yuuichi Akagawa over 2 years ago
    v1.0.0がリリースされました。
    そして、リポジトリの名前もmicro-RTPSからMicro-XRCE-DDSに変更になりました。
    github.com/.../Micro-XRCE-DDS

    betaからbeta2でAPIが変わり、beta2から正式版でもまたAPIが変わりました。
    (betaからbeta2は全然違うモノになり、beta2から正式は名前が変わったくらい?)
    • Cancel
    • Up 0 Down
    • Reply
    • Verify Answer
    • Cancel
  • Okamiya Yuuki
    0 Okamiya Yuuki over 2 years ago in reply to Yuuichi Akagawa
    対応していきます!
    • Cancel
    • Up 0 Down
    • Reply
    • Verify Answer
    • Cancel
  • るぅて
    0 るぅて over 2 years ago in reply to Okamiya Yuuki
    ダメ元でRTPSを最新のMicro-XRCE-DDSを使って、agentとclientをROSEで実績あるものにして試してみたのですが、やはり"Error at create session."となって繋がりませんでした。

    micro-RTPSのソースはないでしょうか?
    • Cancel
    • Up 0 Down
    • Reply
    • Verify Answer
    • Cancel
  • Okamiya Yuuki
    0 Okamiya Yuuki over 2 years ago in reply to るぅて
    ソースは前記のgit cloneの対象のURLに示す通りです。
    • Cancel
    • Up 0 Down
    • Reply
    • Verify Answer
    • Cancel
  • るぅて
    0 るぅて over 2 years ago in reply to Okamiya Yuuki
    既に、そのURLがMicro-XRCE-DDSに飛ばされるので、取得できないです。
    • Cancel
    • Up 0 Down
    • Reply
    • Verify Answer
    • Cancel
  • Okamiya Yuuki
    0 Okamiya Yuuki over 2 years ago in reply to るぅて
    失礼しました。
    micro-RTPSからMicro-XRCE-DDSに変わったために、micro-RTPSのソースがなくなったということですね。
    • Cancel
    • Up 0 Down
    • Reply
    • Verify Answer
    • Cancel
  • るぅて
    0 るぅて over 2 years ago in reply to Okamiya Yuuki
    はい!eProsimaも古いものを残しておいてくれればいいと思うのですが、、、
    • Cancel
    • Up 0 Down
    • Reply
    • Verify Answer
    • Cancel
  • Yuuichi Akagawa
    0 Yuuichi Akagawa over 2 years ago in reply to るぅて

    2018/10/27現在のmicro-RTPS v1.0.0bビルド手順です。
    AgentとClientは別々に取得してビルドするものとします。
    Ubuntu 18.04(amd64)で確認しました。

    作業ディレクトリディレクトリ作成

     mkdir ~/micrortps
    

    GadgetRenesasのmicro-RTPS-agentを取得

    micro-transportを使いたいだけ。ビルドはしない。

     cd ~/micrortps
     git clone href="https://github.com/GadgetRenesas/micro-RTPS-agent.git
    

    Agentのビルド

    1. micro-XRCE-DDS-Agentを取得

     cd ~/micrortps
     git clone https://github.com/eProsima/Micro-XRCE-DDS-Agent.git
     cd Micro-XRCE-DDS-Agent
     git checkout e18261062ca27e8f20d8bc8f6d2811ee5fc2ef16
     git clone -b v1.6.0 https://github.com/eProsima/Fast-RTPS.git thirdparty/fastrtps
     git clone https://github.com/chriskohlhoff/asio.git thirdparty/asio
     cp -a ../micro-RTPS-agent/thirdparty/micrortps_transport thirdparty
    

    2. CMakeLists.txtを修正

    227行目付近
    #find_package(fastcdr REQUIRED)
    #find_package(fastrtps REQUIRED)
    #eprosima_find_thirdparty(Asio asio)
    eprosima_find_package(fastrtps REQUIRED)
    eprosima_find_package(micrortps_transport REQUIRED)
    

    3. ビルド

     mkdir build && cd build
     cmake -DTHIRDPARTY=ON ..
     make
    

    カレントディレクトリに、MicroRTPSAgent が生成される。make installは必要なく、この実行ファイルを直接実行可能。

    実行例

     ./MicroRTPSAgent udp 2020 

    Clientのビルド

    1. micro-XRCE-DDS-Clientを取得

     cd ~/micrortps
     git clone https://github.com/eProsima/Micro-XRCE-DDS-Client.git
     cd Micro-XRCE-DDS-Client
     git checkout 79d7cd343eb6558f8c7009dc3094e3ec616c1f70
     git clone https://github.com/eProsima/micro-CDR.git thirdparty/microcdr
     cd thirdparty/microcdr
     git checkout 0061c9af1f17e560bee604dd882772913bf90073
     cd ../..
     cp -a ../micro-RTPS-agent/thirdparty/micrortps_transport thirdparty
    

    2. ビルド

     mkdir buil d&& cd build
     cmake -DTHIRDPARTY=ON -DEPROSIMA_BUILD_EXAMPLES=ON ..
     make
    

    examples以下の各ディレクトリに実行ファイルが生成される。

    ROSEのサンプルと通信できるのはSubscribeHelloWorldClientとPublishHelloWorldClient
    ※ROSEのサンプルそのままでは動きません。xmlをこれらexampleの記述と同じに修正する必要があります。

    実行例

     examples/SubscribeHelloWorld/SubscribeHelloWorldClient udp 127.0.0.1 2020
     examples/PublishHelloWorld/PublishHelloWorldClient udp 127.0.0.1 2020
    • Cancel
    • Up 0 Down
    • Reply
    • Verify Answer
    • Cancel
Reply
  • Yuuichi Akagawa
    0 Yuuichi Akagawa over 2 years ago in reply to るぅて

    2018/10/27現在のmicro-RTPS v1.0.0bビルド手順です。
    AgentとClientは別々に取得してビルドするものとします。
    Ubuntu 18.04(amd64)で確認しました。

    作業ディレクトリディレクトリ作成

     mkdir ~/micrortps
    

    GadgetRenesasのmicro-RTPS-agentを取得

    micro-transportを使いたいだけ。ビルドはしない。

     cd ~/micrortps
     git clone href="https://github.com/GadgetRenesas/micro-RTPS-agent.git
    

    Agentのビルド

    1. micro-XRCE-DDS-Agentを取得

     cd ~/micrortps
     git clone https://github.com/eProsima/Micro-XRCE-DDS-Agent.git
     cd Micro-XRCE-DDS-Agent
     git checkout e18261062ca27e8f20d8bc8f6d2811ee5fc2ef16
     git clone -b v1.6.0 https://github.com/eProsima/Fast-RTPS.git thirdparty/fastrtps
     git clone https://github.com/chriskohlhoff/asio.git thirdparty/asio
     cp -a ../micro-RTPS-agent/thirdparty/micrortps_transport thirdparty
    

    2. CMakeLists.txtを修正

    227行目付近
    #find_package(fastcdr REQUIRED)
    #find_package(fastrtps REQUIRED)
    #eprosima_find_thirdparty(Asio asio)
    eprosima_find_package(fastrtps REQUIRED)
    eprosima_find_package(micrortps_transport REQUIRED)
    

    3. ビルド

     mkdir build && cd build
     cmake -DTHIRDPARTY=ON ..
     make
    

    カレントディレクトリに、MicroRTPSAgent が生成される。make installは必要なく、この実行ファイルを直接実行可能。

    実行例

     ./MicroRTPSAgent udp 2020 

    Clientのビルド

    1. micro-XRCE-DDS-Clientを取得

     cd ~/micrortps
     git clone https://github.com/eProsima/Micro-XRCE-DDS-Client.git
     cd Micro-XRCE-DDS-Client
     git checkout 79d7cd343eb6558f8c7009dc3094e3ec616c1f70
     git clone https://github.com/eProsima/micro-CDR.git thirdparty/microcdr
     cd thirdparty/microcdr
     git checkout 0061c9af1f17e560bee604dd882772913bf90073
     cd ../..
     cp -a ../micro-RTPS-agent/thirdparty/micrortps_transport thirdparty
    

    2. ビルド

     mkdir buil d&& cd build
     cmake -DTHIRDPARTY=ON -DEPROSIMA_BUILD_EXAMPLES=ON ..
     make
    

    examples以下の各ディレクトリに実行ファイルが生成される。

    ROSEのサンプルと通信できるのはSubscribeHelloWorldClientとPublishHelloWorldClient
    ※ROSEのサンプルそのままでは動きません。xmlをこれらexampleの記述と同じに修正する必要があります。

    実行例

     examples/SubscribeHelloWorld/SubscribeHelloWorldClient udp 127.0.0.1 2020
     examples/PublishHelloWorld/PublishHelloWorldClient udp 127.0.0.1 2020
    • Cancel
    • Up 0 Down
    • Reply
    • Verify Answer
    • Cancel
Children
No Data
サイト使用条件
プライバシーポリシー
お問い合わせ
© 2010-2020 Renesas Electronics Corporation. All rights reserved.