본문 바로가기
Robot/ROS

[ROS2] 치트시트

by interactics 2022. 8. 14.

원래 자꾸 까먹는 것은 모아두고 필요할 때마다 봐야합니다. 어떻게 그걸 다 외우나요?

 

ROS2 삭제

#본인의 ROS 버전을 적습니다.
sudo apt remove ~nros-foxy-* && sudo apt autoremove 

sudo rm /etc/apt/sources.list.d/ros2.list
sudo apt update
sudo apt autoremove
# Consider upgrading for packages previously shadowed.
sudo apt upgrade

 

ROS2 CLI

패키지

패키지 생성하는 명령어

ros2 pkg create --build-type ament_cmake <패키지_이름> --dependencies <의존_패키지> --node-name <만들_노드이름>

 

LOG

# Foxy 버전
ros2 run <패키지_이름> <노드_이름> --ros-args --log-level debug

# Galactic ~ Humble
ros2 run <패키지_이름> <노드_이름> --ros-args --log-level <로거_이름(logger_usage)>:=debug

 

pub

CLI로 multiarray 메시지 퍼블리시하기

ros2 topic pub /multiarray_msg  std_msgs/Float32MultiArray '{layout: {dim: [{label: 'abc', size: 2, stride: 2}], data_offset: 2}, data: [1.0, 5.0]}'

 

 

action

ros2 action send_goal
ROS2 action 메시지를 터미널에서 퍼블리시할 때

ros2 action send_goal <action_name> <action_type> '<value>'
#ex) ros2 action send_goal /action_name interfaces/action/type 'point: {x: 0, y: 0, z: 0}'
#ex) ros2 action send_goal /turtle1/rotate_absolute turtlesim/action/RotateAbsolute "{theta: 1.5708}"

이 때 Action 메시지 형태는 각각

### interfaces/action/type

# Goal
geometry_msgs/Point point
---
# Result
bool result
---
# Feedback
bool feedback

-----------------
### turtlesim/action/RotateAbsolute

# The desired heading in radians
float32 theta
---
# The angular displacement in radians to the starting position
float32 delta
---
# The remaining rotation in radians
float32 remaining

이다.

 

옵션

--feedback 피드백이 지속적으로 표시가 된다.

 

 

 

기타 패키지

TF StaticTransformBroadcaster

터미널에서 사용할 때

RPY

단위는 [m]와 [rad]입니다.

ros2 run tf2_ros static_transform_publisher x y z yaw pitch roll frame_id child_frame_id

쿼터니언

ros2 run tf2_ros static_transform_publisher x y z qx qy qz qw frame_id child_frame_id

 

런치파일에서 사용할 때

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
   return LaunchDescription([
      Node(
            package='tf2_ros',
            executable='static_transform_publisher',
            arguments = ['0', '0', '1', '0', '0', '0', 'world', 'mystaticturtle']
      ),
   ])

 

댓글