ROS bag play in python

최준혁·2021년 12월 21일
0

ROS_Tip

목록 보기
1/4
subprocess 모듈은 파이썬 프로그램 내에서 새로운 프로세스를 스폰하고 여기에 입출력 파이프를 연결하며 리턴코드를 획득할 수 있도록 하는 모듈로, 다른 언어로 만들어진 프로그램을 통합, 제어할 수 있게 만드는 모듈이다. 이 모듈은 기존에 오랜된 몇몇 모듈과 함수(os.system, os.spawn*)들을 대체하기 위해 만들어졌다. (혹은 os.popen 같은 함수도…)

node
#!/usr/bin/env python
import rospy
import subprocess

rospy.init_node("none")
player_proc = subprocess.Popen(['rosbag', 'play', 'subset.bag', '-q'], cwd="/home/cjh/catkin_ws/src/test/bags/")

이를 이용하여 launch file에서도 실행해보자.

launch file
<launch>
  <node pkg="rosbag_test" type="test.py" name="test_node" >
  </node>
</launch>

이와 같이 rosbag을 파이썬으로 node name을 부여하여 play 할 수 있다.

[ref]

profile
3D Vision, VSLAM, Robotics, Deep_Learning

0개의 댓글