diff --git a/device/pi_i2c/README.md b/device/pi_i2c/README.md new file mode 100644 index 0000000..982084f --- /dev/null +++ b/device/pi_i2c/README.md @@ -0,0 +1,20 @@ +# nucleo communication + +Raspberry PiのI2C接続 + +## Nodes + +- `Depth`: 深さセンサー +- `Imu`: IMU + +## Executables + +- `depth`: `Depth`Nodeをspin +- `imu`: `Imu`Nodeをspin +- `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/package.xml b/device/pi_i2c/package.xml new file mode 100644 index 0000000..8a0c634 --- /dev/null +++ b/device/pi_i2c/package.xml @@ -0,0 +1,17 @@ + + + + pi_i2c + 0.1.0 + Raspberry PiのI2C接続 + h1rono + MIT + + rclpy + sensor_msgs + packet_interfaces + + + 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/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..ea30254 --- /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 as DepthMsg + + +class Depth(Node): + def __init__(self) -> None: + super().__init__("depth") + self._current_publisher = self.create_publisher(DepthMsg, "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..6df5709 --- /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 as ImuMsg + + +class Imu(Node): + def __init__(self) -> None: + super().__init__("imu") + self._current_publisher = self.create_publisher(ImuMsg, "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 = Imu() + rclpy.spin(imu) + imu.destroy_node() + rclpy.shutdown() + + +if __name__ == "__main__": + main() 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..f530acc --- /dev/null +++ b/device/pi_i2c/setup.py @@ -0,0 +1,33 @@ +import os +from glob import glob + +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']), + (os.path.join('share', package_name, 'launch'), glob(os.path.join('launch', '*'))) + ], + 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': [ + "depth = pi_i2c.depth:main", + "imu = pi_i2c.imu:main", + "all = pi_i2c.all:main" + ], + }, +) diff --git a/device/pi_i2c/test/.gitkeep b/device/pi_i2c/test/.gitkeep new file mode 100644 index 0000000..e69de29