diff --git a/.gitignore b/.gitignore index 14027d8..f56ebec 100755 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,6 @@ config cougars-ros2 cougars-teensy cougars-gpio -cougars-docs \ No newline at end of file +cougars-docs +cougars-base-station +cougars_base_station \ No newline at end of file diff --git a/compose.sh b/compose.sh index 4f77be4..95c86a9 100755 --- a/compose.sh +++ b/compose.sh @@ -7,6 +7,8 @@ # - This can also be used to open a new bash terminal in an already running container # - Make sure you run this from the root of the top-level repo +source config/bash_vars.sh + function printInfo { echo -e "\033[0m\033[36m[INFO] $1\033[0m" } @@ -19,6 +21,8 @@ function printError { echo -e "\033[0m\033[31m[ERROR] $1\033[0m" } +printWarning "This script should be run from the root of the CoUGARS directory" + case $1 in "down") # Check the system architecture @@ -39,6 +43,10 @@ case $1 in printInfo "Loading the development image..." docker compose -f docker/docker-compose-dev.yaml up -d fi + + # Quick permission fix for GPIO access in the container + docker exec --user root cougars bash -c "bash /home/frostlab/gpio/permission_fix.sh $GPIO_CHIP" + docker exec -it cougars bash - ;; + ;; esac diff --git a/coug_launch_mission.sh b/coug_launch_mission.sh new file mode 100644 index 0000000..2d0c757 --- /dev/null +++ b/coug_launch_mission.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# Created by Brighton Anderson, NOV 2024 + +# Make sure the router is powered on before running this script + +# Check if sshpass is installed, and install it if it isn't +if ! command -v sshpass &> /dev/null; then + echo "sshpass could not be found, installing..." + sudo apt update + sudo apt install -y sshpass +fi + +# Define device variables +declare -A DEVICES=( + [1]="coug1.local" + [2]="coug2.local" + [3]="coug3.local" + [4]="coug4.local" + [5]="coug5.local" +) + +# Define username and password +declare -A CREDENTIALS=( + [1]="frostlab:frostlab" + [2]="frostlab:frostlab" + [3]="frostlab:frostlab" + [4]="frostlab:frostlab" + [5]="frostlab:frostlab" +) + +# Function to display menu +display_menu() { + echo "Select a device to SSH into:" + echo "1. Coug1" + echo "2. Coug2" + echo "3. Coug3" + echo "4. Coug4" + echo "5. Coug5" + echo "Enter your choice (1-5):" +} + +# Main script +# Display the menu +display_menu + +# Read user input +read -r choice + +# Validate input +if [[ ! "$choice" =~ ^[1-5]$ ]]; then + echo "Invalid input. Please enter a number between 1 and 5." + exit 1 +fi + +# Split credentials +IFS=':' read -r USERNAME PASSWORD <<< "${CREDENTIALS[$choice]}" + +# Get the selected device IP +DEVICE_IP="${DEVICES[$choice]}" + +# Define the command to execute +COMMAND="cd ~/CoUGARs + bash tmux.sh -i" + + +# Connect to the selected device +echo "Connecting to ${DEVICE_IP}..." +sshpass -p "$PASSWORD" ssh -t -o StrictHostKeyChecking=no "$USERNAME@$DEVICE_IP" "$COMMAND" \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index 16c9f83..c8e0c88 100755 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -197,5 +197,8 @@ USER root RUN apt update && apt upgrade -y USER ${LABNAME} +# Set up bash variable sourcing (Make sure this exists as a volume when you run the container!) +RUN echo "source /home/${LABNAME}/config/bash_vars.sh" >> ~/.bashrc + # Colorized ROS 2 logging output RUN echo "export RCUTILS_COLORIZED_OUTPUT=1" >> /home/${LABNAME}/.bashrc diff --git a/docker/docker-compose-dev.yaml b/docker/docker-compose-dev.yaml index 6926260..d118783 100755 --- a/docker/docker-compose-dev.yaml +++ b/docker/docker-compose-dev.yaml @@ -22,9 +22,11 @@ services: - ../cougars-ros2:/home/frostlab/ros2_ws - ../cougars-teensy:/home/frostlab/teensy_ws - ../cougars-gpio:/home/frostlab/gpio + - ../cougars-docs:/home/frostlab/docs + - ../cougars-base-station:/home/frostlab/base_station - /etc/localtime:/etc/localtime:ro # Syncs the container's time with the host - /tmp/.X11-unix:/tmp/.X11-unix # Required for GUI applications - command: /bin/bash + command: /bin/bash stdin_open: true # Equivalent to -it in docker run tty: true # Equivalent to -it in docker run restart: always # Optional: Keeps the container running after exit unless you want it to be removed like with --rm \ No newline at end of file diff --git a/setup.sh b/setup.sh index 522b59e..4dc8b40 100755 --- a/setup.sh +++ b/setup.sh @@ -18,9 +18,17 @@ function printError { echo -e "\033[0m\033[31m[ERROR] $1\033[0m" } +printWarning "This script should be run from the root of the CoUGARS directory" + if [ "$(uname -m)" == "aarch64" ]; then + ### START RT-SPECIFIC SETUP ### + printInfo "Setting up CoUGARs on a Raspberry Pi 5" + + # Update and upgrade the system + sudo apt update + sudo apt upgrade -y # Install Docker if not already installed if ! [ -x "$(command -v docker)" ]; then @@ -33,55 +41,103 @@ if [ "$(uname -m)" == "aarch64" ]; then fi # Install dependencies - sudo apt update - sudo apt upgrade -y sudo apt install -y vim tmux chrony git mosh - # Set up volumes - mkdir bag - mkdir config - cp -r templates/* config/ + ### END RT-SPECIFIC SETUP ### - # Set up udev rules - sudo ln -s config/local/00-teensy.rules /etc/udev/rules.d/00-teensy.rules - sudo udevadm control --reload-rules - sudo udevadm trigger +else - # Quick GPIO permission fix (one of the two should work) - sudo chmod 777 /dev/gpiochip4 - sudo chmod 777 /dev/gpiochip0 + ### START DEV-SPECIFIC SETUP ### - # Set up config files - sudo ln -s config/local/chrony.conf /etc/chrony/chrony.conf - sudo ln -s config/local/.tmux.conf ~/.tmux.conf + printInfo "Setting up CoUGARs on a development machine" - # Copy repos from GitHub - git clone https://github.com/BYU-FRoSt-Lab/cougars-ros2.git - git clone https://github.com/BYU-FRoSt-Lab/cougars-teensy.git - git clone https://github.com/BYU-FRoSt-Lab/cougars-gpio.git + # Install dependencies + sudo apt install -y vim tmux git mosh -else + ### END DEV-SPECIFIC SETUP ### - printInfo "Setting up CoUGARs on a development machine" +fi - # Install dependencies - sudo apt update - sudo apt install -y vim tmux git +# Set up bag directory +if [ -d "bag" ]; then + printWarning "The bag directory already exists" +else + mkdir bag +fi - # Set up volumes - mkdir bag - mkdir config - cp -r templates/* config/ +# Set up config directory +if [ -d "config" ]; then + printWarning "The config directory already exists -- skipping copying templates" +else + mkdir config + cp -r templates/* config/ +fi - # Set up config files +# Set up tmux config file +if [ -f ~/.tmux.conf ]; then + printWarning "The tmux config symlink already exists" +else sudo ln -s config/local/.tmux.conf ~/.tmux.conf +fi + +if [ "$(uname -m)" == "aarch64" ]; then + + ### START RT-SPECIFIC SETUP ### + + # Set up chrony config file + if [ -f /etc/chrony/chrony.conf ]; then + printWarning "The chrony config symlink already exists" + else + sudo ln -s config/local/chrony.conf /etc/chrony/chrony.conf + fi + + # Set up udev rules + if [ -f /etc/udev/rules.d/00-teensy.rules ]; then + printWarning "The udev rules symlink already exists" + else + sudo ln -s config/local/00-teensy.rules /etc/udev/rules.d/00-teensy.rules + sudo udevadm control --reload-rules + sudo udevadm trigger + fi + + ### END RT-SPECIFIC SETUP ### + +else + + ### START DEV-SPECIFIC SETUP ### + + # TODO: Maybe not needed if we do all the work in the Docker image? + # Get the CoUGARs workspace location on the development machine + current_dir=$(pwd) + source_file=$current_dir/config/bash_vars.sh + + # Attempt to add the current workspace directory to the source file + if ! grep -q "COUG_WORKSPACE_DIR" $source_file; then + echo "export COUG_WORKSPACE_DIR=$current_dir" >> $source_file + printInfo "Saved the CoUGARs workspace path to $source_file" + else + printWarning "The CoUGARs workspace path already exists in $source_file" + fi + + # Attempt to add the source file to the local user's .bashrc + if ! grep -q "source $source_file" ~/.bashrc; then + echo "source $source_file" >> ~/.bashrc + printInfo "Added automatic sourcing of bash variables to .bashrc" + else + printWarning "Automatic sourcing of bash variables is already set up in .bashrc" + fi # Copy repos from GitHub - git clone https://github.com/BYU-FRoSt-Lab/cougars-ros2.git - git clone https://github.com/BYU-FRoSt-Lab/cougars-teensy.git - git clone https://github.com/BYU-FRoSt-Lab/cougars-gpio.git git clone https://github.com/BYU-FRoSt-Lab/cougars-docs.git + git clone https://github.com/BYU-FRoSt-Lab/cougars-base-station.git + + ### END DEV-SPECIFIC SETUP ### fi -printWarning "Make sure to update the vehicle-specific configuration files in "config" now" +# Copy repos from GitHub +git clone https://github.com/BYU-FRoSt-Lab/cougars-ros2.git +git clone https://github.com/BYU-FRoSt-Lab/cougars-teensy.git +git clone https://github.com/BYU-FRoSt-Lab/cougars-gpio.git + +printInfo "Make sure to update the vehicle-specific configuration files in "config" now" diff --git a/templates/bash_vars.sh b/templates/bash_vars.sh index 8dd504c..86f9943 100755 --- a/templates/bash_vars.sh +++ b/templates/bash_vars.sh @@ -11,4 +11,8 @@ export VEHICLE_PARAMS_FILE=/home/frostlab/config/vehicle_params.yaml # ex. /home export GPIO_CHIP=/dev/gpiochip0 # ex. /dev/gpiochip0 # Run "ifconfig eth0 | grep 'inet ' | awk '{print $2}'" from OUTSIDE THE DOCKER CONTAINER and copy that number (ex. "192.168.194.59") here -export STATIC_IP=0 \ No newline at end of file +export STATIC_IP=0 + +# TODO: Maybe not needed if we do all the work in the Docker image? +# Workspace directory of CoUGARS repository on a development machine +# This should be automatically set by 'setup.sh' to the root of the CoUGARS repository if not running on a CougUV diff --git a/templates/gpio_def.py b/templates/gpio_def.py index 50a5ef7..bfd4c3c 100755 --- a/templates/gpio_def.py +++ b/templates/gpio_def.py @@ -13,4 +13,4 @@ STROBE_PIN = 15 # 15 STROBE_RATE = 1 # seconds -GPIO_CHIP = '/dev/gpiochip4' # ex. '/dev/gpiochip4' +GPIO_CHIP = '/dev/gpiochip0' # ex. '/dev/gpiochip0' diff --git a/templates/sim_params.yaml b/templates/sim_params.yaml index 5f3c072..539b652 100755 --- a/templates/sim_params.yaml +++ b/templates/sim_params.yaml @@ -6,7 +6,7 @@ /**: ros__parameters: - water_salinity_ppt: 0.0 # 0 for fresh water, 35 for salt water + water_salinity_ppt: 0.0 # 0.0 for fresh water, 35.0 for salt water magnetic_declination: 10.7 # E is positive, W is negative, 10.70° E for Utah Lake # https://www.ngdc.noaa.gov/geomag/calculators/magcalc.shtml? diff --git a/tmux.sh b/tmux.sh index 21b473a..dc16ea2 100755 --- a/tmux.sh +++ b/tmux.sh @@ -27,33 +27,65 @@ case $1 in printInfo "Starting the tmux session..." + ### FIRST WINDOW - ROS SCRIPTS ### + # Start the tmux session - tmux new-session -d -s cougars + tmux new-session -d -s cougars -n "coug" tmux split-window -h -t cougars tmux split-window -v -t cougars - tmux select-pane -t cougars:0.0 + tmux select-pane -t cougars:coug.0 tmux split-window -v -t cougars - tmux select-pane -t cougars:0.0 + tmux select-pane -t cougars:coug.0 # Send commands to the tmux session - tmux send-keys -t cougars:0.0 "bash compose.sh" ENTER - tmux send-keys -t cougars:0.0 "clear" ENTER - tmux send-keys -t cougars:0.1 "bash compose.sh" ENTER - tmux send-keys -t cougars:0.1 "clear" ENTER - tmux send-keys -t cougars:0.2 "bash compose.sh" ENTER - tmux send-keys -t cougars:0.2 "clear" ENTER - tmux send-keys -t cougars:0.3 "bash compose.sh" ENTER - tmux send-keys -t cougars:0.3 "clear" ENTER - - tmux send-keys -t cougars:0.0 "cd ~/ros2_ws" ENTER - tmux send-keys -t cougars:0.0 "ls" ENTER - tmux send-keys -t cougars:0.0 "bash launch.sh" # Don't start just yet - tmux send-keys -t cougars:0.1 "cd ~/ros2_ws" ENTER - tmux send-keys -t cougars:0.1 "bash test.sh" # Don't start just yet - tmux send-keys -t cougars:0.2 "cd ~/ros2_ws" ENTER - tmux send-keys -t cougars:0.2 "bash record.sh" # Don't start just yet - tmux send-keys -t cougars:0.3 "cd ~/config" ENTER - tmux send-keys -t cougars:0.3 "cat vehicle_params.yaml" ENTER + tmux send-keys -t cougars:coug.0 "echo 'frostlab' | sudo -S systemctl restart chrony" ENTER + + tmux send-keys -t cougars:coug.0 "bash compose.sh" ENTER + tmux send-keys -t cougars:coug.0 "clear" ENTER + tmux send-keys -t cougars:coug.1 "bash compose.sh" ENTER + tmux send-keys -t cougars:coug.1 "clear" ENTER + tmux send-keys -t cougars:coug.2 "bash compose.sh" ENTER + tmux send-keys -t cougars:coug.2 "clear" ENTER + tmux send-keys -t cougars:coug.3 "bash compose.sh" ENTER + tmux send-keys -t cougars:coug.3 "clear" ENTER + + tmux send-keys -t cougars:coug.0 "cd ~/ros2_ws" ENTER + tmux send-keys -t cougars:coug.0 "bash launch.sh " # Don't start just yet + + tmux send-keys -t cougars:coug.1 "cd ~/ros2_ws" ENTER + tmux send-keys -t cougars:coug.1 "bash test.sh " # Don't start just yet + + tmux send-keys -t cougars:coug.2 "cd ~/ros2_ws" ENTER + tmux send-keys -t cougars:coug.2 "bash record.sh " # Don't start just yet + + tmux send-keys -t cougars:coug.3 "cd ~/config" ENTER + tmux send-keys -t cougars:coug.3 "cat vehicle_params.yaml" ENTER + + ### SECOND WINDOW - MOOS SCRIPTS ### + + tmux new-window -t cougars -n "moos" # New window or split terminal again? + tmux split-window -h -t cougars:moos + tmux select-pane -t cougars:moos.0 + tmux split-window -v -t cougars:moos.0 + + tmux send-keys -t cougars:moos.0 "bash compose.sh" ENTER + tmux send-keys -t cougars:moos.0 "clear" ENTER + tmux send-keys -t cougars:moos.1 "bash compose.sh" ENTER + tmux send-keys -t cougars:moos.1 "clear" ENTER + tmux send-keys -t cougars:moos.2 "bash compose.sh" ENTER + tmux send-keys -t cougars:moos.2 "clear" ENTER + + tmux send-keys -t cougars:moos.0 "date" ENTER + + tmux send-keys -t cougars:moos.1 "cat ~/ros2_ws/moos_tools/coug.bhv" ENTER + tmux send-keys -t cougars:moos.1 "bash ~/ros2_ws/moos_tools/mission_deploy.sh" # Don't start just yet + + + tmux send-keys -t cougars:moos.2 "cd ~/ros2_ws/moos_tools" ENTER + tmux send-keys -t cougars:moos.2 "timeout 120s pAntler coug.moos" # Don't start just yet + + # TODO: Add more terminals, etc + # I bet Matthew has some good ideas else printInfo "Attaching to the tmux session..." @@ -63,3 +95,11 @@ case $1 in tmux attach-session -t cougars ;; esac + +# I added some comments -Nelson + +#TODO: - figure out how to edit vehicle_params and moos.bhv for the mission (I think just cat the file so we can see it in the terminal, and we can change it using vim if needed) +# - add in the mission_deploy.sh the pAntler timeout command ('timeout 5 ' should work -- number is in seconds) +# - check with Braden, and Nelson to see if everything else is good to go +# - how to implement plot juggler +# - see if any other commands need to be added to the tmux script from new map waypoint stuff \ No newline at end of file diff --git a/update.sh b/update.sh index 84f85b1..e094527 100755 --- a/update.sh +++ b/update.sh @@ -4,6 +4,20 @@ # Simply pulls all avaliable updates # - Make sure you run this from the root of the top-level repo +function printInfo { + echo -e "\033[0m\033[36m[INFO] $1\033[0m" +} + +function printWarning { + echo -e "\033[0m\033[33m[WARNING] $1\033[0m" +} + +function printError { + echo -e "\033[0m\033[31m[ERROR] $1\033[0m" +} + +printWarning "This script should be run from the root of the CoUGARS directory" + # Docker updates docker pull frostlab/cougars:latest @@ -19,5 +33,12 @@ git pull cd ../cougars-gpio git pull -cd ../cougars-docs -git pull +if [ ! "$(uname -m)" == "aarch64" ]; then + + cd ../cougars-docs + git pull + + cd ../cougars-base-station + git pull + +fi