ROS_BackGround - 8BitsCoding/RobotMentor GitHub Wiki

ROS Linux 백그라운드에서 돌리기

가장 좋은 방법 -> .desktop파일 수정

  1. 시작 프로그램 -> *.desktop파일 생성
$ cd ~/.config/autostart
$ gedit *.desktop

잊지 말 것

  • PATH=/home/user/...

경로(PATH) 넣기

  • .desktop에 'Terminal=true' 넣기

  • 딜레이 넣기 (2가지 방법이 존재)

  1. X-GNOME-Autostart-Delay=10
  2. .sh를 수정 -> sleep=10
  • ROS_MASTER_IP export시키기 (.sh를 쓴다면)
#!/bin/bash
sleep 10
source /opt/ros/indigo/setup.bash
source /home/hanwha/catkin_ws/devel/setup.bash
export ROS_MASTER_URI=http://192.168.10.100:11311
export ROS_HOSTNAME=192.168.10.100
roslaunch USVCORE USVCORE.launch

$ sudo gedit /etc/rc.local
# 아래를 넣자
$ su <user> -s /bin/bash -c "source /opt/ros/indigo/setup.sh; source /home/<user>/catkin_ws/devel/setup.sh; rosluanch <Package> <launchfile>.launch"

단, GUI가 있는 Qt plugin로 생성된 노드의 경우 위와 같은 방법으로 실행이 되지않는다.

아래의 두 가지 과정이 필요!

(추가:190624) 위와 같이 해도 안되는 경우가 발생... 아마 service로 만들어서 발행해야할 듯.

  1. 코드수정
// qnode.cpp
bool QNode::init() {
    std::string master_url = "http://localhost:11311/"; // ROS CORE IP
    std::string host_url = "localhost";                 // Node IP
    std::map<std::string, std::string> remappings;
    remappings["__master"] = master_url;
    remappings["__hostname"] = host_url;
    ros::init(remappings, "<Packagename>");
}

다음과 같은 방법으로 rosinit해야 한다.

  1. 시작 프로그램 -> *.desktop파일 생성
$ cd ~/.config/autostart
$ gedit *.desktop

보통 아래와 같이 선언되어있고 실행파일의 PATH만 넣어주면 됨.

[Desktop Entry]
Type=Application
Exec=/home/usvcon/catkin_ws/devel/lib/turtlebot3_bringup/turtlebot3_diagnostics
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[ko]=new
Name=new
Comment[ko]=test
Comment=test
X-GNOME-Autostart-Delay=60
  • PATH=/home/usvcon/catkin_ws/devel/lib/turtlebot3_bringup/ 추가 하면 끝

딜레이를 넣고 싶다면?

X-GNOME-Autostart-Delay=60


service를 만들어서 백그라운드에서 돌리기

$ sudo apt-get install systemd
$ mkdir ~/scripts
$ cd ~/scripts
$ gedit startup_launch.sh

startup_launch.sh 내부

#!/bin/bash
source /opt/ros/kinetic/setup.bash
source /home/<user>/catkin_ws/devel/setup.bash
roslaunch <pkg> <file>.launch
$ sudo chmod 777 startup_launch.sh
$ cd /lib/systemd/system
$ sudo gedit <pkg>.service
[Unit]
Description=<pkg>

[Service]
Type=forking
ExecStart=/home/<user>/scripts/startup_launch.sh
Restart=on-failure

[Install]
WantedBy=multi-user.target

시험해보기

$ sudo systemctl daemon-reload

시작 시 자동동작

$ sudo systemctl enable <pkg>.service

diable

$ sudo systemctl disable <pkg>.service
⚠️ **GitHub.com Fallback** ⚠️