From f402ae57ec223b804105ffc9e7e0cc6d84299e29 Mon Sep 17 00:00:00 2001 From: BTK203 Date: Sat, 17 Feb 2024 15:21:57 -0500 Subject: [PATCH 1/3] added initial matlab installer --- .../check_toolboxes_installed.m | 33 ++++++ .../matlab_install/configure_matlab.bash | 106 ++++++++++++++++++ .../matlab_install/configure_rostoolbox.m | 36 ++++++ .../matlab_install/install_matlab.bash | 60 ++++++++++ .../matlab_install/install_python39.bash | 22 ++++ .../uwrt_matlab_installer.zip.sha256 | 1 + setup_scripts/update_system.bash | 13 +++ 7 files changed, 271 insertions(+) create mode 100644 setup_scripts/matlab_install/check_toolboxes_installed.m create mode 100755 setup_scripts/matlab_install/configure_matlab.bash create mode 100644 setup_scripts/matlab_install/configure_rostoolbox.m create mode 100755 setup_scripts/matlab_install/install_matlab.bash create mode 100755 setup_scripts/matlab_install/install_python39.bash create mode 100644 setup_scripts/matlab_install/uwrt_matlab_installer.zip.sha256 diff --git a/setup_scripts/matlab_install/check_toolboxes_installed.m b/setup_scripts/matlab_install/check_toolboxes_installed.m new file mode 100644 index 00000000..9b2d2795 --- /dev/null +++ b/setup_scripts/matlab_install/check_toolboxes_installed.m @@ -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"); diff --git a/setup_scripts/matlab_install/configure_matlab.bash b/setup_scripts/matlab_install/configure_matlab.bash new file mode 100755 index 00000000..5d422e87 --- /dev/null +++ b/setup_scripts/matlab_install/configure_matlab.bash @@ -0,0 +1,106 @@ +#!/usr/bin/bash + +# +# UWRT MATLAB Configure script +# usage: ./configure_matlab.bash +# + +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 + +#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 "Replacing" + sudo rm -f /usr/bin/matlab + else + echo "NOT replacing" + 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" +ros2 run riptide_controllers2 model_manager.py refresh_custom_msg_support diff --git a/setup_scripts/matlab_install/configure_rostoolbox.m b/setup_scripts/matlab_install/configure_rostoolbox.m new file mode 100644 index 00000000..ecc11888 --- /dev/null +++ b/setup_scripts/matlab_install/configure_rostoolbox.m @@ -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 \ No newline at end of file diff --git a/setup_scripts/matlab_install/install_matlab.bash b/setup_scripts/matlab_install/install_matlab.bash new file mode 100755 index 00000000..e5a342e5 --- /dev/null +++ b/setup_scripts/matlab_install/install_matlab.bash @@ -0,0 +1,60 @@ +#!/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 + 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 + + 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, checking checksum" + echo "$(cat ./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 + echo "Installer not found in Downloads directory. Perhaps it has a different name?" + echo "Please enter the name of the installer in the Downloads directory (currently $installer_name)" + read installer_name + fi +done + +#extract installer +echo "Found MATLAB installer at $HOME/Downloads/$installer_name" +cp $MATLAB_INSTALL_LOCATION +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) +./install_python39.bash $MATLAB_INSTALL_LOCATION +./configure_matlab.bash $MATLAB_INSTALL_LOCATION /usr/local/bin/python3.9 diff --git a/setup_scripts/matlab_install/install_python39.bash b/setup_scripts/matlab_install/install_python39.bash new file mode 100755 index 00000000..7ccc528f --- /dev/null +++ b/setup_scripts/matlab_install/install_python39.bash @@ -0,0 +1,22 @@ +#!/usr/bin/bash + +# +# MATLAB install helper; installs python 3.9, needed for venv to add custom msg support +# usage: ./install_python39.bash +# + +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 -q -j4 +echo "Installing Python3.9" +sudo make -q altinstall diff --git a/setup_scripts/matlab_install/uwrt_matlab_installer.zip.sha256 b/setup_scripts/matlab_install/uwrt_matlab_installer.zip.sha256 new file mode 100644 index 00000000..0864eba1 --- /dev/null +++ b/setup_scripts/matlab_install/uwrt_matlab_installer.zip.sha256 @@ -0,0 +1 @@ +a6f0dabf2998c8288de76bff07c045a1a101c2c42edca3c6a3aed00799fe72b0 diff --git a/setup_scripts/update_system.bash b/setup_scripts/update_system.bash index 8152376f..16c18926 100755 --- a/setup_scripts/update_system.bash +++ b/setup_scripts/update_system.bash @@ -51,6 +51,19 @@ case "$CHOICE" in esac printf "\n\n\n" +read -p "Install MATLAB? This will take approximately 15 additional minutes and use approximately 17 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" + # 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 From 34757050c3dd43e72bfc2e4caae518cf6ee39525 Mon Sep 17 00:00:00 2001 From: BTK203 Date: Sat, 17 Feb 2024 21:15:45 -0500 Subject: [PATCH 2/3] integrate matlab, new controller, and simulator into setup --- setup_scripts/dev_install/install_dev.bash | 8 ++-- setup_scripts/dev_install/riptide.repos | 4 ++ .../install_groot.bash | 0 .../matlab_install/configure_matlab.bash | 12 +++++- .../matlab_install/install_matlab.bash | 41 +++++++++++-------- .../matlab_install/install_python39.bash | 5 ++- setup_scripts/update_system.bash | 17 +++++++- 7 files changed, 60 insertions(+), 27 deletions(-) rename setup_scripts/{optional_installs => }/install_groot.bash (100%) diff --git a/setup_scripts/dev_install/install_dev.bash b/setup_scripts/dev_install/install_dev.bash index 9e6e5917..235f389c 100755 --- a/setup_scripts/dev_install/install_dev.bash +++ b/setup_scripts/dev_install/install_dev.bash @@ -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 @@ -49,9 +47,11 @@ 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 @@ -59,4 +59,4 @@ colcon build if [ $? -ne 0 ]; then echo "Development software build failed! The script will continue but may have errors going further" sleep 10 -fi \ No newline at end of file +fi diff --git a/setup_scripts/dev_install/riptide.repos b/setup_scripts/dev_install/riptide.repos index 5919777e..12156eaa 100644 --- a/setup_scripts/dev_install/riptide.repos +++ b/setup_scripts/dev_install/riptide.repos @@ -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: diff --git a/setup_scripts/optional_installs/install_groot.bash b/setup_scripts/install_groot.bash similarity index 100% rename from setup_scripts/optional_installs/install_groot.bash rename to setup_scripts/install_groot.bash diff --git a/setup_scripts/matlab_install/configure_matlab.bash b/setup_scripts/matlab_install/configure_matlab.bash index 5d422e87..16981c98 100755 --- a/setup_scripts/matlab_install/configure_matlab.bash +++ b/setup_scripts/matlab_install/configure_matlab.bash @@ -34,6 +34,9 @@ do 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. @@ -53,10 +56,10 @@ then read confirm if [ "$confirm" = "y" ] || [ "$confirm" = "Y" ] then - echo "Replacing" + echo "Removing" sudo rm -f /usr/bin/matlab else - echo "NOT replacing" + echo "NOT removing" fi fi @@ -103,4 +106,9 @@ 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 + diff --git a/setup_scripts/matlab_install/install_matlab.bash b/setup_scripts/matlab_install/install_matlab.bash index e5a342e5..b31c80d7 100755 --- a/setup_scripts/matlab_install/install_matlab.bash +++ b/setup_scripts/matlab_install/install_matlab.bash @@ -4,6 +4,7 @@ # 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" @@ -17,32 +18,38 @@ mkdir -p $MATLAB_INSTALL_LOCATION #create target folder download_fail=1 while [ $download_fail -eq 1 ] do - 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 - 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, checking checksum" - echo "$(cat ./uwrt_matlab_installer.zip.sha256) $HOME/Downloads/$installer_name" | sha256sum --check --status + 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 - echo "Installer not found in Downloads directory. Perhaps it has a different name?" - echo "Please enter the name of the installer in the Downloads directory (currently $installer_name)" - read installer_name + #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 "Found MATLAB installer at $HOME/Downloads/$installer_name" -cp $MATLAB_INSTALL_LOCATION echo "Extracting installer" unzip -q ~/Downloads/$installer_name -d $MATLAB_INSTALL_LOCATION @@ -56,5 +63,5 @@ echo "Removing installer" rm -rf $MATLAB_INSTALL_LOCATION/uwrt_matlab_installer #post-installation tasks (install python, configure matlab) -./install_python39.bash $MATLAB_INSTALL_LOCATION -./configure_matlab.bash $MATLAB_INSTALL_LOCATION /usr/local/bin/python3.9 +~/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 diff --git a/setup_scripts/matlab_install/install_python39.bash b/setup_scripts/matlab_install/install_python39.bash index 7ccc528f..2371005b 100755 --- a/setup_scripts/matlab_install/install_python39.bash +++ b/setup_scripts/matlab_install/install_python39.bash @@ -17,6 +17,7 @@ tar -xf Python-3.9.0.tgz cd Python-3.9.0 ./configure echo "Building Python3.9" -make -q -j4 +make --quiet -j4 echo "Installing Python3.9" -sudo make -q altinstall +sudo make --quiet altinstall + diff --git a/setup_scripts/update_system.bash b/setup_scripts/update_system.bash index 16c18926..c8982763 100755 --- a/setup_scripts/update_system.bash +++ b/setup_scripts/update_system.bash @@ -51,7 +51,7 @@ case "$CHOICE" in esac printf "\n\n\n" -read -p "Install MATLAB? This will take approximately 15 additional minutes and use approximately 17 GB (default is no) " CHOICE +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" @@ -64,6 +64,19 @@ case "$CHOICE" in 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 @@ -75,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" \ No newline at end of file +echo "Please reboot your computer for final changes to take effect" From 3f5cb8a15466a5d3b9aa52013929a7882bfe4fdb Mon Sep 17 00:00:00 2001 From: BTK203 Date: Sat, 17 Feb 2024 23:23:59 -0500 Subject: [PATCH 3/3] fix installer detection logic error --- setup_scripts/matlab_install/install_matlab.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup_scripts/matlab_install/install_matlab.bash b/setup_scripts/matlab_install/install_matlab.bash index b31c80d7..a41e17ef 100755 --- a/setup_scripts/matlab_install/install_matlab.bash +++ b/setup_scripts/matlab_install/install_matlab.bash @@ -37,7 +37,7 @@ do echo "Please download the file to your \"Downloads\" folder, then press enter to continue:" read - if [ -f "$HOME/Downloads/$installer_name" ] + 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?"