Coder Social home page Coder Social logo

Comments (10)

nonanonno avatar nonanonno commented on September 6, 2024

参考になりそうなドキュメント

from ros2_d.

nonanonno avatar nonanonno commented on September 6, 2024

from ros2_d.

nonanonno avatar nonanonno commented on September 6, 2024

from ros2_d.

nonanonno avatar nonanonno commented on September 6, 2024

rust を参考に作成する必要がありそうなパッケージ

  • rosidl_generator_d : interface generator
    • これ自体は python で作成
    • ament_cmake_export_dub に依存
  • ament_cmake_export_dub : build system ?
  • ament_dub : dub によるプロジェクト作成に必要?
  • rcld : client library
  • rcld_common : common library

from ros2_d.

nonanonno avatar nonanonno commented on September 6, 2024

Client Library は基本的に C API である rcl を使って作る。なので、D から これらの API を呼べるようにする必要がある。D は C 関数を直接呼べるので、D 用の ヘッダを用意すれば良いが、dpp でできそう。

  • 参考: https://karita.xyz/log/posts/dpp-guide/
    • 手元では libclang-7-dev を使用
    • preBuildCommands
      DFLAGS=\"-L=-L/usr/lib/llvm-7/lib/\" dub run dpp -- --preprocess-only --include-path /opt/ros/foxy/include source/rcl.dpp

試したところ、 atilaneves/dpp#272 の問題に遭遇した。以下のスクリプトで回避する。

sed -i -e '3i public import core.stdc.stdio;' source/rcl.d
sed -i -z 's/struct _IO_FILE[^{]*{[^{]*}//' source/rcl.d

ノード作成は以下のコードで確認できた。

import rcl;
import std.stdio;
import std.conv;
import std.string;
import core.runtime;
import core.thread;

void main() {
	auto args = Runtime.cArgs;

	auto init_options = rcl_get_zero_initialized_init_options();
	auto allocator = rcutils_get_default_allocator();

	if (rcl_init_options_init(&init_options, allocator) != 0) {
		writeln("rcl_init_options_init failed");
		return;
	}

	auto context = rcl_context_t();
	if (rcl_init(args.argc, args.argv, &init_options, &context) != 0) {
		writeln("rcl_init failed");
		return;
	}
	scope (exit) {
		rcl_shutdown(&context);
	}

	auto node_handle = rcl_get_zero_initialized_node();
	auto node_options = rcl_node_get_default_options();
	if (rcl_node_init(&node_handle, "test", "", &context, &node_options) != 0) {
		writeln("rcl_node_init failed");
		return;
	}
	scope (exit) {
		rcl_node_fini(&node_handle);
	}

	Thread.sleep(10.seconds);

}

from ros2_d.

nonanonno avatar nonanonno commented on September 6, 2024

dub.json

{
	"authors": [
		"nonanonno"
	],
	"preBuildCommands": [
		"dub fetch dpp --version=0.4.2",
		"DFLAGS=\"-L=-L/usr/lib/llvm-7/lib/\" dub run dpp -- --preprocess-only --include-path /opt/ros/foxy/include source/rcl.dpp",
		"sed -i -e '3i public import core.stdc.stdio;' source/rcl.d",
		"sed -i -z 's/struct _IO_FILE[^{]*{[^{]*}//' source/rcl.d"
	],
	"copyright": "Copyright © 2020, nonanonno",
	"description": "A minimal D application.",
	"license": "proprietary",
	"name": "rosd_test",
	"lflags-posix": [
		"-L/opt/ros/foxy/lib"
	],
	"libs": [
		"rcl",
		"rcutils"
	]
}

from ros2_d.

nonanonno avatar nonanonno commented on September 6, 2024

rust を見る限りでは、
msg をコードで使用するためのファイルは rosidl_generator_xx で作成される。順番としては、

  1. rosidl_generator_xx をビルド & . ./install/setup.bash
  2. msg の package をビルド

という順番になる。

1 と 2 は1回の colcon build でやっても良い。

この順番があるため、apt で取得した標準 msg もビルドし直す必要があり、rust では以下の package もダウンロードしてビルドしている。

  • common_interfaces
  • rcl_interfaces
  • rosidl_defaults (rust を generator に追加するために必要?)

from ros2_d.

nonanonno avatar nonanonno commented on September 6, 2024

topic publish

C API を使用している。

void main() {
	auto args = Runtime.cArgs;

	auto init_options = rcl_get_zero_initialized_init_options();
	auto allocator = rcutils_get_default_allocator();

	if (rcl_init_options_init(&init_options, allocator) != 0) {
		writeln("rcl_init_options_init failed");
		return;
	}

	auto context = rcl_context_t();
	if (rcl_init(args.argc, args.argv, &init_options, &context) != 0) {
		writeln("rcl_init failed");
		return;
	}
	scope (exit) {
		rcl_shutdown(&context);
	}
	rcl_init_options_fini(&init_options);

	// create node
	auto node_handle = rcl_get_zero_initialized_node();
	auto node_options = rcl_node_get_default_options();
	if (rcl_node_init(&node_handle, "test", "", &context, &node_options) != 0) {
		writeln("rcl_node_init failed");
		return;
	}
	scope (exit) {
		rcl_node_fini(&node_handle);
	}

	// create publisher
	auto pub_handle = rcl_get_zero_initialized_publisher();
	auto pub_options = rcl_publisher_get_default_options();
	auto ts = rosidl_typesupport_c__get_message_type_support_handle__std_msgs__msg__Bool();
	if (rcl_publisher_init(&pub_handle, &node_handle, ts,
			cast(const char*) "test", &pub_options) != 0) {
		writeln("rcl_publisher_init failed");
		return;
	}
	scope (exit) {
		rcl_publisher_fini(&pub_handle, &node_handle);
	}

	auto msg = std_msgs__msg__Bool__create();
	scope (exit) {
		std_msgs__msg__Bool__destroy(msg);
	}

	foreach (i; 0 .. 10) {
		msg.data = i % 2 == 0;
		rcl_publish(&pub_handle, cast(void*) msg, null);
		Thread.sleep(1.seconds);
	}

}

from ros2_d.

nonanonno avatar nonanonno commented on September 6, 2024

msg は とりあえず C 構造体に ディープコピーすることにする。配列周りに D の機能を使いたいため、後々裏側を変える。

from ros2_d.

nonanonno avatar nonanonno commented on September 6, 2024

とりあえずの方針は

  • target は foxy
  • rcld を作りつつ、プロジェクトの構成を決める
    • 中身は、 rcld.Node ができれば良い
    • ros2 コマンドの利用は一旦考えなず、 dub プロジェクトとする
  • rosidl_generator_d を作る。
  • pub/sub を作る。
  • ...

from ros2_d.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.