Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Improved scripts #116

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 65 additions & 20 deletions launch_interface.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,71 @@
#!/bin/bash
set -o pipefail

# Usage: ./launch_interface.sh -m $HELLO_FLEET_PATH/maps/<map_name>.yaml
MAP_ARG=""
if getopts ":m:" opt && [[ $opt == "m" && -f $OPTARG ]]; then
echo "Setting map..."
MAP_ARG="map_yaml:=$OPTARG"
while getopts m:t:f opt; do
case $opt in
m)
# Usage: ./launch_interface.sh -m $HELLO_FLEET_PATH/maps/<map_name>.yaml
if [[ -f $OPTARG ]]; then
MAP="-m $OPTARG"
fi
;;
t)
# Usage: ./launch_interface.sh -t pyttsx3
TTS="-t $OPTARG"
;;
f)
# Usage: ./launch_interface.sh -f
FIREBASE="-f"
esac
done

timestamp='stretch_web_teleop_'`date '+%Y%m%d%H%M'`;
logdir="$HOME/stretch_user/log/web_teleop/$timestamp"
logfile_ros="$logdir/start_ros2.txt"
logfile_node="$logdir/start_web_server_and_robot_browser.txt"
logzip="$logdir/stretch_web_teleop_logs.zip"
mkdir -p $logdir

function echo_failure_help {
zip -r $logzip $logdir/ > /dev/null
echo ""
echo "#############################################"
echo "FAILURE. COULD NOT LAUNCH WEB TELEOP."
echo "Look at the troubleshooting guide for solutions to common issues: https://docs.hello-robot.com/0.3/getting_started/demos_web_teleop/#troubleshooting"
echo "or contact Hello Robot support and include $logzip"
echo "#############################################"
echo ""
exit 1
}

echo "#############################################"
echo "LAUNCHING WEB TELEOP"
echo "#############################################"

cd $HOME/ament_ws/src/stretch_web_teleop
./start_ros2.sh -l $logdir $MAP $TTS |& tee $logfile_ros
if [ $? -ne 0 ]; then
echo_failure_help
fi

# Usage: ./launch_interface.sh -t pyttsx3
TTS_ARG=""
if getopts ":t:" opt && [[ $opt == "t" ]]; then
echo "Setting tts engine..."
TTS_ARG="tts_engine:=$OPTARG"
# echo ""
cd $HOME/ament_ws/src/stretch_web_teleop
./start_web_server_and_robot_browser.sh -l $logdir $FIREBASE |& tee $logfile_node
if [ $? -ne 0 ]; then
echo_failure_help
fi

stretch_free_robot_process.py;
./stop_interface.sh
sudo udevadm control --reload-rules && sudo udevadm trigger
source /opt/ros/humble/setup.bash
source ~/ament_ws/install/setup.bash
source /usr/share/colcon_cd/function/colcon_cd.sh
sleep 2;
screen -dm -S "web_teleop_ros" ros2 launch stretch_web_teleop web_interface.launch.py $MAP_ARG $TTS_ARG
sleep 3;
~/ament_ws/src/stretch_web_teleop/start_web_server_and_robot_browser.sh
zip -r $logzip $logdir/ > /dev/null

echo ""
echo "#############################################"
echo "DONE! WEB TELEOP IS UP!"
echo "Visit the URL(s) below to see the web interface:"
if [ "$FIREBASE" = "-f" ]; then
echo "https://web.hello-robot.com/"
else
echo "https://localhost/operator"
ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/https:\/\/\2\/operator/p'
fi
echo "#############################################"
echo ""
60 changes: 60 additions & 0 deletions start_ros2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
set -e

REDIRECT_LOGDIR="$HOME/stretch_user/log/web_teleop"
mkdir -p $REDIRECT_LOGDIR
while getopts l:m:t: opt; do
case $opt in
l)
# Usage: ./start_ros2.sh -l /tmp/some_folder
if [[ -d $OPTARG ]]; then
REDIRECT_LOGDIR=$OPTARG
fi
;;
m)
# Usage: ./start_ros2.sh -m $HELLO_FLEET_PATH/maps/<map_name>.yaml
if [[ -f $OPTARG ]]; then
echo "Setting map..."
MAP_ARG="map_yaml:=$OPTARG"
fi
;;
t)
# Usage: ./start_ros2.sh -t pyttsx3
echo "Setting tts engine..."
TTS_ARG="tts_engine:=$OPTARG"
;;
esac
done
REDIRECT_LOGFILE="$REDIRECT_LOGDIR/start_ros2.`date '+%Y%m%d%H%M'`_redirected.txt"
echo "Arguments:" &>> $REDIRECT_LOGFILE
echo "-l $REDIRECT_LOGDIR" &>> $REDIRECT_LOGFILE
echo "-m $MAP_ARG" &>> $REDIRECT_LOGFILE
echo "-t $TTS_ARG" &>> $REDIRECT_LOGFILE

if [[ -z `nmcli -t -f DEVICE c show --active | grep wlo1` ]]; then
echo "Not connected to Wifi. Starting Wifi-Connect..."
echo "Please connect to $HOSTNAME wifi and provide your home network's credentials"
sudo wifi-connect -s $HOSTNAME &>> $REDIRECT_LOGFILE
fi

echo "Setup environment..."
. /etc/hello-robot/hello-robot.conf
export HELLO_FLEET_ID HELLO_FLEET_ID
export HELLO_FLEET_PATH=$HOME/stretch_user
source /opt/ros/humble/setup.bash &>> $REDIRECT_LOGFILE
source ~/ament_ws/install/setup.bash &>> $REDIRECT_LOGFILE
source /usr/share/colcon_cd/function/colcon_cd.sh &>> $REDIRECT_LOGFILE

echo "Freeing robot process..."
/usr/bin/python3 $HOME/.local/bin/stretch_free_robot_process.py &>> $REDIRECT_LOGFILE

echo "Stopping previous instances..."
./stop_interface.sh &>> $REDIRECT_LOGFILE

echo "Reload USB bus..."
sudo udevadm control --reload-rules && sudo udevadm trigger &>> $REDIRECT_LOGFILE

echo "Start ROS2..."
sleep 2;
screen -dm -S "web_teleop_ros" ros2 launch stretch_web_teleop web_interface.launch.py $MAP_ARG $TTS_ARG &>> $REDIRECT_LOGFILE
sleep 3;
40 changes: 32 additions & 8 deletions start_web_server_and_robot_browser.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
#!/bin/bash
set -e

REDIRECT_LOGDIR="$HOME/stretch_user/log/web_teleop"
mkdir -p $REDIRECT_LOGDIR
STORAGE="localstorage"
while getopts l:f opt; do
case $opt in
l)
# Usage: ./start_web_server_and_robot_browser.sh -l /tmp/some_folder
if [[ -d $OPTARG ]]; then
REDIRECT_LOGDIR=$OPTARG
fi
;;
f)
# Usage: ./start_web_server_and_robot_browser.sh -f
echo "Using firebase..."
STORAGE="firebase"
esac
done
REDIRECT_LOGFILE="$REDIRECT_LOGDIR/start_web_server_and_robot_browser.`date '+%Y%m%d%H%M'`_redirected.txt"
echo "Arguments:" &>> $REDIRECT_LOGFILE
echo "-l $REDIRECT_LOGDIR" &>> $REDIRECT_LOGFILE
echo "-f $STORAGE" &>> $REDIRECT_LOGFILE

echo "Run webpack..."
export NODE_EXTRA_CA_CERTS="/home/hello-robot/ament_ws/src/stretch_web_teleop/certificates/rootCA.pem"
cd ~/ament_ws/src/stretch_web_teleop && pm2 start -s npm --name="stretch_web_teleop" -- run localstorage
cd ~/ament_ws/src/stretch_web_teleop && pm2 start -s server.js --watch
cd ~/ament_ws/src/stretch_web_teleop && pm2 start -s start_robot_browser.js --watch
set +x
echo ""
echo "Visit the URL(s) below to see the web interface:"
echo "https://localhost/operator"
ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/https:\/\/\2\/operator/p'
cd ~/ament_ws/src/stretch_web_teleop && pm2 start -s npm --name="stretch_web_teleop" -- run $STORAGE &>> $REDIRECT_LOGFILE

echo "Start local server..."
cd ~/ament_ws/src/stretch_web_teleop && pm2 start -s server.js --watch &>> $REDIRECT_LOGFILE

echo "Start robot browser..."
cd ~/ament_ws/src/stretch_web_teleop && pm2 start -s start_robot_browser.js --watch &>> $REDIRECT_LOGFILE
ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/https:\/\/\2\/operator/p' &>> $REDIRECT_LOGFILE
3 changes: 2 additions & 1 deletion stop_interface.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
# but this would not arise if this script properly terminates
# realsense nodes.
screen -S "web_teleop_ros" -X stuff '^C'
t1=$?
sleep 3;
if [[ $? -ne 0 ]]; then
if [[ $t1 -ne 0 ]]; then
echo "Using pkill"
sudo pkill screen
fi
Expand Down