PX4의 ROS 기반 통합 테스트 방법을 설명합니다.
전제 조건
테스트 실행
MAVROS 테스트를 실행합니다.
source <catkin_ws>/devel/setup.bash
cd <PX4-Autopilot_clone>
make px4_sitl_default sitl_gazebo
make <test_target>
test_target
is a makefile targets from the set: tests_mission, tests_mission_coverage, tests_offboard and tests_avoidance.
test/
아래에 있는 테스트 스크립트를 직접 실행할 수도 있습니다.
source <catkin_ws>/devel/setup.bash
cd <PX4-Autopilot_clone>
make px4_sitl_default sitl_gazebo
./test/<test_bash_script> <test_launch_file>
예:
./test/rostest_px4_run.sh mavros_posix_tests_offboard_posctl.test
테스트를 GUI로 실행하여 진행 상황을 쉽게 확인할 수도 있습니다(기본적으로 테스트는 "헤드리스"로 실행됨).
./test/rostest_px4_run.sh mavros_posix_tests_offboard_posctl.test gui:=true headless:=false
.test 파일은 integrationtests/python_src/px4_it/mavros/
에 정의된 해당 Python 테스트를 실행합니다.
신규 MAVROS 테스트 작성(Python)
ROS(1)/MAVROS를 사용하여 새로운 파이썬 테스트를 PX4 테스트 스위트에 추가하는 방법을 설명합니다.
기존 테스트를 예제(integrationtests/python_src/px4_it/mavros/)를 검토하십시오. 공식 ROS 문서에는 unittest(이 테스트 모음의 기반이 됨)를 사용 방법을 설명합니다.
새 테스트를 작성하려면:
아래의 빈 테스트 스켈레톤을 복사하여 새 테스트 스크립트를 작성합니다.
#!/usr/bin/env python
# [... LICENSE ...]
#
# @author Example Author <author@example.com>
#
PKG = 'px4'
import unittest
import rospy
import rosbag
from sensor_msgs.msg import NavSatFix
class MavrosNewTest(unittest.TestCase):
"""
Test description
"""
def setUp(self):
rospy.init_node('test_node', anonymous=True)
rospy.wait_for_service('mavros/cmd/arming', 30)
rospy.Subscriber("mavros/global_position/global", NavSatFix, self.global_position_callback)
self.rate = rospy.Rate(10) # 10hz
self.has_global_pos = False
def tearDown(self):
pass
#
# General callback functions used in tests
#
def global_position_callback(self, data):
self.has_global_pos = True
def test_method(self):
"""Test method description"""
# FIXME: hack to wait for simulation to be ready
while not self.has_global_pos:
self.rate.sleep()
# TODO: execute test
if __name__ == '__main__':
import rostest
rostest.rosrun(PKG, 'mavros_new_test', MavrosNewTest)
새 테스트만 실행합니다.
시뮬레이터를 시작합니다.
cd <PX4-Autopilot_clone>
source Tools/setup_gazebo.bash
roslaunch launch/mavros_posix_sitl.launch
테스트를 실행합니다(새로운 쉘에서).
cd <PX4-Autopilot_clone>
source Tools/setup_gazebo.bash
rosrun px4 mavros_new_test.py
시작 파일에 새 테스트 노드 추가
test/
에서 새 <test_name>.test
ROS 실행 파일을 만듭니다.
기본 스크립트 rostest_px4_run.sh 또는 rostest_avoidance_run.sh 중 하나를 사용하여 테스트 파일을 호출합니다.
(선택 사항) Makefile에서 새 대상 만들기
새 대상 이름을 추가하고 테스트를 호출합니다.
예:
tests_<new_test_target_name>: rostest
@"$(SRC_DIR)"/test/rostest_px4_run.sh mavros_posix_tests_<new_test>.test
위에서 설명한 대로 테스트를 실행합니다.