From 2822f4c5db7bf541bcd1d92b2fb6821eae75eab9 Mon Sep 17 00:00:00 2001 From: Arthur Golubtsov Date: Wed, 20 Mar 2019 23:55:30 +0000 Subject: [PATCH 1/2] Drone: modify client_config script --- Drone/client_setup.sh | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) mode change 100644 => 100755 Drone/client_setup.sh diff --git a/Drone/client_setup.sh b/Drone/client_setup.sh old mode 100644 new mode 100755 index 0a279a4..7af4b75 --- a/Drone/client_setup.sh +++ b/Drone/client_setup.sh @@ -1,12 +1,13 @@ #!/bin/bash # $1 - ssid, $2 - password of wifi router -# $3 - hostname of rpi +# $3 - hostname of rpi +# $4 - server ip # check if enough arguments -if [[ $# -ne 3 ]] ; then - echo -e "\nPlease, enter arguments: ssid, password of wifi and hostname." - echo -e "\nExample: sudo $0 clever-swarm swarmwifi clever-1\n" +if [[ $# -ne 4 ]] ; then + echo -e "\nPlease, enter arguments: ssid, wifi password, copter id and server ip" + echo -e "\nExample: sudo ./$0 clever-swarm swarmwifi clever-1 192.168.1.100\n" exit 0 fi @@ -19,7 +20,9 @@ sed -i 's/interface wlan0//' /etc/dhcpcd.conf sed -i 's/static ip_address=192.168.11.1\/24//' /etc/dhcpcd.conf # make backup of wpa_supplicant.conf -cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.OLD +if ! [ -f "/etc/wpa_supplicant/wpa_supplicant.conf.OLD" ] ; then + cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.OLD +fi # ssid and password of the router cat << EOF | tee /etc/wpa_supplicant/wpa_supplicant.conf @@ -43,7 +46,18 @@ sed -i "/127.0.1.1/c 127.0.1.1 $3" /etc/hosts sed -i "/ROS_HOSTNAME/c ROS_HOSTNAME=\'$3\'" /home/pi/.bashrc sed -i "/ROS_HOSTNAME/c ROS_HOSTNAME=$3" /lib/systemd/system/roscore.env -# set sudoers variables to make sudo works with ros: TODO +# set sudoers variables to make sudo works with ros: +grep -qxF 'Defaults env_keep += "ROS_LOG_DIR"' /etc/sudoers || cat << EOT >> /etc/sudoers + +Defaults env_keep += "PYTHONPATH" +Defaults env_keep += "PATH" +Defaults env_keep += "ROS_ROOT" +Defaults env_keep += "ROS_MASTER_URI" +Defaults env_keep += "ROS_PACKAGE_PATH" +Defaults env_keep += "ROS_LOCATIONS" +Defaults env_keep += "ROS_HOME" +Defaults env_keep += "ROS_LOG_DIR" +EOT # copy aruco.launch and clever.launch: TODO??? @@ -54,5 +68,19 @@ apt-get -y install winbind # set /etc/nsswitch.conf sed -i '/hosts:/c hosts: files dns wins' /etc/nsswitch.conf +# install chrony +apt-get -y install chrony + +# configure chrony as client +cat << EOF | tee /etc/chrony/chrony.conf +server $4 iburst +driftfile /var/lib/chrony/drift +makestep 1.0 3 +rtcsync +EOF + +# change server ip in client_config +sed -i "0,/^host/s/\(^h.*\)/host = $4/" client_config.ini + # restart clever reboot \ No newline at end of file From 7a3fb423777cc5386676ecb6294044836e3ffeab Mon Sep 17 00:00:00 2001 From: Arthur Date: Thu, 21 Mar 2019 14:48:33 +0000 Subject: [PATCH 2/2] Drone: modify client_config.sh --- Drone/client_setup.sh | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/Drone/client_setup.sh b/Drone/client_setup.sh index 7af4b75..88d1908 100755 --- a/Drone/client_setup.sh +++ b/Drone/client_setup.sh @@ -6,16 +6,17 @@ # check if enough arguments if [[ $# -ne 4 ]] ; then - echo -e "\nPlease, enter arguments: ssid, wifi password, copter id and server ip" - echo -e "\nExample: sudo ./$0 clever-swarm swarmwifi clever-1 192.168.1.100\n" + echo -e "\nPlease, enter arguments: router ssid, wifi password, copter id and server ip" + echo -e "\nExample: sudo $0 clever-swarm swarmwifi clever-1 192.168.1.100" + echo -e "\nWarning: this script requires wifi router to be connected to internet!\n" exit 0 fi -# stop and disable dnsmasq service +# stop and disable dnsmasq service (to set wifi in client mode) systemctl stop dnsmasq systemctl disable dnsmasq -# enable get auto ip +# enable getting auto ip sed -i 's/interface wlan0//' /etc/dhcpcd.conf sed -i 's/static ip_address=192.168.11.1\/24//' /etc/dhcpcd.conf @@ -24,7 +25,7 @@ if ! [ -f "/etc/wpa_supplicant/wpa_supplicant.conf.OLD" ] ; then cp /etc/wpa_supplicant/wpa_supplicant.conf /etc/wpa_supplicant/wpa_supplicant.conf.OLD fi -# ssid and password of the router +# set ssid and password of the router cat << EOF | tee /etc/wpa_supplicant/wpa_supplicant.conf ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev update_config=1 @@ -36,6 +37,9 @@ network={ } EOF +# restart dhcpcd to connect to wifi as a client +systemctl restart dhcpcd + # set hostname for linux cat << EOF | tee /etc/hostname $3 @@ -46,7 +50,7 @@ sed -i "/127.0.1.1/c 127.0.1.1 $3" /etc/hosts sed -i "/ROS_HOSTNAME/c ROS_HOSTNAME=\'$3\'" /home/pi/.bashrc sed -i "/ROS_HOSTNAME/c ROS_HOSTNAME=$3" /lib/systemd/system/roscore.env -# set sudoers variables to make sudo works with ros: +# add sudoers variables to make sudo works with ros (for led strip) grep -qxF 'Defaults env_keep += "ROS_LOG_DIR"' /etc/sudoers || cat << EOT >> /etc/sudoers Defaults env_keep += "PYTHONPATH" @@ -59,16 +63,25 @@ Defaults env_keep += "ROS_HOME" Defaults env_keep += "ROS_LOG_DIR" EOT -# copy aruco.launch and clever.launch: TODO??? +# configure aruco.launch and clever.launch (for positioning with aruco map) +sed -i '/' /home/pi/catkin_ws/src/clever/clever/launch/aruco.launch +sed -i '/' /home/pi/catkin_ws/src/clever/clever/launch/aruco.launch +sed -i '/' /home/pi/catkin_ws/src/clever/clever/launch/aruco.launch +sed -i '/' /home/pi/catkin_ws/src/clever/clever/launch/clever.launch -# install samba and winbind +# copy office map to animation map if there is no animation map file +if ! [ -f "/home/pi/catkin_ws/src/clever/aruco_pose/map/animation_map.txt" ] ; then + sudo -u pi cp /home/pi/catkin_ws/src/clever/aruco_pose/map/office.txt /home/pi/catkin_ws/src/clever/aruco_pose/map/animation_map.txt +fi + +# install samba and winbind (for hostname resolving) apt-get -y install samba apt-get -y install winbind # set /etc/nsswitch.conf sed -i '/hosts:/c hosts: files dns wins' /etc/nsswitch.conf -# install chrony +# install chrony (for time syncing) apt-get -y install chrony # configure chrony as client @@ -82,5 +95,9 @@ EOF # change server ip in client_config sed -i "0,/^host/s/\(^h.*\)/host = $4/" client_config.ini +# set roscore service to restart on-failure +sed -i '/Restart=/c Restart=on-failure\ +RestartSec=3' /lib/systemd/system/roscore.service + # restart clever reboot \ No newline at end of file