#!/usr/bin/env bash

set -eou pipefail

# Find workspace
workspace=$(bazel info workspace)
# Set up environment
source "$workspace/scripts/shell/bazel/function.sh"
# Change directory to the root of the workspace
cd ${workspace}
if [ "$#" -lt 1 ] ; then
  echo "No robot name in arg 1, exiting..."
  exit 1
fi
# Run teleop processes
ZOOX_ROBOT_NAME=${1} bazel_run teleop/launch:develop_launch teleop_supervisor_extra_args:="--vehicle_discovery_initial_peers=10.2.17.30" &
# Wait for roscore to initialize
until [[ "$(bazel_run //bin:rostopic list 2>/dev/null)" ]]
do
  sleep 0.1
done
# Run our teleop-chum play wrapper
./teleop/launch/teleop_play.sh --run_id 20171206T001352-kitt_03 --start_timestamp=1512519950 --end_timestamp=1512519987 --loop
