Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
snelsondurrant committed Nov 22, 2024
2 parents 52ff05e + edd74f4 commit 1c8f02c
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 63 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ config
cougars-ros2
cougars-teensy
cougars-gpio
cougars-docs
cougars-docs
cougars-base-station
cougars_base_station
10 changes: 9 additions & 1 deletion compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand All @@ -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
Expand All @@ -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
68 changes: 68 additions & 0 deletions coug_launch_mission.sh
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion docker/docker-compose-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
124 changes: 90 additions & 34 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
6 changes: 5 additions & 1 deletion templates/bash_vars.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
2 changes: 1 addition & 1 deletion templates/gpio_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
2 changes: 1 addition & 1 deletion templates/sim_params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down
Loading

0 comments on commit 1c8f02c

Please sign in to comment.