commit e5961a913a789aeafe7d59f1736592aa61fd0569 Author: AhmedElsafy Date: Tue Apr 6 15:21:30 2021 -0300 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..0b8cacb --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# Systemd Services + +Services to run on startup + + - Radio Listener to tune the cameras, restart TX2 or FCU with a flip of switch on the RC + - ROSCORE start + - MAVROS start + - Camera start + - GPU stereo vision start + - RTSP broadcaster start + +# Install + +Copy all files inside directory sbin to `/usr/sbin/` then run `sudo chmod +x` for each file after coping + +Copy all files inside directory services to /etc/systemd/system/ + +Copy `env.sh` to `/etc/ros/`then run `sudo chmod +x env.sh` + +Enable all services + + sudo systemctl enable --now roslaunch + sudo systemctl enable --now ros_radio_listener + sudo systemctl enable --now roscore + sudo systemctl enable --now apriltag + sudo systemctl enable --now camlaunch + + diff --git a/env.sh b/env.sh new file mode 100755 index 0000000..11db090 --- /dev/null +++ b/env.sh @@ -0,0 +1,4 @@ +#!/bin/sh +export ROS_HOSTNAME=$(hostname).local +export ROS_MASTER_URI=http://$ROS_HOSTNAME:11311 +export SERVER_IP=192.168.195.50 diff --git a/sbin/apriltaglaunch b/sbin/apriltaglaunch new file mode 100755 index 0000000..980c0a5 --- /dev/null +++ b/sbin/apriltaglaunch @@ -0,0 +1,7 @@ +#!/bin/bash +source ~/catkin-ws/devel/setup.bash +source /etc/ros/env.sh +export ROS_HOME=$(echo ~spiri/.ros) +roslaunch apriltag_ros continuous_detection_nodelet.launch __ns:=stereo & +PID=$! +wait "$PID" diff --git a/sbin/camlaunch b/sbin/camlaunch new file mode 100755 index 0000000..e8cbc8d --- /dev/null +++ b/sbin/camlaunch @@ -0,0 +1,7 @@ +#!/bin/bash +source ~/catkin-ws/devel/setup.bash +source /etc/ros/env.sh +export ROS_HOME=$(echo ~spiri/.ros) +roslaunch jetson_csi_cam video-daylight-nodelet-800x600.launch +PID=$! +wait "$PID" diff --git a/sbin/ros_radio_listener b/sbin/ros_radio_listener new file mode 100755 index 0000000..1bf9b0f --- /dev/null +++ b/sbin/ros_radio_listener @@ -0,0 +1,7 @@ +#!/bin/bash +source ~/catkin-ws/devel/setup.bash +source /etc/ros/env.sh +export ROS_HOME=$(echo ~spiri/.ros) +roslaunch mavros_fly radio_listener.launch & +PID=$! +wait "$PID" diff --git a/sbin/roslaunch b/sbin/roslaunch new file mode 100755 index 0000000..1c59442 --- /dev/null +++ b/sbin/roslaunch @@ -0,0 +1,7 @@ +#!/bin/bash +source ~/catkin-ws/devel/setup.bash +source /etc/ros/env.sh +export ROS_HOME=$(echo ~spiri/.ros) +roslaunch mavros px4_spiri_avoid.launch & +PID=$! +wait "$PID" diff --git a/service/apriltag.service b/service/apriltag.service new file mode 100644 index 0000000..9f74eb9 --- /dev/null +++ b/service/apriltag.service @@ -0,0 +1,10 @@ +[Unit] +Requires=camlaunch.service +PartOf=camlaunch.service +After=NetworkManager.service time-sync.target roscore.service camlaunch.service +[Service] +Type=simple +User=spiri +ExecStart=/usr/sbin/apriltaglaunch +[Install] +WantedBy=multi-user.target diff --git a/service/camlaunch.service b/service/camlaunch.service new file mode 100644 index 0000000..a7e0797 --- /dev/null +++ b/service/camlaunch.service @@ -0,0 +1,10 @@ +[Unit] +Requires=roscore.service +PartOf=roscore.service +After=NetworkManager.service time-sync.target roscore.service +[Service] +Type=simple +User=spiri +ExecStart=/usr/sbin/camlaunch +[Install] +WantedBy=multi-user.target diff --git a/service/ros_radio_listener.service b/service/ros_radio_listener.service new file mode 100644 index 0000000..f4ecbdf --- /dev/null +++ b/service/ros_radio_listener.service @@ -0,0 +1,10 @@ +[Unit] +Requires=roscore.service +PartOf=roscore.service +After=NetworkManager.service time-sync.target roscore.service roslaunch.service +[Service] +Type=simple +User=spiri +ExecStart=/usr/sbin/ros_radio_listener +[Install] +WantedBy=multi-user.target diff --git a/service/roscore.service b/service/roscore.service new file mode 100644 index 0000000..be83d5d --- /dev/null +++ b/service/roscore.service @@ -0,0 +1,15 @@ +[Unit] +After=NetworkManager.service time-sync.target +[Service] +Type=forking +User=spiri +# Start roscore as a fork and then wait for the tcp port to be opened +# —————————————————————- +# Source all the environment variables, start roscore in a fork +# Since the service type is forking, systemd doesn’t mark it as +# ‘started’ until the original process exits, so we have the +# non-forked shell wait until it can connect to the tcp opened by +# roscore, and then exit, preventing conflicts with dependant services +ExecStart=/bin/sh -c ". /opt/ros/melodic/setup.sh; . /etc/ros/env.sh; roscore & while ! echo exit | nc localhost 11311 > /dev/null; do sleep 1; done" +[Install] +WantedBy=multi-user.target diff --git a/service/roslaunch.service b/service/roslaunch.service new file mode 100644 index 0000000..9e19377 --- /dev/null +++ b/service/roslaunch.service @@ -0,0 +1,10 @@ +[Unit] +Requires=roscore.service +PartOf=roscore.service +After=NetworkManager.service time-sync.target roscore.service +[Service] +Type=simple +User=spiri +ExecStart=/usr/sbin/roslaunch +[Install] +WantedBy=multi-user.target