-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hardware-testing): Added hardware testing usb package (#13140)
The hardware-testing package is used for testing various parts of the Flex, however in order to use it you have to have a computer that has all of our packages, and dependencies and has been set up to run our software. This poses some friction as it requires a lot to get up and running. This pr solves this problem by creating a hardware-testing package, that can be run from a USB drive plugged directly into the Flex. - Added setup-usb-module to hardware-testing Makefile, which creates a USB package - Added hardware-testing entry to scripts/python_build_utils.py so we can get the package version - Added correct versioning based on git tags when producing sdist/wheel files
- Loading branch information
Showing
5 changed files
with
297 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
hardware-testing/hardware_testing/tools/usb-package/readme.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
## OVERVIEW | ||
The usb-package bundles up the hardware_testing module so it can run from a usb thumbdrive on the Flex. | ||
|
||
## INSTRUCTIONS | ||
|
||
### How to make package: | ||
make -C hardware-testing setup-usb-module | ||
This will produce a tar file **hardware_testing_usb-<version>.tar.gz** in **hardware-testing/dist/** | ||
example: | ||
hardware_testing_usb-0.0.1.tar.gz | ||
|
||
You can also make and install the tar file to a target with the **usb_dir** option | ||
This will extract the contents to the specified location | ||
make -C hardware-testing setup-usb-module usb_dir="/Volumes/ENFAIN/" | ||
|
||
### How to deploy: | ||
If you use the **usb_dir** option the usb-package will be installed on the usb drive | ||
You can also manually extract the tar file onto a target like so | ||
tar -xvf hardware_testing_usb-0.0.1.tar.gz -C "<drive-location>" | ||
|
||
### How to install on the Flex: | ||
Once you have an usb thumdrive with the usb-packge deployed you can plug in the thumbdrive to | ||
a Flex and start the setup script to install the required files like so | ||
|
||
0. Make sure the Flex is powered on | ||
1. ssh to the robot with | ||
ssh root@<ip-address> | ||
NOTE: You can also use screen or similar if you are using an FTDI connection | ||
screen /dev/<ftdi-device> 115200 | ||
2. Plug in the hardware-testing thumbdrive to the Flex | ||
The device should be mounted to **/media/sda** or similar | ||
Note: You can also manually mount the thumbdrive with | ||
a. From the Linux command line list usb devices with | ||
blkid | ||
Note: | ||
Your drive address should be something like | ||
**/dev/sda: LABEL="ENFAIN"...** | ||
The LABEL should be the name of your usb thumbdrive | ||
b. mount the drive | ||
mount /dev/sda /mnt | ||
c. the device should now be accessed thorugh /mnt | ||
3. Navigate to the mounted drive | ||
a. if drive was automatically mounted, run | ||
cd /media/sdx/hardware_testing_usb where x is the enumerated drive | ||
b. or if mounted manually | ||
cd /mnt/hardware_testing_usb | ||
4. Run the setup script | ||
a. From the usb-packge dir **hardware_testing_usb** run | ||
./setup | ||
5. Re-logging to apply | ||
a. from the command shell run | ||
logout | ||
b. use ssh or screen to log back in | ||
see step 1 above. | ||
6. You should now see | ||
**Hardware-Testing package enabled at <mount-location>/hardware_testing_usb** | ||
|
||
Note: **<mount-location>** is where the thumbdrive was mounted typically **/media/sdx** | ||
but could also be **/mnt** or different if mounted manually | ||
7. Done | ||
a. The hardware-testing package is now setup and can be used as normal | ||
example: | ||
python3 -m hardware_testing.scripts.module_calibration | ||
|
||
|
||
### How to uninstall from the Flex: | ||
With the usb thumbdrive plugged into the Flex | ||
1. Navigate to usb-packge dir | ||
cd <mount-location>/hardware_testing_usb | ||
2. Run the setup script | ||
./setup teardown | ||
You should see **Teardown Success** | ||
3. The usb drive can now be removed | ||
|
||
|
||
### Troubleshoting | ||
|
||
If the usb thumbdrive is removed and replugged it could enumerate differently. | ||
This means you will need to run the ./setup script again |
145 changes: 145 additions & 0 deletions
145
hardware-testing/hardware_testing/tools/usb-package/setup.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
#! /bin/bash | ||
|
||
# This script sets up the hardware-testing module to run from usb or some other dir on the Flex robot. Read the readme.txt file for setup and instructions. | ||
|
||
USB_DIR=$(pwd) | ||
MOUNT_DIR=$(dirname ${USB_DIR}) | ||
PACKAGE_VERSION="" | ||
PACKAGE_NAME="hardware_testing" | ||
PACKAGE_DIR=$(echo ${USB_DIR}/${PACKAGE_NAME}-*/) | ||
PACKAGE_TAR_FILE=$(echo ${USB_DIR}/${PACKAGE_NAME}-*.tar.gz) | ||
PKG_INFO_FILE=$PACKAGE_DIR/PKG-INFO | ||
SYSTEM_VERSION_FILE="/etc/VERSION.json" | ||
ENV_PROFILE="/etc/profile.d/ot-usb-environ.sh" | ||
|
||
# Script entry-point | ||
main() { | ||
echo "Validating files" | ||
validate "$@" | ||
|
||
# execute action | ||
case $1 in | ||
teardown) | ||
echo "Teardown" | ||
teardown | ||
;; | ||
*) | ||
echo "Setup" | ||
setup | ||
;; | ||
esac | ||
} | ||
|
||
# Make sure we have the correct files before doing anything | ||
validate() { | ||
# Check if we are running on the robot or not | ||
if [ ! -f $SYSTEM_VERSION_FILE ]; then | ||
echo "${SYSTEM_VERSION_FILE} not found, make sure you're running this from a robot!" | ||
exit 1; | ||
fi | ||
is_flex=$(cat $SYSTEM_VERSION_FILE | grep -o OT-3) | ||
if [ -z $is_flex ]; then | ||
echo "Make sure robot is a Flex before running setup." | ||
exit 1 | ||
fi | ||
|
||
# Extract the tarball | ||
usb_module_filename=$(ls $PACKAGE_TAR_FILE) | ||
if [ ! -f "$usb_module_filename" ]; then | ||
echo "Could not find package tarball - ${PACKAGE_TAR_FILE}" | ||
exit 1; | ||
fi | ||
} | ||
|
||
_extract_tarball() { | ||
echo "Extracting tarball ${usb_module_filename}" | ||
tar -xvf $usb_module_filename -C $USB_DIR | ||
|
||
# Get the version of the package | ||
if [ ! -f $PKG_INFO_FILE ]; then | ||
echo "error: ${PKG_INFO_FILE} was not found!" | ||
exit 1; | ||
fi | ||
PACKAGE_VERSION=$(cat ${PKG_INFO_FILE} | sed -n '/Version/{n;n;p}') | ||
} | ||
|
||
|
||
# Helper function to write/delete environment variable profile script | ||
_env_profile() { | ||
# mount the filesystem rw | ||
mount -o remount,rw / | ||
|
||
if [[ $1 =~ "delete" ]]; then | ||
echo "Deleting usb-package env file - ${ENV_PROFILE}" | ||
rm -rf $ENV_PROFILE | ||
mount -o remount,ro / | ||
return; | ||
fi | ||
|
||
echo "Writing usb-package env profile - $ENV_PROFILE" | ||
|
||
cat <<EOF > $ENV_PROFILE | ||
#!/usr/bin/env sh | ||
# Do an auto-teardown if the usb device is not found | ||
if [ ! -d $USB_DIR ]; then | ||
mount -o remount,rw / | ||
rm -rf $ENV_PROFILE | ||
mount -o remount,ro / | ||
return 1; | ||
fi | ||
echo "Hardware-Testing package enabled at $USB_DIR" | ||
export PYTHONPATH=\$PYTHONPATH:$PACKAGE_DIR | ||
# set OT_SYSTEM_VERSION if not set | ||
if [ -z \$OT_SYSTEM_VERSION ]; then | ||
export OT_SYSTEM_VERSION="0.0.0" | ||
fi | ||
# set the TESTING_DATA_DIR | ||
export TESTING_DATA_DIR=$USB_DIR/testing_data | ||
EOF | ||
# remount filesystem as ro | ||
mount -o remount,ro / | ||
} | ||
|
||
# Sets up the hardware-testing module to be used from usb location | ||
setup() { | ||
echo "Setting up hardware-testing module ${PACKAGE_VERSION}" | ||
|
||
# lets extract that tarball | ||
_extract_tarball | ||
|
||
# Lets set up the environment profile | ||
_env_profile | ||
|
||
# TODO (ba, 2023-07-19): set the logging location for hardware-testing scripts to usb | ||
# We need to consilidate hardware-testing logging before being able to do this. | ||
|
||
# Lets deal with plot-webpage since the sdist file only contains .py files | ||
cp -r $USB_DIR/plot $PACKAGE_DIR/$PACKAGE_NAME/tools/ | ||
|
||
# Lets deal with hardware-testing-description file, is /data correct? | ||
cp -r $USB_DIR/.hardware-testing-description /data/ | ||
|
||
echo "Hardware-Testing module has been setup, re-login to apply changes." | ||
} | ||
|
||
# Tearsdown the hardare-testing module | ||
teardown() { | ||
echo "Tearing down hardare-testing module ${PACKAGE_VERSION}" | ||
|
||
# delete the environment profile | ||
_env_profile delete | ||
|
||
# delete the description file | ||
rm -rf /data/.hardware-testing-description | ||
|
||
echo "Teardown Success" | ||
} | ||
|
||
set -eE -o pipefail | ||
trap teardown ERR | ||
|
||
main "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters