setup.py
파이썬 파일 ros2 run으로 실행하려면 setup.py 파일에 entry_points 부분에 파일명 추가
'실행 시 사용될 이름 = 패키지 이름.파일 이름:main'
entry_points={
'console_scripts': [
'example_node_1 = basic_topic_pkg.node_example_1:main',
'example_node_2 = basic_topic_pkg.node_example_2:main',
'example_node_3 = basic_topic_pkg.node_example_3:main',
'example_node_4 = basic_topic_pkg.node_example_4:main',
'example_node_5 = basic_topic_pkg.node_example_5:main',
'example_node_6 = basic_topic_pkg.node_example_6:main',
'topic_pub_node = basic_topic_pkg.topic_example_1_publisher:main',
'topic_sub_node = basic_topic_pkg.topic_example_2_subscriber:main',
'mimic_node = basic_topic_pkg.topic_example_4_mimic:main',
],
},
Timer
node.create_timer(주기, 콜백 함수 이름)
count = 0
def timer_callback():
global count
count += 1
print(f'==== Hello ROS 2 : {count}====')
Spin: Node의 상태를 지속적으로 살핌
rclpy.spin(node)
Node Composition: Node의 생성을 객체지향으로 구현
생성자내에서 super().__init__('노드 이름')
class NodeClass(Node):
def __init__(self):
super().__init__('node_name')
self.create_timer(0.2, self.timer_callback)
self.count = 1
def timer_callback(self):
self.get_logger().info(f'==== Hello ROS2 : {self.count} ====')
self.count += 1
def main(args=None):
rclpy.init(args=args)
node = NodeClass()
node.get_logger().info('\n==== Create Node ====')
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
"""main function"""
main()
Logger Level: 콘솔 출력 글씨 색
get_logger().< >();
info: 흰색
warn: 노란색
error, fatal: 빨간색
'ROS2' 카테고리의 다른 글
6일차 & 7일차 (0) | 2022.07.19 |
---|---|
ROS2 Service 프로그래밍 (0) | 2022.07.18 |
ROS2 Topic 프로그래밍 (0) | 2022.07.17 |
ROS2 Launch file (0) | 2022.07.17 |