From a5430f1d5703ed1dbd8e7145751af34bbe907a6b Mon Sep 17 00:00:00 2001 From: H1rono Date: Thu, 30 May 2024 18:24:20 +0900 Subject: [PATCH 1/5] Create package --- device/pi_i2c/README.md | 9 +++++++++ device/pi_i2c/package.xml | 13 +++++++++++++ device/pi_i2c/pi_i2c/__init__.py | 0 device/pi_i2c/resource/pi_i2c | 0 device/pi_i2c/setup.cfg | 4 ++++ device/pi_i2c/setup.py | 25 +++++++++++++++++++++++++ device/pi_i2c/test/.gitkeep | 0 7 files changed, 51 insertions(+) create mode 100644 device/pi_i2c/README.md create mode 100644 device/pi_i2c/package.xml create mode 100644 device/pi_i2c/pi_i2c/__init__.py create mode 100644 device/pi_i2c/resource/pi_i2c create mode 100644 device/pi_i2c/setup.cfg create mode 100644 device/pi_i2c/setup.py create mode 100644 device/pi_i2c/test/.gitkeep diff --git a/device/pi_i2c/README.md b/device/pi_i2c/README.md new file mode 100644 index 0000000..4c03b9b --- /dev/null +++ b/device/pi_i2c/README.md @@ -0,0 +1,9 @@ +# nucleo communication + +Raspberry PiのI2C接続 + +## Nodes + +## Executables + +## Launches diff --git a/device/pi_i2c/package.xml b/device/pi_i2c/package.xml new file mode 100644 index 0000000..95c8924 --- /dev/null +++ b/device/pi_i2c/package.xml @@ -0,0 +1,13 @@ + + + + pi_i2c + 0.1.0 + Raspberry PiのI2C接続 + h1rono + MIT + + + ament_python + + diff --git a/device/pi_i2c/pi_i2c/__init__.py b/device/pi_i2c/pi_i2c/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/device/pi_i2c/resource/pi_i2c b/device/pi_i2c/resource/pi_i2c new file mode 100644 index 0000000..e69de29 diff --git a/device/pi_i2c/setup.cfg b/device/pi_i2c/setup.cfg new file mode 100644 index 0000000..92710de --- /dev/null +++ b/device/pi_i2c/setup.cfg @@ -0,0 +1,4 @@ +[develop] +script_dir=$base/lib/pi_i2c +[install] +install_scripts=$base/lib/pi_i2c diff --git a/device/pi_i2c/setup.py b/device/pi_i2c/setup.py new file mode 100644 index 0000000..d2d1ee7 --- /dev/null +++ b/device/pi_i2c/setup.py @@ -0,0 +1,25 @@ +from setuptools import find_packages, setup + +package_name = 'pi_i2c' + +setup( + name=package_name, + version='0.1.0', + packages=find_packages(exclude=['test']), + data_files=[ + ('share/ament_index/resource_index/packages', + ['resource/' + package_name]), + ('share/' + package_name, ['package.xml']), + ], + install_requires=['setuptools'], + zip_safe=True, + maintainer='h1rono', + maintainer_email='hronok66@gmail.com', + description='Raspberry PiのI2C接続', + license='MIT', + tests_require=[], + entry_points={ + 'console_scripts': [ + ], + }, +) diff --git a/device/pi_i2c/test/.gitkeep b/device/pi_i2c/test/.gitkeep new file mode 100644 index 0000000..e69de29 From 7f73081d07ea78dd82942e6fd8d1cb42665d6bd7 Mon Sep 17 00:00:00 2001 From: H1rono Date: Thu, 30 May 2024 18:51:51 +0900 Subject: [PATCH 2/5] Add dependencies --- device/pi_i2c/package.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/device/pi_i2c/package.xml b/device/pi_i2c/package.xml index 95c8924..8a0c634 100644 --- a/device/pi_i2c/package.xml +++ b/device/pi_i2c/package.xml @@ -7,6 +7,10 @@ h1rono MIT + rclpy + sensor_msgs + packet_interfaces + ament_python From dcba574db8c4ebce699a618108b11ccbaf7610c0 Mon Sep 17 00:00:00 2001 From: H1rono Date: Thu, 30 May 2024 18:54:59 +0900 Subject: [PATCH 3/5] Add nodes and executables --- device/pi_i2c/README.md | 7 +++++++ device/pi_i2c/pi_i2c/all.py | 27 +++++++++++++++++++++++++++ device/pi_i2c/pi_i2c/depth.py | 29 +++++++++++++++++++++++++++++ device/pi_i2c/pi_i2c/imu.py | 29 +++++++++++++++++++++++++++++ device/pi_i2c/setup.py | 3 +++ 5 files changed, 95 insertions(+) create mode 100644 device/pi_i2c/pi_i2c/all.py create mode 100644 device/pi_i2c/pi_i2c/depth.py create mode 100644 device/pi_i2c/pi_i2c/imu.py diff --git a/device/pi_i2c/README.md b/device/pi_i2c/README.md index 4c03b9b..3cdad9a 100644 --- a/device/pi_i2c/README.md +++ b/device/pi_i2c/README.md @@ -4,6 +4,13 @@ Raspberry PiのI2C接続 ## Nodes +- `Depth`: 深さセンサー +- `Imu`: IMU + ## Executables +- `depth`: `Depth`Nodeをspin +- `imu`: `Imu`Nodeをspin +- `all`: `Depth`, `Imu`Node2つを同時にspin + ## Launches diff --git a/device/pi_i2c/pi_i2c/all.py b/device/pi_i2c/pi_i2c/all.py new file mode 100644 index 0000000..46b8db1 --- /dev/null +++ b/device/pi_i2c/pi_i2c/all.py @@ -0,0 +1,27 @@ +import sys + +import rclpy +from rclpy.executors import SingleThreadedExecutor, ExternalShutdownException + +from .depth import Depth +from .imu import Imu + + +def main(args=sys.argv): + rclpy.init(args=args) + try: + depth = Depth() + imu = Imu() + + executor = SingleThreadedExecutor() + executor.add_node(depth) + executor.add_node(imu) + executor.spin() + except KeyboardInterrupt: + pass + except ExternalShutdownException: + sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/device/pi_i2c/pi_i2c/depth.py b/device/pi_i2c/pi_i2c/depth.py new file mode 100644 index 0000000..740cb05 --- /dev/null +++ b/device/pi_i2c/pi_i2c/depth.py @@ -0,0 +1,29 @@ +import sys + +import rclpy +from rclpy.node import Node +from packet_interfaces.msg import Depth + + +class Depth(Node): + def __init__(self) -> None: + super().__init__("depth") + self._current_publisher = self.create_publisher(Depth, "depth", 10) + self._timer = self.create_timer(0.5, self._timer_callback) + + def _timer_callback(self) -> None: + # TODO + # 深さセンサーからデータを取得してpublish + self.get_logger().info("tick") + + +def main(args=sys.argv): + rclpy.init(args=args) + depth = Depth() + rclpy.spin(depth) + depth.destroy_node() + rclpy.shutdown() + + +if __name__ == "__main__": + main() diff --git a/device/pi_i2c/pi_i2c/imu.py b/device/pi_i2c/pi_i2c/imu.py new file mode 100644 index 0000000..fa6f0d1 --- /dev/null +++ b/device/pi_i2c/pi_i2c/imu.py @@ -0,0 +1,29 @@ +import sys + +import rclpy +from rclpy.node import Node +from sensor_msgs.msg import Imu + + +class Depth(Node): + def __init__(self) -> None: + super().__init__("imu") + self._current_publisher = self.create_publisher(Imu, "imu", 10) + self._timer = self.create_timer(0.5, self._timer_callback) + + def _timer_callback(self) -> None: + # TODO + # IMUからデータを取得してpublish + self.get_logger().info("tick") + + +def main(args=sys.argv): + rclpy.init(args=args) + imu = Depth() + rclpy.spin(imu) + imu.destroy_node() + rclpy.shutdown() + + +if __name__ == "__main__": + main() diff --git a/device/pi_i2c/setup.py b/device/pi_i2c/setup.py index d2d1ee7..b82d76a 100644 --- a/device/pi_i2c/setup.py +++ b/device/pi_i2c/setup.py @@ -20,6 +20,9 @@ tests_require=[], entry_points={ 'console_scripts': [ + "depth = pi_i2c.depth:main", + "imu = pi_i2c.imu:main", + "all = pi_i2c.all:main" ], }, ) From a60905d64b569b8db9d91fd26f9da552f6a96b6e Mon Sep 17 00:00:00 2001 From: H1rono Date: Thu, 30 May 2024 19:05:22 +0900 Subject: [PATCH 4/5] Add launch files --- device/pi_i2c/README.md | 4 ++++ device/pi_i2c/launch/all_launch.py | 11 +++++++++++ device/pi_i2c/launch/depth_launch.py | 11 +++++++++++ device/pi_i2c/launch/imu_launch.py | 11 +++++++++++ device/pi_i2c/setup.py | 5 +++++ 5 files changed, 42 insertions(+) create mode 100644 device/pi_i2c/launch/all_launch.py create mode 100644 device/pi_i2c/launch/depth_launch.py create mode 100644 device/pi_i2c/launch/imu_launch.py diff --git a/device/pi_i2c/README.md b/device/pi_i2c/README.md index 3cdad9a..982084f 100644 --- a/device/pi_i2c/README.md +++ b/device/pi_i2c/README.md @@ -14,3 +14,7 @@ Raspberry PiのI2C接続 - `all`: `Depth`, `Imu`Node2つを同時にspin ## Launches + +- `all_launch.py`: `all`executableを`device`namespace下で実行 +- `depth_launch.py`: `depth`executableを`device`namespace下で実行 +- `imu_launch.py`: `imu`executableを`device`namespace下で実行 diff --git a/device/pi_i2c/launch/all_launch.py b/device/pi_i2c/launch/all_launch.py new file mode 100644 index 0000000..213fc56 --- /dev/null +++ b/device/pi_i2c/launch/all_launch.py @@ -0,0 +1,11 @@ +from launch import LaunchDescription +from launch_ros.actions import Node + + +def generate_launch_description() -> LaunchDescription: + all_exec = Node( + package="pi_i2c", + executable="all", + namespace="device" + ) + return LaunchDescription([all_exec]) diff --git a/device/pi_i2c/launch/depth_launch.py b/device/pi_i2c/launch/depth_launch.py new file mode 100644 index 0000000..51d1c56 --- /dev/null +++ b/device/pi_i2c/launch/depth_launch.py @@ -0,0 +1,11 @@ +from launch import LaunchDescription +from launch_ros.actions import Node + + +def generate_launch_description() -> LaunchDescription: + depth = Node( + package="pi_i2c", + executable="depth", + namespace="device" + ) + return LaunchDescription([depth]) diff --git a/device/pi_i2c/launch/imu_launch.py b/device/pi_i2c/launch/imu_launch.py new file mode 100644 index 0000000..54f129a --- /dev/null +++ b/device/pi_i2c/launch/imu_launch.py @@ -0,0 +1,11 @@ +from launch import LaunchDescription +from launch_ros.actions import Node + + +def generate_launch_description() -> LaunchDescription: + imu = Node( + package="pi_i2c", + executable="imu", + namespace="device" + ) + return LaunchDescription([imu]) diff --git a/device/pi_i2c/setup.py b/device/pi_i2c/setup.py index b82d76a..f530acc 100644 --- a/device/pi_i2c/setup.py +++ b/device/pi_i2c/setup.py @@ -1,5 +1,9 @@ +import os +from glob import glob + from setuptools import find_packages, setup + package_name = 'pi_i2c' setup( @@ -10,6 +14,7 @@ ('share/ament_index/resource_index/packages', ['resource/' + package_name]), ('share/' + package_name, ['package.xml']), + (os.path.join('share', package_name, 'launch'), glob(os.path.join('launch', '*'))) ], install_requires=['setuptools'], zip_safe=True, From 68a95971754072f965bcac65de013f95f0b8ebe2 Mon Sep 17 00:00:00 2001 From: H1rono Date: Thu, 30 May 2024 19:47:10 +0900 Subject: [PATCH 5/5] Fix name conflicts --- device/pi_i2c/pi_i2c/depth.py | 4 ++-- device/pi_i2c/pi_i2c/imu.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/device/pi_i2c/pi_i2c/depth.py b/device/pi_i2c/pi_i2c/depth.py index 740cb05..ea30254 100644 --- a/device/pi_i2c/pi_i2c/depth.py +++ b/device/pi_i2c/pi_i2c/depth.py @@ -2,13 +2,13 @@ import rclpy from rclpy.node import Node -from packet_interfaces.msg import Depth +from packet_interfaces.msg import Depth as DepthMsg class Depth(Node): def __init__(self) -> None: super().__init__("depth") - self._current_publisher = self.create_publisher(Depth, "depth", 10) + self._current_publisher = self.create_publisher(DepthMsg, "depth", 10) self._timer = self.create_timer(0.5, self._timer_callback) def _timer_callback(self) -> None: diff --git a/device/pi_i2c/pi_i2c/imu.py b/device/pi_i2c/pi_i2c/imu.py index fa6f0d1..6df5709 100644 --- a/device/pi_i2c/pi_i2c/imu.py +++ b/device/pi_i2c/pi_i2c/imu.py @@ -2,13 +2,13 @@ import rclpy from rclpy.node import Node -from sensor_msgs.msg import Imu +from sensor_msgs.msg import Imu as ImuMsg -class Depth(Node): +class Imu(Node): def __init__(self) -> None: super().__init__("imu") - self._current_publisher = self.create_publisher(Imu, "imu", 10) + self._current_publisher = self.create_publisher(ImuMsg, "imu", 10) self._timer = self.create_timer(0.5, self._timer_callback) def _timer_callback(self) -> None: @@ -19,7 +19,7 @@ def _timer_callback(self) -> None: def main(args=sys.argv): rclpy.init(args=args) - imu = Depth() + imu = Imu() rclpy.spin(imu) imu.destroy_node() rclpy.shutdown()