Entire process of installing bringup manually using a systemd service.
rosrun robot_upstart uninstall robot_uppstart_serviceNote : robot_upstart_service replace this with your service name without .service extension.
2. Create a bash script for roslaunch to upstart your robo. (For Simplycity I'll call this launch.sh)
#!/bin/bash
counter=10 # Set counter variable to 10
echo "home = $HOME"
source /opt/ros/noetic/setup.bash
source /home/amrita-acrux/ros1_ws/devel/setup.bash
export ROS_HOSTNAME=$(hostname -I | awk '{print $1}')
# Function to check and source the file
check_and_source() {
if [[ "$ROS_HOSTNAME" == *"localhost"* || -z "$ROS_HOSTNAME" ]]; then
source $HOME/.bashrc
return 0 # Success
else
return 1 # Failure
fi
}
# Attempt to source the file counter times
while [ $counter -gt 0 ]; do
check_and_source
if [ $? -eq 0 ]; then
((counter--))
else
break
fi
sleep 1
done
# Check if the loop was successful
if [ $counter -eq 0 ]; then
echo "DIDN'T WORK"
else
echo "LET'S GOO"
roslaunch ROBOT_FIRMWARE ROBOT_LAUNCH_FILE.LAUNCH
fiNote, here replace ROBOT_FIRMWARE with Your Robot's Package name.
and Replace ROBOT_LAUNCH_FILE.LAUNCH with your robot's Laucnh File.
IMPORTANT. (Make sure the file you created has executable permissions)
chmod +x launch.shon this path /etc/systemd/user/robot_bringup.service
[Unit]
Description=RigBetel Labs ROBOT UPSTART SCRIPT
After=NetworkManager.service
[Service]
Type=simple
ExecStart=/path/to/your/above/bash/script.sh
Restart=always
[Install]
WantedBy=default.targetNote If Possible try changing $HOME with your full path as it will be more accurate.
Replace /path/to/your/above/bash/launch.sh with the path to your launch.sh shell script.
systemctl enable --user robot_bringup.serviceNOTE : We are not running the below command with SUDO, don't use sudo as we are doing it for the robot user only.
5. Check whether the systemd service is started correctly or not. Some helpful commands are given below.
systemctl start --user robot_bringup.serviceCheck Status
systemctl status --user robot_bringup.serviceTo check Logs
journalctl --user-unit robot_bringup.serviceNote this is the most important step.
Why are are doing this? We need something to start a user session so that after each boot it should start the systemd service automatically.
loginctl enable-lingerNote, make sure you are doing it from the same user you configured the service
OR
loginctl enable-linger robot-username