Skip to content

Commit

Permalink
Added automatic services
Browse files Browse the repository at this point in the history
  • Loading branch information
vortexuser committed Mar 26, 2024
1 parent c36646a commit 16e1eb5
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 88 deletions.
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
28 changes: 25 additions & 3 deletions scripts/add_service_files_to_bootup_sequence.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ 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/"

Expand All @@ -20,32 +24,44 @@ cd $SCRIPT_DIR


# Setup ----------
echo "Seting up .service files..."
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



Expand All @@ -57,13 +73,19 @@ 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' has been installed and started successfully :)"
echo "'$SERVICE_FILE_NAME_TEMPERATURE' has been installed and started successfully :)"
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.

15 changes: 0 additions & 15 deletions sensors/bms/startup_scripts/bms_startup.service

This file was deleted.

23 changes: 0 additions & 23 deletions sensors/bms/startup_scripts/bms_startup_backup.service

This file was deleted.

2 changes: 1 addition & 1 deletion sensors/temperature/README
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ We messure temperature of the 4 ESCs that run the thrusters as well as 2 temperu

## Service file bootup

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

Enjoy :)
Expand Down
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

0 comments on commit 16e1eb5

Please sign in to comment.