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

Support for automated matlab install #326

Open
wants to merge 3 commits into
base: humble
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions setup_scripts/dev_install/install_dev.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ echo "Starting ROSDEP"
sudo rosdep init
rosdep update

# TODO query for new sim setup here

echo "Importing repositories"
vcs import < ~/osu-uwrt/riptide_setup/setup_scripts/dev_install/riptide.repos . --recursive
vcs pull
Expand Down Expand Up @@ -49,14 +47,16 @@ echo "Downloading Pico utils"
sudo apt install -y cmake gcc-arm-none-eabi libnewlib-arm-none-eabi build-essential

# build development software (this should pass)
echo "Building riptide software"
echo "Building riptide_software"
cd ~/osu-uwrt/development/software
rosdep install --from-paths src --ignore-src --rosdistro $ROS_DISTRO -y -r
sudo apt install -y libglfw3-dev #for the sim
pip install transforms3d #for mapping
source /opt/ros/$ROS_DISTRO/setup.bash
source ~/osu-uwrt/development/dependencies/install/setup.bash
colcon build

if [ $? -ne 0 ]; then
echo "Development software build failed! The script will continue but may have errors going further"
sleep 10
fi
fi
4 changes: 4 additions & 0 deletions setup_scripts/dev_install/riptide.repos
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ repositories:
type: git
url: https://github.com/osu-uwrt/riptide_gui.git
version: master
software/src/riptide_simulator:
type: git
url: https://github.com/osu-uwrt/riptide_simulator.git
version: master

# dependencies
dependencies/src/nortek_dvl:
Expand Down
33 changes: 33 additions & 0 deletions setup_scripts/matlab_install/check_toolboxes_installed.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
%
% UWRT Matlab installer toolbox checking script
%

fprintf("Checking for missing toolboxes...");
EXPECTED_TOOLBOXES = [
"MATLAB Coder";
"Robotics System Toolbox";
"Simulink Coder";
"HDL Coder";
"Fixed-Point Designer";
"Aerospace Toolbox";
"Embedded Coder";
"Control System Toolbox";
"Simulink";
"Aerospace Blockset";
"ROS Toolbox";
];

installed_toolboxes_table = matlab.addons.installedAddons;
installed_toolbox_names = installed_toolboxes_table{:, 1};
missing_toolboxes = setdiff(EXPECTED_TOOLBOXES, installed_toolbox_names);

if ~isempty(missing_toolboxes)
fprintf("MISSING TOOLBOXES DETECTED!\nToolboxes:\n");
for i = 1 : length(missing_toolboxes)
fprintf("%s\n", missing_toolboxes(i));
end
fprintf("\n");
error("Found missing toolboxes, listed above. Please install them and re-run the matlab configure script (configure_matlab.bash).")
end

fprintf("No missing toolboxes found.\n");
114 changes: 114 additions & 0 deletions setup_scripts/matlab_install/configure_matlab.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/bash

#
# UWRT MATLAB Configure script
# usage: ./configure_matlab.bash <matlab_install_dir> <python39_install_dir>
#

echo
echo "[INFO] Checking and configuring Matlab"
echo

# ensure that matlab executable exists. This means that matlab installed correctly.
matlabdir=$1
matlabexecutable=$matlabdir/bin/matlab
echo "Checking matlab"
while [ ! -f $matlabexecutable ] || [ "$matlabdir" = "" ]
do
echo
echo
echo "Expected to find a MATLAB executable at $matlabexecutable, however there is none present."
echo "Please enter the ABSOLUTE location of the matlab install directory: (currently: $matlabdir)"
read matlabdir
matlabexecutable=$matlabdir/bin/matlab
done

echo "Checking Python"
pythonexecutable=$2
while [ ! -f $pythonexecutable ] || [ "$pythonexecutable" = "" ]
do
echo
echo
echo "Expected to find a Python3.9 executable at $pythonexecutable, however there is none present."
echo "Please enter the ABSOLUTE location of the Python executable: (currently: $pythonexecutable)"
read pythonexecutable
done

#change into scripts directory so we can run matlab scripts
cd ~/osu-uwrt/riptide_setup/setup_scripts/matlab_install

#link matlab executable to /usr/bin so that it can be easily run
#this is done as a shell script because the matlab executable tries
#to reference files relative to itself.
echo "Linking MATLAB executable to /usr/bin"
rm -f $matlabdir/launch_matlab.bash #this prevents multiple installs from writing to the file a multiple times
cat >> $matlabdir/launch_matlab.bash << EOF
#!/usr/bin/bash
$matlabexecutable \$*

EOF
chmod +x $matlabdir/launch_matlab.bash

#check if the file exists
if [ -f "/usr/bin/matlab" ]
then
echo "/usr/bin/matlab already exists. Replace it [y/n]?"
read confirm
if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ]
then
echo "Removing"
sudo rm -f /usr/bin/matlab
else
echo "NOT removing"
fi
fi

sudo ln $matlabdir/launch_matlab.bash /usr/bin/matlab

#remove stdc++ shared lib that shipped with matlab. We want to use the system one, it works better
echo "Configuring MATLAB to use system stdc++ lib"
oldstdlib=`find $matlabdir/sys/os -maxdepth 2 -name libstdc++.so.6`
newstdlib=$oldstdlib.renamed
if [ "$oldstdlib" = "" ]
then
echo
echo "WARNING: The libstdc++.so.6 file (which should have shipped with MATLAB) was not found!"
echo "Please ensure that this file does not exist ANYWHERE in your MATLAB directory ($matlabdir)!"
echo "Your install may not work properly if it is not removed."
echo "Please press enter to continue."
echo
read
else
echo "Found stdc++ shared object file as : $oldstdlib"
echo "Renaming $oldstdlib to $newstdlib"
mv $oldstdlib $newstdlib
fi

#check that needed toolboxes are installed

echo "Checking that all required toolboxes are present"
matlab -batch check_toolboxes_installed
check_fail=$?
while [ $check_fail -eq 1 ]
do
echo
echo "Missing toolboxes detected. Please install the toolboxes listed above, then press enter to continue."
read

echo "Checking that all required toolboxes are present"
matlab -batch check_toolboxes_installed
check_fail=$?
done

#set up ros toolbox
echo "Configuring ROS toolbox environment"
matlab -batch "configure_rostoolbox(\"$pythonexecutable\")"

#configure custom msgs
echo "Configuring custom ROS message support"
# source ros first
. /opt/ros/$ROS_DISTRO/setup.bash
. ~/osu-uwrt/development/dependencies/install/setup.bash
. ~/osu-uwrt/development/software/install/setup.bash
ros2 run riptide_controllers2 model_manager.py refresh_custom_msg_support

36 changes: 36 additions & 0 deletions setup_scripts/matlab_install/configure_rostoolbox.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
%
% UWRT Matlab Installer ROS toolbox configuration script
% Need to set python executable to 3.9 and then manually invoke ROS venv
% setup
%
function configure_rostoolbox(python_location)
format compact

%save old python executable
old_pe = pyenv;
old_python = old_pe.Executable;

fprintf("Temporarily overriding python executable setting. Currently set to %s\n", old_python);

%activate python 3.9
pyenv("Version", python_location);

%check that it actually worked
new_pe = pyenv;
if new_pe.Executable ~= python_location
error("Python was not correctly set to 3.9! Cannot continue.\n");
end

%init ROS2 venv
fprintf("Configuring MATLAB ROS2 venv\n");
ros.ros2.internal.createOrGetLocalPython(true); %the "true" forces reinit

%set back old python executable
pyenv("Version", old_python);
new_pe = pyenv;
if new_pe.Executable == old_python
fprintf("Python executable successfully set back to %s\n", new_pe.Executable);
else
warning("Old python executable NOT successfully restored. It is now %s\n", new_pe.Executable);
end
end
67 changes: 67 additions & 0 deletions setup_scripts/matlab_install/install_matlab.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/bash

#
# UWRT Matlab Install Script
# usage: ./install_matlab.bash
# this script expects to be executed in its own directory. DONT call it from another directory
#

echo
echo "[INFO] Installing Matlab"
echo

MATLAB_INSTALL_LOCATION=~/osu-uwrt/matlab/MATLAB
mkdir -p $MATLAB_INSTALL_LOCATION #create target folder

#need to ask use to download the installer because we probably shouldnt host it on github
#because mathworks wouldnt be too happy about that. So we'll do that here
download_fail=1
while [ $download_fail -eq 1 ]
do
installer_name=uwrt_matlab_installer.zip

if [ -f "$HOME/Downloads/$installer_name" ]
then
#found file, check its sum. if the sum is good then while will break
echo "Found installer at $HOME/Downloads/$installer_name"
echo "Checking checksum"
echo "$(cat ~/osu-uwrt/riptide_setup/setup_scripts/matlab_install/uwrt_matlab_installer.zip.sha256) $HOME/Downloads/$installer_name" | sha256sum --check --status
download_fail=$? #download fail will be set to the result of the previous command
else
#could not find file. Ask user to download it
echo
echo
echo "Checksum of MATLAB Installer could not be verified. Please download the MATLAB installer!"
echo "You can find the UWRT offline installer on Teams in Software -> Files -> MATLAB -> uwrt_matlab_installer.zip."
echo
echo "Please download the file to your \"Downloads\" folder, then press enter to continue:"
read

if [ ! -f "$HOME/Downloads/$installer_name" ]
then
# file still not there. Maybe it has a different name
echo "Installer not found in Downloads directory. Perhaps it has a different name?"
echo "Please enter the name of the installer in the $HOME/Downloads directory (currently $installer_name)"
read installer_name
fi
fi
done

echo "Verified MATLAB installer at $HOME/Downloads/$installer_name"

#extract installer
echo "Extracting installer"
unzip -q ~/Downloads/$installer_name -d $MATLAB_INSTALL_LOCATION

#run installer
#TODO: document the process: ui/install/product_installer_ui/bundle.index.js
echo "Running installer"
$MATLAB_INSTALL_LOCATION/uwrt_matlab_installer/install

#remove installer
echo "Removing installer"
rm -rf $MATLAB_INSTALL_LOCATION/uwrt_matlab_installer

#post-installation tasks (install python, configure matlab)
~/osu-uwrt/riptide_setup/setup_scripts/matlab_install/install_python39.bash $MATLAB_INSTALL_LOCATION
~/osu-uwrt/riptide_setup/setup_scripts/matlab_install/configure_matlab.bash $MATLAB_INSTALL_LOCATION /usr/local/bin/python3.9
23 changes: 23 additions & 0 deletions setup_scripts/matlab_install/install_python39.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/bash

#
# MATLAB install helper; installs python 3.9, needed for venv to add custom msg support
# usage: ./install_python39.bash <directory>
#

echo
echo "[INFO] Installing Python 3.9"
echo

cd $1

# this downloads source archive and build it
wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
tar -xf Python-3.9.0.tgz
cd Python-3.9.0
./configure
echo "Building Python3.9"
make --quiet -j4
echo "Installing Python3.9"
sudo make --quiet altinstall

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
a6f0dabf2998c8288de76bff07c045a1a101c2c42edca3c6a3aed00799fe72b0
28 changes: 27 additions & 1 deletion setup_scripts/update_system.bash
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ case "$CHOICE" in
esac
printf "\n\n\n"

read -p "Install MATLAB? This will take approximately 15 additional minutes and use approximately 10 GB (default is no) " CHOICE
case "$CHOICE" in
[yY]*)
echo "Running MATLAB setup"
~/osu-uwrt/riptide_setup/setup_scripts/matlab_install/install_matlab.bash
;;

*)
echo "Skipping MATLAB setup"
;;
esac
printf "\n\n\n"

# install controller packages
echo "Installing most recent controller packages"
# source ros first
. /opt/ros/$ROS_DISTRO/setup.bash
. ~/osu-uwrt/development/dependencies/install/setup.bash
. ~/osu-uwrt/development/software/install/setup.bash
ros2 run riptide_controllers2 model_manager.py -y clean_workspace
ros2 run riptide_controllers2 model_manager.py -y download_packages --build

#setup groot
echo "Installing Groot"
~/osu-uwrt/riptide_setup/setup_scripts/install_groot.bash

# setup hosts and add hardware udev rules
echo "Setting up hardware and hosts files"
sudo ~/osu-uwrt/riptide_setup/setup_scripts/hardware/setup_hosts.bash
Expand All @@ -62,4 +88,4 @@ echo "Setting bashrc for development"

printf "\n\n\n"
echo "If no errors occurred during compilation, then everything was setup correctly"
echo "Please reboot your computer for final changes to take effect"
echo "Please reboot your computer for final changes to take effect"