ROS2 package design(2)

이준혁·2024년 12월 18일

ROS2

목록 보기
6/14

제가 작성하는 이 글은 제가 공부하기 위해 작성하고 제 학교 후배들에게 조금이라도 ros에 대해서 접하게 하고자 작성하게 되었습니다. 그러니 만약 틀린내용이나 그러니 제가 부족한 부분이 있을수 있으니 주의해주면서 봐주시면 감사하겠습니다 -Happy Lee-


2. 패키지 제작

ros2 pkg create --build-type ament_python py_test

다음 파이썬 코드를 제작하기 위한 패키지 입니다.
py_test/

├── package.xml
├── py_test/
│ └── init.py

├── resource/
│ └── py_test

├── setup.cfg
├── setup.py

└── test/
├── test_copyright.py
├── test_flake8.py
└── test_pep257.py

이렇게 디자인이 되면 다음 이제 패키지 설계부분에서는

2.1 Package.xml

코드

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <name>ex_calculator</name>
  <version>0.0.0</version>
  <description>TODO: Package description</description>
  <maintainer email="leejh104@naver.com">park</maintainer>
  <license>TODO: License declaration</license>

# 추가 ------------------------------------------------------
  <depend>rclpy</depend>
  <depend>std_msgs</depend>
  <depend>study_msg</depend>
# ---------------------------------------------------------

  <test_depend>ament_copyright</test_depend>
  <test_depend>ament_flake8</test_depend>
  <test_depend>ament_pep257</test_depend>
  <test_depend>python3-pytest</test_depend>

  <export>
    <build_type>ament_python</build_type>
  </export>
</package>

rclpy : ROS2의 Python 클라이언트 라이브러리로 python으로 작성된 ros2 노드가 동작할수 있도록함
std_msgs : ROS2에서 제공하는 표준 메시지 패키지로 기본 데이터 타임에 메시지로 사용할 때 필요합니다.
study_msg : 사용자가 정의한 메시지 타입으로 사용을 위한 의존성을 제공하는것

2.2 setup.py

from setuptools import find_packages, setup

package_name = 'py_test'

setup(
    name=package_name,
    version='0.0.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='happy',
    maintainer_email='happy@todo.todo',
    description='TODO: Package description',
    license='TODO: License declaration',
    tests_require=['pytest'],
    entry_points={
        'console_scripts': [
        # 변경사항------------------------------------------
            'argument = py_test.arithmetic.argument:main',
            'operator = py_test.arithmetic.operator:main',
            'calculator = py_test.calculator.main:main',
            'checker = py_test.checker.main:main',
        ],
    },
)

여기서

entry_points : 이것은 ros2 run 에서 돌리는 프로그램의 이름을 작성하는 것이다. 그래서 이어지는 것을 이름을 작성하는것

profile
#자기공부 #틀린것도많음 #자기개발 여러분 인생이 힘들다 하더라도 그것을 깨는 순간 큰 희열감으로 옵니다~

0개의 댓글