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

Feature/service file launch #162

Merged
merged 2 commits into from
Mar 26, 2024
Merged
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
25 changes: 25 additions & 0 deletions mission/blackbox/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Balackbox

Logs data of all the important topics such as:
/asv/power_sense_module/current
/asv/power_sense_module/voltage
/asv/temperature/ESC1
/asv/temperature/ESC2
/asv/temperature/ESC3
/asv/temperature/ESC4
/asv/temperature/ambient1
/asv/temperature/ambient2
internal/status/bms0
internal/status/bms1
/thrust/thruster_forces
/pwm


## Service file bootup

To start the blackbox loging automaticaly every time on bootup just run this command:
```
./vortex-asv/add_service_files_to_bootup_sequence.sh
```

Enjoy :)
4 changes: 3 additions & 1 deletion mission/blackbox/startup_scripts/blackbox.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ After=network.target

[Service]
# Use the wrapper script for ExecStart
ExecStart=/bin/bash <home directory>/<username>/<workspace>/src/vortex-asv/mission/blackbox/startup_scripts/blackbox.sh
# DONT CHANGE THIS LINE!!!!
# Use vortex-asv/scripts/add_service_files_to_bootup_sequence.sh to automaticaly set everything up
ExecStart=/bin/bash '<pathToThisFile>blackbox.sh'
WorkingDirectory=/home/vortex/
StandardOutput=journal+console
User=vortex
Expand Down
9 changes: 9 additions & 0 deletions mission/internal_status/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ This ros node just publishes the current and voltage data we get from the lib to
* /asv/power_sense_module/current for the current data [A]
* /asv/power_sense_module/voltage for the voltage data [V]

## Service file bootup

To start the internal_status publishing automaticaly every time on bootup just run this command:
```
./vortex-asv/add_service_files_to_bootup_sequence.sh
```

Enjoy :)




Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ After=network.target

[Service]
# Use the wrapper script for ExecStart
ExecStart=/bin/bash /home/vortex/rose_test_ws/src/vortex-asv/mission/internal_status/startup_scripts/internal_status.sh
# DONT CHANGE THIS LINE!!!!
# Use vortex-asv/scripts/add_service_files_to_bootup_sequence.sh to automaticaly set everything up
ExecStart=/bin/bash '<pathToThisFile>internal_status.sh'
WorkingDirectory=/home/vortex/
StandardOutput=journal+console
User=vortex
Expand Down
91 changes: 91 additions & 0 deletions scripts/add_service_files_to_bootup_sequence.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/bin/bash

# Variables ----------
# Define variables for launching service files
SERVICE_FILE_NAME_BMS="bms.service"
SERVICE_FILE_PATH_BMS="../sensors/bms/startup_scripts/"
SERVICE_FILE_NAME_TEMPERATURE="temperature.service"
SERVICE_FILE_PATH_TEMPERATURE="../sensors/temperature/startup_scripts/"
SERVICE_FILE_NAME_INTERNAL_STATUS="internal_status.service"
SERVICE_FILE_PATH_INTERNAL_STATUS="../mission/internal_status/startup_scripts/"
SERVICE_FILE_NAME_BLACKBOX="blackbox.service"
SERVICE_FILE_PATH_BLACKBOX="../mission/blackbox/startup_scripts/"

SYSTEMD_PATH="/etc/systemd/system/"



# Navigating ----------
echo "Navigated to the correct folder..."
# Get scripts directory and go there
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/"
cd $SCRIPT_DIR



# Setup ----------
echo "Setting up .service files..."
# Copy the .service files to current directory
cp $SERVICE_FILE_PATH_BMS$SERVICE_FILE_NAME_BMS $SERVICE_FILE_NAME_BMS # BMS
cp $SERVICE_FILE_PATH_TEMPERATURE$SERVICE_FILE_NAME_TEMPERATURE $SERVICE_FILE_NAME_TEMPERATURE # Temperature
cp $SERVICE_FILE_PATH_INTERNAL_STATUS$SERVICE_FILE_NAME_INTERNAL_STATUS $SERVICE_FILE_NAME_INTERNAL_STATUS # Internal Status
cp $SERVICE_FILE_PATH_BLACKBOX$SERVICE_FILE_NAME_BLACKBOX $SERVICE_FILE_NAME_BLACKBOX # Blackbox

# Replace placeholders in the .service files
# Note: This assumes <pathToThisFile> is to be replaced with the current directory
sed -i "s|<pathToThisFile>|$SCRIPT_DIR$SERVICE_FILE_PATH_BMS|g" $SERVICE_FILE_NAME_BMS # BMS
sed -i "s|<pathToThisFile>|$SCRIPT_DIR$SERVICE_FILE_PATH_TEMPERATURE|g" $SERVICE_FILE_NAME_TEMPERATURE # Temperature
sed -i "s|<pathToThisFile>|$SCRIPT_DIR$SERVICE_FILE_PATH_INTERNAL_STATUS|g" $SERVICE_FILE_NAME_INTERNAL_STATUS # Internal Status
sed -i "s|<pathToThisFile>|$SCRIPT_DIR$SERVICE_FILE_PATH_BLACKBOX|g" $SERVICE_FILE_NAME_BLACKBOX # Blackbox

# Kill the systems service files if it exists
sudo systemctl kill $SERVICE_FILE_NAME_BMS # BMS
sudo systemctl kill $SERVICE_FILE_NAME_TEMPERATURE # Temperature
sudo systemctl kill $SERVICE_FILE_NAME_INTERNAL_STATUS # Internal Status
sudo systemctl kill $SERVICE_FILE_NAME_BLACKBOX # Blackbox

# Copy the modified .service files to the systemd directory
# Note: Need sudo permission to copy to /etc/systemd/system
sudo cp $SERVICE_FILE_NAME_BMS $SYSTEMD_PATH # BMS
sudo cp $SERVICE_FILE_NAME_TEMPERATURE $SYSTEMD_PATH # Temperature
sudo cp $SERVICE_FILE_NAME_INTERNAL_STATUS $SYSTEMD_PATH # Internal Status
sudo cp $SERVICE_FILE_NAME_BLACKBOX $SYSTEMD_PATH # Blackbox

# Delete the redundant copy
rm $SERVICE_FILE_NAME_BMS # BMS
rm $SERVICE_FILE_NAME_TEMPERATURE # Temperature
rm $SERVICE_FILE_NAME_INTERNAL_STATUS # Internal Status
rm $SERVICE_FILE_NAME_BLACKBOX # Blackbox

# Change permision of the .service files
sudo chmod 777 $SYSTEMD_PATH$SERVICE_FILE_NAME_BMS # BMS
sudo chmod 777 $SYSTEMD_PATH$SERVICE_FILE_NAME_TEMPERATURE # Temperature
sudo chmod 777 $SYSTEMD_PATH$SERVICE_FILE_NAME_INTERNAL_STATUS # Internal Status
sudo chmod 777 $SYSTEMD_PATH$SERVICE_FILE_NAME_BLACKBOX # Blackbox



# Launching ----------
echo "Launching .service files..."
# Reload systemd to recognize the new services
sudo systemctl daemon-reload

# Enable new services to start on boot
sudo systemctl enable $SERVICE_FILE_NAME_BMS # BMS
sudo systemctl enable $SERVICE_FILE_NAME_TEMPERATURE # Temperature
sudo systemctl enable $SERVICE_FILE_NAME_INTERNAL_STATUS # Internal Status
sudo systemctl enable $SERVICE_FILE_NAME_BLACKBOX # Blackbox

# Start the services immediately
sudo systemctl start $SERVICE_FILE_NAME_BMS # BMS
sudo systemctl start $SERVICE_FILE_NAME_TEMPERATURE # Temperature
sudo systemctl start $SERVICE_FILE_NAME_INTERNAL_STATUS # Internal Status
sudo systemctl start $SERVICE_FILE_NAME_BLACKBOX # Blackbox



# Debugging ----------
echo "'$SERVICE_FILE_NAME_BMS' - installed and started successfully :)"
echo "'$SERVICE_FILE_NAME_TEMPERATURE' - installed and started successfully :)"
echo "'$SERVICE_FILE_NAME_INTERNAL_STATUS' - installed and started successfully :)"
echo "'$SERVICE_FILE_NAME_BLACKBOX' - installed and started successfully :)"
23 changes: 4 additions & 19 deletions sensors/bms/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,12 @@ create_key_value_pair(key: str, value) -> KeyValue:
creates KeyValue object from supplied key and value
```

## Startup service
## Service file bootup

Note: The .service file may need to be edited in order to source the setup.bash file
from the correct workspace.

This package also contains a .service file for running the node on startup. To enable this, just run (from this directory)
```
sudo cp startup_script/bms_startup.service /etc/systemd/system/bms_startup.service
```
then run the following commands
```
cd /etc/systemd/system
```
```
sudo systemctl daemon-reload && sudo systemctl enable bms_startup.service
```
To verify that the service is enabled, run
To start the BMS publishing automaticaly every time on bootup just run this command:
```
systemctl list-unit-files | grep enabled
./vortex-asv/add_service_files_to_bootup_sequence.sh
```
The file will now run automatically on startup the next time the system starts.

If this fails, try checking if systemd is installed.
Enjoy :)

17 changes: 0 additions & 17 deletions sensors/bms/startup_script/bms.service

This file was deleted.

7 changes: 0 additions & 7 deletions sensors/bms/startup_script/bms.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ After=network.target

[Service]
# Use the wrapper script for ExecStart
ExecStart=/bin/bash <home directory>/<username>/<workspace>/src/vortex-asv/sensors/bms/startup_scripts/bms.sh
# DONT CHANGE THIS LINE!!!!
# Use vortex-asv/scripts/add_service_files_to_bootup_sequence.sh to automaticaly set everything up
ExecStart=/bin/bash '<pathToThisFile>bms.sh'
WorkingDirectory=/home/vortex/
StandardOutput=journal+console
User=vortex
Expand Down
23 changes: 0 additions & 23 deletions sensors/bms/startup_scripts/bms_startup_backup.service

This file was deleted.

11 changes: 11 additions & 0 deletions sensors/temperature/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Temperature

We messure temperature of the 4 ESCs that run the thrusters as well as 2 temperure sensors for the ambient temperature in the electrical housing

## Service file bootup

To start the Temperature publishing automaticaly every time on bootup just run this command:
./vortex-asv/add_service_files_to_bootup_sequence.sh

Enjoy :)

4 changes: 3 additions & 1 deletion sensors/temperature/startup_scripts/temperature.service
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ After=network.target

[Service]
# Use the wrapper script for ExecStart
ExecStart=/bin/bash /home/vortex/rose_test_ws/src/vortex-asv/sensors/temperature/startup_scripts/temperature.sh
# DONT CHANGE THIS LINE!!!!
# Use vortex-asv/scripts/add_service_files_to_bootup_sequence.sh to automaticaly set everything up
ExecStart=/bin/bash '<pathToThisFile>temperature.sh'
WorkingDirectory=/home/vortex/
StandardOutput=journal+console
User=vortex
Expand Down
Loading