From e5961a913a789aeafe7d59f1736592aa61fd0569 Mon Sep 17 00:00:00 2001 From: AhmedElsafy Date: Tue, 6 Apr 2021 15:21:30 -0300 Subject: [PATCH] initial commit --- README.md | 28 ++++++++++++++++++++++++++++ env.sh | 4 ++++ sbin/apriltaglaunch | 7 +++++++ sbin/camlaunch | 7 +++++++ sbin/ros_radio_listener | 7 +++++++ sbin/roslaunch | 7 +++++++ service/apriltag.service | 10 ++++++++++ service/camlaunch.service | 10 ++++++++++ service/ros_radio_listener.service | 10 ++++++++++ service/roscore.service | 15 +++++++++++++++ service/roslaunch.service | 10 ++++++++++ 11 files changed, 115 insertions(+) create mode 100644 README.md create mode 100755 env.sh create mode 100755 sbin/apriltaglaunch create mode 100755 sbin/camlaunch create mode 100755 sbin/ros_radio_listener create mode 100755 sbin/roslaunch create mode 100644 service/apriltag.service create mode 100644 service/camlaunch.service create mode 100644 service/ros_radio_listener.service create mode 100644 service/roscore.service create mode 100644 service/roslaunch.service 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