-
[드론] PX4 + ros noetic offboard control troubleshooting개발 로그/바코드 드론 2023. 11. 23. 21:02
https://docs.px4.io/main/ko/ros/mavros_offboard_python.html
MAVROS Offboard control example (Python) | PX4 오토파일럿 사용자 설명서 (main)
MAVROS Offboard control example (Python) This tutorial shows the basics of OFFBOARD control with MAVROS Python, using an Iris quadcopter simulated in Gazebo Classic. It provides step-by-step instructions demonstrating how to start developing programs to co
docs.px4.io
이 링크 따라서 하다보면, "왜안되지" 싶은 상황에 직면하게 된다.
Resource not found: px4 ROS path [0]=/opt/ros/noetic/share/ros ROS path [1]=/root/catkin_ws/src/mavlink ROS path [2]=/root/catkin_ws/src/mavros/libmavconn ROS path [3]=/root/catkin_ws/src/mavros/mavros_msgs ROS path [4]=/root/catkin_ws/src/mavros/mavros ROS path [5]=/root/catkin_ws/src/mavros/mavros_extras ROS path [6]=/root/catkin_ws/src/offboard_py ROS path [7]=/root/catkin_ws/src/mavros/test_mavros ROS path [8]=/opt/ros/noetic/share The traceback for the exception was written to the log file
이런 오류가 뿜어져 나오는데, 이 경우 위 링크에서는 bashrc에 이걸 추가하라고 설명하고 있다.
source ~/PX4-Autopilot/Tools/simulation/gazebo/setup_gazebo.bash ~/PX4-Autopilot ~/PX4-Autopilot/build/px4_sitl_default export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:~/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic export GAZEBO_PLUGIN_PATH=$GAZEBO_PLUGIN_PATH:/usr/lib/x86_64-linux-gnu/gazebo-9/plugins
사실 이것도 문제가 있고, 그 전에 해야하는것들도 있다.
1. px4 빌드
source ~/PX4-Autopilot/Tools/simulation/gazebo/setup_gazebo.bash ~/PX4-Autopilot ~/PX4-Autopilot/build/px4_sitl_default
이 줄 맨 마지막에 ~/PX4-Autopilot/build/px4_sitl_default 이 디렉토리를 찾는다.
즉 /PX4-Autopilot이 빌드가 되어있어야 하는 것이다. 따라서 /PX4-Autopilot 디렉토리에 가서,
# 제 경우, root 디렉토리에 PX4-Autopilot을 clone해둬서, cd ~/PX4-Autopilot make px4_sitl gazebo-classic
이 명령을 해줘야 한다.
2. offb_node.py 수정
""" * File: offb_node.py * Stack and tested in Gazebo Classic 9 SITL """ #! /usr/bin/env python import rospy from geometry_msgs.msg import PoseStamped from mavros_msgs.msg import State from mavros_msgs.srv import CommandBool, CommandBoolRequest, SetMode, SetModeRequest current_state = State() def state_cb(msg): global current_state current_state = msg if __name__ == "__main__": rospy.init_node("offb_node_py") state_sub = rospy.Subscriber("mavros/state", State, callback = state_cb) ... (생략)
해당 코드의 윗부분을 지우고, python3을 사용하니 python3으로 바꿔야한다.
#! /usr/bin/env python3 import rospy from geometry_msgs.msg import PoseStamped from mavros_msgs.msg import State from mavros_msgs.srv import CommandBool, CommandBoolRequest, SetMode, SetModeRequest current_state = State() def state_cb(msg): global current_state current_state = msg if __name__ == "__main__": rospy.init_node("offb_node_py") state_sub = rospy.Subscriber("mavros/state", State, callback = state_cb) ... (생략)
3. ~/.bashrc 수정
source /opt/ros/noetic/setup.bash source ~/catkin_ws/devel/setup.bash source ~/PX4-Autopilot/Tools/simulation/gazebo-classic/setup_gazebo.bash ~/PX4-Autopilot ~/PX4-Autopilot/build/px4_sitl_default export ROS_PACKAGE_PATH=~/PX4-Autopilot:$ROS_PACKAGE_PATH export ROS_PACKAGE_PATH=~/PX4-Autopilot/Tools/simulation/gazebo-classic/sitl_gazebo-classic:$ROS_PACKAGE_PATH export GAZEBO_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/gazebo-11/plugins:$GAZEBO_PLUGIN_PATH
내 환경에 맞게 경로 몇가지 수정했다. 이걸 ~/.bashrc 마지막 부분에 추가하면 된다.
source ~/catkin_ws/devel/setup.bash
시행착오를 겪어보니, 이걸 저 사이에서 수행한다는게 중요한 것 같다.
'개발 로그 > 바코드 드론' 카테고리의 다른 글
[드론] unilidar + pointlio 세팅완료 (0) 2023.11.04 [드론] pcl 종속성 문제 해결 (0) 2023.10.27 [드론] Unitree Lidar ROS2 세팅 정리 (0) 2023.10.27