SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Downloaden Sie, um offline zu lesen
2
7
@atsukiyokota
@AtsukiYokota
• R 2 O
7
• R
• R
S S
• 2 1 1
• 3
• 2
• 4 7
• 25
2
1
• RT PIO
RI 2 T A O SI
• t mo i mn m
• c t n eA c p
• S O T PTC 1
I
m
p ct
l
6 2
5 5 11 2
26 5
fm
R
r
g OSa nP
l m
• m w r 2 A c
C R
• :i i B t
• Op ro f i e
K
OR S
A
PP I
2 2
y
SR a
5 I f cn A
•
• ::
• :
• C
•
• . . . .
• 2 2
• 2 2
•
• 3 3
• + #-
.
.
2
3 2
• 3 ) Ot h r c
$ ros2 pkg create –build-type ament_python YOUR_AWESOME_PACKAGE
u lnkc / 2 ) / g ws_rt c
• 2 ) .32uo_ k c nkkx t mP u
• r a u
• ( yu .32 t r / le snk
(SRt cs s s .32 rgp (
from setuptools import setup
package_name = 'examples_rclpy_topics'
setup(
name=package_name, # パッケージ名
version='0.6.3', # バージョン番号
packages=[package_name], # ソースコードのディレクトリ
data_files=[ # ソースコード以外のファイル
('share/ament_index/resource_index/packages', ['resource/’ +
package_name]),
('share/' + package_name, ['package.xml']),
],
install_requires=['setuptools'], # 依存Python3モジュール
zip_safe=True,
author='Mikael Arguedas',
author_email='mikael@osrfoundation.org',
maintainer='Atsuki Yokota',
maintainer_email='atsuki.yokota@gmail.com',
keywords=['ROS'],
classifiers=[ # PyPIの分類情報
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Topic :: Software Development',
],
description='Examples of publishers/subscribers using rclpy.',
license='Apache License, Version 2.0',
tests_require=['pytest'], # テストフレームワーク名
entry_points={ # 実行コマンド名とその呼び出し先
'console_scripts': [
'publisher = ' + package_name + '.publisher:main',
'subscriber = ' + package_name + '.subscriber:main',
],
},
)
; =fR
• 2 2 m si a 2 . S _
R S Rc a
• 2 S d_ . . o ld O
• . 3 2 P b a R3 3 prl ba
$ ros2 run examples_rclpy_topics publisher
• O
• c e u“ fys m =;2 c _b a
• c ; p s e “ lays m ai t m _a
=;2 c . . / . ; ; 2 S
• ha ys fr mP S ai
1 ld
,
• h . 2 v x i , egkm 2h
O rs PChy o n o
• _h . ,. , e h x O rs a oLR y h
o n v xo n e MSe
find_package(std_msgs REQUIRED)
find_package(action_msgs REQUIRED)
find_package(rosidl_default_generators REQUIRED)
rosidl_generate_interfaces(${PROJECT_NAME}
"srv/SetMessage.srv"
"action/Fibonacci.action"
DEPENDENCIES std_msgs action_msgs
)
ament_export_dependencies(rosidl_default_runtime)
ament_package()
,
3
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class MinimalPublisher(Node):
def __init__(self):
super().__init__('minimal_publisher')
self.publisher = self.create_publisher(String, 'chatter')
self.timer = self.create_timer(0.5, self.timer_callback)
def timer_callback(self):
msg = String()
msg.data = 'Hello World!'
self.publisher.publish(msg)
self.get_logger().info(msg.data)
_e
.
c
. dea
R . .
R N
. R
.
R _e
R
def main(args=None):
rclpy.init(args=args)
minimal_publisher = MinimalPublisher()
rclpy.spin(minimal_publisher)
rclpy.shutdown()
if __name__ == '__main__':
main()
. 1
.
= 2
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
class MinimalSubscriber(Node):
def __init__(self):
super().__init__('minimal_subscriber')
self.subscription = self.create_subscription(
String, 'chatter', self.listener_callback)
def listener_callback(self, msg):
self.get_logger().info(msg.data)
def main(args=None):
rclpy.init(args=args)
minimal_subscriber = MinimalSubscriber()
rclpy.spin(minimal_subscriber)
rclpy.shutdown()
if __name__ == '__main__':
main()
4
from example_interfaces.srv import AddTwoInts
import rclpy
from rclpy.node import Node
class MinimalService(Node):
def __init__(self):
super().__init__('minimal_service')
self.srv = self.create_service(
AddTwoInts, 'add_two_ints', self.add_two_ints_callback)
def add_two_ints_callback(self, request, response):
response.sum = request.a + request.b
self.get_logger().info('{} + {} = {}'.format(request.a, request.b,
response.sum))
return response
H
,
1
def main(args=None):
rclpy.init(args=args)
minimal_service = MinimalService()
rclpy.spin(minimal_service)
rclpy.shutdown()
if __name__ == '__main__':
main()
from example_interfaces.srv import AddTwoInts
import rclpy
from rclpy.node import Node
class MinimalClient(Node):
def __init__(self):
super().__init__('minimal_client')
self.client = self.create_client(AddTwoInts, 'add_two_ints')
while not self.client.wait_for_service(timeout_sec=1.0):
self.get_logger().info('waiting...')
self.request = AddTwoInts.Request()
def call_async(self):
self.request.a = 1
self.request.b = 2
return self.client.call_async(self.request)
1 1
def main(args=None):
rclpy.init(args=args)
minimal_client = MinimalClient()
future = minimal_client.call_async()
rclpy.spin_until_future_complete(minimal_client, future)
if future.done() and future.result() is not None:
response = future.result()
minimal_client.get_logger().info('{} + {} = {}'.format(
minimal_client.request.a, minimal_client.request.b,
response.sum))
rclpy.shutdown()
F
F
5
import time
from example_interfaces.action import Fibonacci
import rclpy
from rclpy.action import ActionServer, CancelResponse, GoalResponse
from rclpy.callback_groups import ReentrantCallbackGroup
from rclpy.executors import MultiThreadedExecutor
from rclpy.node import Node
class MinimalActionServer(Node):
def __init__(self):
super().__init__('minimal_action_server')
self._action_server = ActionServer(
self, Fibonacci, 'fibonacci',
execute_callback=self.execute_callback,
callback_group=ReentrantCallbackGroup())
_e _
b ec
b aec
def destroy(self):
self._action_server.destroy()
super().destroy_node()
async def execute_callback(self, goal_handle):
self.get_logger().info('executing...')
msg = Fibonacci.Feedback()
msg.sequence = [0, 1]
for i in range(1, goal_handle.request.order):
if goal_handle.is_cancel_requested:
goal_handle.canceled()
self.get_logger().info('goal_canceled')
return Fibonacci.Result()
msg.sequence.append(msg.sequence[i] + msg.sequence[i-1])
self.get_logger().info('feedback:{}'.format(msg.sequence))
goal_handle.publish_feedback(msg)
time.sleep(1) # dummy job
. /
/ PdI
c
w sn i
f a h f
. i
f f
t t Oe
5 3
Pd
f f
t
f f
goal_handle.set_succeeded()
result = Fibonacci.Result()
result.sequence = msg.sequence
self.get_logger().info('result:{}'.format(result.sequence))
return result
def main(args=None):
rclpy.init(args=args)
minimal_action_server = MinimalActionServer()
executor = MultiThreadedExecutor()
rclpy.spin(minimal_action_server, executor=executor)
minimal_action_server.destroy()
rclpy.shutdown()
if __name__ == '__main__':
main()
E
E
from action_msgs.msg import GoalStatus
from example_interfaces.action import Fibonacci
import rclpy
from rclpy.action import ActionClient
from rclpy.node import Node
class MinimalActionClient(Node):
def __init__(self):
super().__init__('minimal_action_client')
self._action_client = ActionClient(self, Fibonacci, 'fibonacci')
def goal_response_callback(self, future):
goal_handle = future.result()
if not goal_handle.accepted:
self.get_logger().info('goal rejected')
return
self._get_result_future = goal_handle.get_result_async()
self._get_result_future.add_done_callback(self.get_result_callback)
def feedback_callback(self, feedback):
self.get_logger().info('feedback:{}'.format(
feedback.feedback.sequence))
def get_result_callback(self, future):
status = future.result().action_status
if status == GoalStatus.STATUS_SUCCEEDED:
self.get_logger().info('result:{}'.format(
future.result().requence))
rclpy.shutdown()
def send_goal(self):
self.get_logger().info('waiting...')
self._action_client.wait_for_server()
goal_msg = Fibonacci.Goal()
goal_msg.order = 10
self._send_goal_future = self._action_client.send_goal_async(
goal_msg, feedback_callback=self.feedback_callback)
self._send_goal_future.add_done_callback(
self.goal_response_callback)
ca _
b
b 3
b c
b
def main(args=None):
rclpy.init(args=args)
action_client = MinimalActionClient()
action_client.send_goal()
rclpy.spin(action_client)
action_client.destroy_node()
if __name__ == '__main__':
main()
D

Weitere ähnliche Inhalte

Was ist angesagt?

オープンソース SLAM の分類
オープンソース SLAM の分類オープンソース SLAM の分類
オープンソース SLAM の分類Yoshitaka HARA
 
NDTスキャンマッチング 第1回3D勉強会@PFN 2018年5月27日
NDTスキャンマッチング 第1回3D勉強会@PFN 2018年5月27日NDTスキャンマッチング 第1回3D勉強会@PFN 2018年5月27日
NDTスキャンマッチング 第1回3D勉強会@PFN 2018年5月27日Kitsukawa Yuki
 
ORB-SLAMの手法解説
ORB-SLAMの手法解説ORB-SLAMの手法解説
ORB-SLAMの手法解説Masaya Kaneko
 
「伝わるチケット」の書き方
「伝わるチケット」の書き方「伝わるチケット」の書き方
「伝わるチケット」の書き方onozaty
 
モデル高速化百選
モデル高速化百選モデル高速化百選
モデル高速化百選Yusuke Uchida
 
ROS の活用による屋外の歩行者空間に適応した自律移動ロボットの開発
ROS の活用による屋外の歩行者空間に適応した自律移動ロボットの開発ROS の活用による屋外の歩行者空間に適応した自律移動ロボットの開発
ROS の活用による屋外の歩行者空間に適応した自律移動ロボットの開発Yoshitaka HARA
 
LiDAR点群と画像とのマッピング
LiDAR点群と画像とのマッピングLiDAR点群と画像とのマッピング
LiDAR点群と画像とのマッピングTakuya Minagawa
 
ROS2勉強会 4章前半
ROS2勉強会 4章前半ROS2勉強会 4章前半
ROS2勉強会 4章前半tomohiro kuwano
 
[DL輪読会]画像を使ったSim2Realの現況
[DL輪読会]画像を使ったSim2Realの現況[DL輪読会]画像を使ったSim2Realの現況
[DL輪読会]画像を使ったSim2Realの現況Deep Learning JP
 
Cartographer と Autoware を用いた自律走行
Cartographer と Autoware を用いた自律走行Cartographer と Autoware を用いた自律走行
Cartographer と Autoware を用いた自律走行Yoshitaka HARA
 
STMとROSをシリアル通信させて移動ロボットを作る
STMとROSをシリアル通信させて移動ロボットを作るSTMとROSをシリアル通信させて移動ロボットを作る
STMとROSをシリアル通信させて移動ロボットを作るmozyanari
 
DockerコンテナでGitを使う
DockerコンテナでGitを使うDockerコンテナでGitを使う
DockerコンテナでGitを使うKazuhiro Suga
 
Apache Arrow - データ処理ツールの次世代プラットフォーム
Apache Arrow - データ処理ツールの次世代プラットフォームApache Arrow - データ処理ツールの次世代プラットフォーム
Apache Arrow - データ処理ツールの次世代プラットフォームKouhei Sutou
 
Deep Learningを用いたロボット制御
Deep Learningを用いたロボット制御Deep Learningを用いたロボット制御
Deep Learningを用いたロボット制御Ryosuke Okuta
 
Open3DでSLAM入門 PyCon Kyushu 2018
Open3DでSLAM入門 PyCon Kyushu 2018Open3DでSLAM入門 PyCon Kyushu 2018
Open3DでSLAM入門 PyCon Kyushu 2018Satoshi Fujimoto
 
四脚ロボットによる つくばチャレンジへの取り組み
四脚ロボットによるつくばチャレンジへの取り組み四脚ロボットによるつくばチャレンジへの取り組み
四脚ロボットによる つくばチャレンジへの取り組みkiyoshiiriemon
 
Surveyから始まる研究者への道 - Stand on the shoulders of giants -
Surveyから始まる研究者への道 - Stand on the shoulders of giants -Surveyから始まる研究者への道 - Stand on the shoulders of giants -
Surveyから始まる研究者への道 - Stand on the shoulders of giants -諒介 荒木
 
Gazebo/ROSで力覚センサプラグインを使う
Gazebo/ROSで力覚センサプラグインを使うGazebo/ROSで力覚センサプラグインを使う
Gazebo/ROSで力覚センサプラグインを使うHDeanK
 

Was ist angesagt? (20)

オープンソース SLAM の分類
オープンソース SLAM の分類オープンソース SLAM の分類
オープンソース SLAM の分類
 
NDTスキャンマッチング 第1回3D勉強会@PFN 2018年5月27日
NDTスキャンマッチング 第1回3D勉強会@PFN 2018年5月27日NDTスキャンマッチング 第1回3D勉強会@PFN 2018年5月27日
NDTスキャンマッチング 第1回3D勉強会@PFN 2018年5月27日
 
研究効率化Tips Ver.2
研究効率化Tips Ver.2研究効率化Tips Ver.2
研究効率化Tips Ver.2
 
ORB-SLAMの手法解説
ORB-SLAMの手法解説ORB-SLAMの手法解説
ORB-SLAMの手法解説
 
「伝わるチケット」の書き方
「伝わるチケット」の書き方「伝わるチケット」の書き方
「伝わるチケット」の書き方
 
モデル高速化百選
モデル高速化百選モデル高速化百選
モデル高速化百選
 
ROS の活用による屋外の歩行者空間に適応した自律移動ロボットの開発
ROS の活用による屋外の歩行者空間に適応した自律移動ロボットの開発ROS の活用による屋外の歩行者空間に適応した自律移動ロボットの開発
ROS の活用による屋外の歩行者空間に適応した自律移動ロボットの開発
 
LiDAR点群と画像とのマッピング
LiDAR点群と画像とのマッピングLiDAR点群と画像とのマッピング
LiDAR点群と画像とのマッピング
 
ROS2勉強会 4章前半
ROS2勉強会 4章前半ROS2勉強会 4章前半
ROS2勉強会 4章前半
 
[DL輪読会]画像を使ったSim2Realの現況
[DL輪読会]画像を使ったSim2Realの現況[DL輪読会]画像を使ったSim2Realの現況
[DL輪読会]画像を使ったSim2Realの現況
 
Cartographer と Autoware を用いた自律走行
Cartographer と Autoware を用いた自律走行Cartographer と Autoware を用いた自律走行
Cartographer と Autoware を用いた自律走行
 
STMとROSをシリアル通信させて移動ロボットを作る
STMとROSをシリアル通信させて移動ロボットを作るSTMとROSをシリアル通信させて移動ロボットを作る
STMとROSをシリアル通信させて移動ロボットを作る
 
DockerコンテナでGitを使う
DockerコンテナでGitを使うDockerコンテナでGitを使う
DockerコンテナでGitを使う
 
Apache Arrow - データ処理ツールの次世代プラットフォーム
Apache Arrow - データ処理ツールの次世代プラットフォームApache Arrow - データ処理ツールの次世代プラットフォーム
Apache Arrow - データ処理ツールの次世代プラットフォーム
 
Deep Learningを用いたロボット制御
Deep Learningを用いたロボット制御Deep Learningを用いたロボット制御
Deep Learningを用いたロボット制御
 
Open3DでSLAM入門 PyCon Kyushu 2018
Open3DでSLAM入門 PyCon Kyushu 2018Open3DでSLAM入門 PyCon Kyushu 2018
Open3DでSLAM入門 PyCon Kyushu 2018
 
四脚ロボットによる つくばチャレンジへの取り組み
四脚ロボットによるつくばチャレンジへの取り組み四脚ロボットによるつくばチャレンジへの取り組み
四脚ロボットによる つくばチャレンジへの取り組み
 
Visual slam
Visual slamVisual slam
Visual slam
 
Surveyから始まる研究者への道 - Stand on the shoulders of giants -
Surveyから始まる研究者への道 - Stand on the shoulders of giants -Surveyから始まる研究者への道 - Stand on the shoulders of giants -
Surveyから始まる研究者への道 - Stand on the shoulders of giants -
 
Gazebo/ROSで力覚センサプラグインを使う
Gazebo/ROSで力覚センサプラグインを使うGazebo/ROSで力覚センサプラグインを使う
Gazebo/ROSで力覚センサプラグインを使う
 

Ähnlich wie ROS2勉強会@別府 第7章Pythonクライアントライブラリrclpy

Linuxカーネルを読んで改めて知るプロセスとスレッドの違い
Linuxカーネルを読んで改めて知るプロセスとスレッドの違いLinuxカーネルを読んで改めて知るプロセスとスレッドの違い
Linuxカーネルを読んで改めて知るプロセスとスレッドの違いRetrieva inc.
 
Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM  Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM Mark Rees
 
SCALE 15x Minimizing PostgreSQL Major Version Upgrade Downtime
SCALE 15x Minimizing PostgreSQL Major Version Upgrade DowntimeSCALE 15x Minimizing PostgreSQL Major Version Upgrade Downtime
SCALE 15x Minimizing PostgreSQL Major Version Upgrade DowntimeJeff Frost
 
Linux 系統管理與安全:基本 Linux 系統知識
Linux 系統管理與安全:基本 Linux 系統知識Linux 系統管理與安全:基本 Linux 系統知識
Linux 系統管理與安全:基本 Linux 系統知識維泰 蔡
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовYandex
 
Python na Infraestrutura 
MySQL do Facebook

Python na Infraestrutura 
MySQL do Facebook
Python na Infraestrutura 
MySQL do Facebook

Python na Infraestrutura 
MySQL do Facebook
Artur Rodrigues
 
The Ring programming language version 1.7 book - Part 83 of 196
The Ring programming language version 1.7 book - Part 83 of 196The Ring programming language version 1.7 book - Part 83 of 196
The Ring programming language version 1.7 book - Part 83 of 196Mahmoud Samir Fayed
 
Gazelle - Plack Handler for performance freaks #yokohamapm
Gazelle - Plack Handler for performance freaks #yokohamapmGazelle - Plack Handler for performance freaks #yokohamapm
Gazelle - Plack Handler for performance freaks #yokohamapmMasahiro Nagano
 
Beyond the Query: A Cassandra + Solr + Spark Love Triangle Using Datastax Ent...
Beyond the Query: A Cassandra + Solr + Spark Love Triangle Using Datastax Ent...Beyond the Query: A Cassandra + Solr + Spark Love Triangle Using Datastax Ent...
Beyond the Query: A Cassandra + Solr + Spark Love Triangle Using Datastax Ent...DataStax Academy
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansiblebcoca
 
The Ring programming language version 1.5.3 book - Part 87 of 184
The Ring programming language version 1.5.3 book - Part 87 of 184The Ring programming language version 1.5.3 book - Part 87 of 184
The Ring programming language version 1.5.3 book - Part 87 of 184Mahmoud Samir Fayed
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Qiangning Hong
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたTaro Matsuzawa
 
Node.js System: The Landing
Node.js System: The LandingNode.js System: The Landing
Node.js System: The LandingHaci Murat Yaman
 
PostgreSQL Open SV 2018
PostgreSQL Open SV 2018PostgreSQL Open SV 2018
PostgreSQL Open SV 2018artgillespie
 
Hacking parse.y (RubyConf 2009)
Hacking parse.y (RubyConf 2009)Hacking parse.y (RubyConf 2009)
Hacking parse.y (RubyConf 2009)ujihisa
 

Ähnlich wie ROS2勉強会@別府 第7章Pythonクライアントライブラリrclpy (20)

Linuxカーネルを読んで改めて知るプロセスとスレッドの違い
Linuxカーネルを読んで改めて知るプロセスとスレッドの違いLinuxカーネルを読んで改めて知るプロセスとスレッドの違い
Linuxカーネルを読んで改めて知るプロセスとスレッドの違い
 
Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM  Relational Database Access with Python ‘sans’ ORM
Relational Database Access with Python ‘sans’ ORM
 
SCALE 15x Minimizing PostgreSQL Major Version Upgrade Downtime
SCALE 15x Minimizing PostgreSQL Major Version Upgrade DowntimeSCALE 15x Minimizing PostgreSQL Major Version Upgrade Downtime
SCALE 15x Minimizing PostgreSQL Major Version Upgrade Downtime
 
Boosting Developer Productivity with Clang
Boosting Developer Productivity with ClangBoosting Developer Productivity with Clang
Boosting Developer Productivity with Clang
 
Stop Monkeys Fall
Stop Monkeys FallStop Monkeys Fall
Stop Monkeys Fall
 
Linux 系統管理與安全:基本 Linux 系統知識
Linux 系統管理與安全:基本 Linux 系統知識Linux 系統管理與安全:基本 Linux 系統知識
Linux 系統管理與安全:基本 Linux 系統知識
 
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан КольцовRust: код может быть одновременно безопасным и быстрым, Степан Кольцов
Rust: код может быть одновременно безопасным и быстрым, Степан Кольцов
 
Python na Infraestrutura 
MySQL do Facebook

Python na Infraestrutura 
MySQL do Facebook
Python na Infraestrutura 
MySQL do Facebook

Python na Infraestrutura 
MySQL do Facebook

 
Fact, Fiction, and FP
Fact, Fiction, and FPFact, Fiction, and FP
Fact, Fiction, and FP
 
lecture56.ppt
lecture56.pptlecture56.ppt
lecture56.ppt
 
The Ring programming language version 1.7 book - Part 83 of 196
The Ring programming language version 1.7 book - Part 83 of 196The Ring programming language version 1.7 book - Part 83 of 196
The Ring programming language version 1.7 book - Part 83 of 196
 
Gazelle - Plack Handler for performance freaks #yokohamapm
Gazelle - Plack Handler for performance freaks #yokohamapmGazelle - Plack Handler for performance freaks #yokohamapm
Gazelle - Plack Handler for performance freaks #yokohamapm
 
Beyond the Query: A Cassandra + Solr + Spark Love Triangle Using Datastax Ent...
Beyond the Query: A Cassandra + Solr + Spark Love Triangle Using Datastax Ent...Beyond the Query: A Cassandra + Solr + Spark Love Triangle Using Datastax Ent...
Beyond the Query: A Cassandra + Solr + Spark Love Triangle Using Datastax Ent...
 
Hacking ansible
Hacking ansibleHacking ansible
Hacking ansible
 
The Ring programming language version 1.5.3 book - Part 87 of 184
The Ring programming language version 1.5.3 book - Part 87 of 184The Ring programming language version 1.5.3 book - Part 87 of 184
The Ring programming language version 1.5.3 book - Part 87 of 184
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
 
Node.js System: The Landing
Node.js System: The LandingNode.js System: The Landing
Node.js System: The Landing
 
PostgreSQL Open SV 2018
PostgreSQL Open SV 2018PostgreSQL Open SV 2018
PostgreSQL Open SV 2018
 
Hacking parse.y (RubyConf 2009)
Hacking parse.y (RubyConf 2009)Hacking parse.y (RubyConf 2009)
Hacking parse.y (RubyConf 2009)
 

Kürzlich hochgeladen

NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdfKamal Acharya
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxchumtiyababu
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEselvakumar948
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsvanyagupta248
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilVinayVitekari
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiessarkmank1
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesRAJNEESHKUMAR341697
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptDineshKumar4165
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadhamedmustafa094
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesMayuraD1
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 

Kürzlich hochgeladen (20)

NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Verification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptxVerification of thevenin's theorem for BEEE Lab (1).pptx
Verification of thevenin's theorem for BEEE Lab (1).pptx
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 

ROS2勉強会@別府 第7章Pythonクライアントライブラリrclpy

  • 1. 2 7
  • 3. • R 2 O 7 • R • R S S
  • 4. • 2 1 1 • 3 • 2 • 4 7 • 25
  • 5. 2 1
  • 6. • RT PIO RI 2 T A O SI • t mo i mn m • c t n eA c p • S O T PTC 1 I m p ct l 6 2 5 5 11 2 26 5 fm R r g OSa nP
  • 7. l m • m w r 2 A c C R • :i i B t • Op ro f i e K OR S A PP I 2 2 y SR a 5 I f cn A
  • 8. • • :: • : • C • • . . . . • 2 2 • 2 2 • • 3 3 • + #-
  • 10. 3 2 • 3 ) Ot h r c $ ros2 pkg create –build-type ament_python YOUR_AWESOME_PACKAGE u lnkc / 2 ) / g ws_rt c • 2 ) .32uo_ k c nkkx t mP u • r a u • ( yu .32 t r / le snk (SRt cs s s .32 rgp (
  • 11. from setuptools import setup package_name = 'examples_rclpy_topics' setup( name=package_name, # パッケージ名 version='0.6.3', # バージョン番号 packages=[package_name], # ソースコードのディレクトリ data_files=[ # ソースコード以外のファイル ('share/ament_index/resource_index/packages', ['resource/’ + package_name]), ('share/' + package_name, ['package.xml']), ], install_requires=['setuptools'], # 依存Python3モジュール zip_safe=True, author='Mikael Arguedas', author_email='mikael@osrfoundation.org', maintainer='Atsuki Yokota', maintainer_email='atsuki.yokota@gmail.com',
  • 12. keywords=['ROS'], classifiers=[ # PyPIの分類情報 'Intended Audience :: Developers', 'License :: OSI Approved :: Apache Software License', 'Programming Language :: Python', 'Topic :: Software Development', ], description='Examples of publishers/subscribers using rclpy.', license='Apache License, Version 2.0', tests_require=['pytest'], # テストフレームワーク名 entry_points={ # 実行コマンド名とその呼び出し先 'console_scripts': [ 'publisher = ' + package_name + '.publisher:main', 'subscriber = ' + package_name + '.subscriber:main', ], }, )
  • 13. ; =fR • 2 2 m si a 2 . S _ R S Rc a • 2 S d_ . . o ld O • . 3 2 P b a R3 3 prl ba $ ros2 run examples_rclpy_topics publisher • O • c e u“ fys m =;2 c _b a • c ; p s e “ lays m ai t m _a =;2 c . . / . ; ; 2 S • ha ys fr mP S ai 1 ld
  • 14. , • h . 2 v x i , egkm 2h O rs PChy o n o • _h . ,. , e h x O rs a oLR y h o n v xo n e MSe find_package(std_msgs REQUIRED) find_package(action_msgs REQUIRED) find_package(rosidl_default_generators REQUIRED) rosidl_generate_interfaces(${PROJECT_NAME} "srv/SetMessage.srv" "action/Fibonacci.action" DEPENDENCIES std_msgs action_msgs ) ament_export_dependencies(rosidl_default_runtime) ament_package() ,
  • 15. 3
  • 16. import rclpy from rclpy.node import Node from std_msgs.msg import String class MinimalPublisher(Node): def __init__(self): super().__init__('minimal_publisher') self.publisher = self.create_publisher(String, 'chatter') self.timer = self.create_timer(0.5, self.timer_callback) def timer_callback(self): msg = String() msg.data = 'Hello World!' self.publisher.publish(msg) self.get_logger().info(msg.data) _e . c . dea R . . R N . R . R _e R
  • 17. def main(args=None): rclpy.init(args=args) minimal_publisher = MinimalPublisher() rclpy.spin(minimal_publisher) rclpy.shutdown() if __name__ == '__main__': main() . 1 . = 2
  • 18. import rclpy from rclpy.node import Node from std_msgs.msg import String class MinimalSubscriber(Node): def __init__(self): super().__init__('minimal_subscriber') self.subscription = self.create_subscription( String, 'chatter', self.listener_callback) def listener_callback(self, msg): self.get_logger().info(msg.data)
  • 19. def main(args=None): rclpy.init(args=args) minimal_subscriber = MinimalSubscriber() rclpy.spin(minimal_subscriber) rclpy.shutdown() if __name__ == '__main__': main()
  • 20. 4
  • 21. from example_interfaces.srv import AddTwoInts import rclpy from rclpy.node import Node class MinimalService(Node): def __init__(self): super().__init__('minimal_service') self.srv = self.create_service( AddTwoInts, 'add_two_ints', self.add_two_ints_callback) def add_two_ints_callback(self, request, response): response.sum = request.a + request.b self.get_logger().info('{} + {} = {}'.format(request.a, request.b, response.sum)) return response H , 1
  • 22. def main(args=None): rclpy.init(args=args) minimal_service = MinimalService() rclpy.spin(minimal_service) rclpy.shutdown() if __name__ == '__main__': main()
  • 23. from example_interfaces.srv import AddTwoInts import rclpy from rclpy.node import Node class MinimalClient(Node): def __init__(self): super().__init__('minimal_client') self.client = self.create_client(AddTwoInts, 'add_two_ints') while not self.client.wait_for_service(timeout_sec=1.0): self.get_logger().info('waiting...') self.request = AddTwoInts.Request() def call_async(self): self.request.a = 1 self.request.b = 2 return self.client.call_async(self.request) 1 1
  • 24. def main(args=None): rclpy.init(args=args) minimal_client = MinimalClient() future = minimal_client.call_async() rclpy.spin_until_future_complete(minimal_client, future) if future.done() and future.result() is not None: response = future.result() minimal_client.get_logger().info('{} + {} = {}'.format( minimal_client.request.a, minimal_client.request.b, response.sum)) rclpy.shutdown() F F
  • 25. 5
  • 26. import time from example_interfaces.action import Fibonacci import rclpy from rclpy.action import ActionServer, CancelResponse, GoalResponse from rclpy.callback_groups import ReentrantCallbackGroup from rclpy.executors import MultiThreadedExecutor from rclpy.node import Node class MinimalActionServer(Node): def __init__(self): super().__init__('minimal_action_server') self._action_server = ActionServer( self, Fibonacci, 'fibonacci', execute_callback=self.execute_callback, callback_group=ReentrantCallbackGroup()) _e _ b ec b aec
  • 27. def destroy(self): self._action_server.destroy() super().destroy_node() async def execute_callback(self, goal_handle): self.get_logger().info('executing...') msg = Fibonacci.Feedback() msg.sequence = [0, 1] for i in range(1, goal_handle.request.order): if goal_handle.is_cancel_requested: goal_handle.canceled() self.get_logger().info('goal_canceled') return Fibonacci.Result() msg.sequence.append(msg.sequence[i] + msg.sequence[i-1]) self.get_logger().info('feedback:{}'.format(msg.sequence)) goal_handle.publish_feedback(msg) time.sleep(1) # dummy job . / / PdI c w sn i f a h f . i f f t t Oe 5 3 Pd f f t f f
  • 28. goal_handle.set_succeeded() result = Fibonacci.Result() result.sequence = msg.sequence self.get_logger().info('result:{}'.format(result.sequence)) return result def main(args=None): rclpy.init(args=args) minimal_action_server = MinimalActionServer() executor = MultiThreadedExecutor() rclpy.spin(minimal_action_server, executor=executor) minimal_action_server.destroy() rclpy.shutdown() if __name__ == '__main__': main() E E
  • 29. from action_msgs.msg import GoalStatus from example_interfaces.action import Fibonacci import rclpy from rclpy.action import ActionClient from rclpy.node import Node class MinimalActionClient(Node): def __init__(self): super().__init__('minimal_action_client') self._action_client = ActionClient(self, Fibonacci, 'fibonacci')
  • 30. def goal_response_callback(self, future): goal_handle = future.result() if not goal_handle.accepted: self.get_logger().info('goal rejected') return self._get_result_future = goal_handle.get_result_async() self._get_result_future.add_done_callback(self.get_result_callback) def feedback_callback(self, feedback): self.get_logger().info('feedback:{}'.format( feedback.feedback.sequence))
  • 31. def get_result_callback(self, future): status = future.result().action_status if status == GoalStatus.STATUS_SUCCEEDED: self.get_logger().info('result:{}'.format( future.result().requence)) rclpy.shutdown() def send_goal(self): self.get_logger().info('waiting...') self._action_client.wait_for_server() goal_msg = Fibonacci.Goal() goal_msg.order = 10 self._send_goal_future = self._action_client.send_goal_async( goal_msg, feedback_callback=self.feedback_callback) self._send_goal_future.add_done_callback( self.goal_response_callback) ca _ b b 3 b c b
  • 32. def main(args=None): rclpy.init(args=args) action_client = MinimalActionClient() action_client.send_goal() rclpy.spin(action_client) action_client.destroy_node() if __name__ == '__main__': main() D