diff --git a/README.md b/README.md index 2814938..3f43a3d 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,35 @@ Nvidia Jeston TX2/Xavier/XavierNX have CAN controller(s) integrated in the main # receiving data from can0 $ candump can0 ``` +--------------------------------------------------------------------------------- + +**Alternatives to 3:** +1) Add into bunker_robot_base.launch: +``` + +``` +* The ROS environment is set up to handle password prompts, or configure sudo to allow these commands to execute without a password. This can be done by editing the sudoers file (using sudo visudo) like so: + ``` + $ sudo visudo + ``` +* And adding a line for specific commands to be run without a password: + ``` + ALL=(ALL) NOPASSWD: /sbin/modprobe, /sbin/ip link set can0 up type can bitrate 500000 + ``` +OR + +2) Run the shellscript: +``` +$ sudo ./bunker_pro.sh +``` +*Note*: modify bunker_pro.sh: +``` +# Replace '/opt/ros/noetic' with your actual ROS distribution path. +source /opt/ros/noetic/setup.bash +# Replace '/home/ara/bunker_ws' with your actual ROS ws path. +source /home/ara/bunker_ws/devel/setup.bash +``` +--------------------------------------------------------------------------------- 4. Launch ROS nodes diff --git a/bunker_bringup/launch/bunker_robot_base.launch b/bunker_bringup/launch/bunker_robot_base.launch index 210c64f..f0c41ee 100644 --- a/bunker_bringup/launch/bunker_robot_base.launch +++ b/bunker_bringup/launch/bunker_robot_base.launch @@ -8,6 +8,8 @@ + + diff --git a/bunker_bringup/scripts/bunker_pro.sh b/bunker_bringup/scripts/bunker_pro.sh new file mode 100644 index 0000000..3426662 --- /dev/null +++ b/bunker_bringup/scripts/bunker_pro.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +# Check for root permissions +if [ "$(id -u)" != "0" ]; then + echo "This script must be run as root" >&2 + exit 1 +fi + +# Source the ROS environment +# Replace '/opt/ros/noetic' with your actual ROS distribution path. +source /opt/ros/noetic/setup.bash +# Replace '/home/ara/bunker_ws' with your actual ROS ws path. +source /home/ara/bunker_ws/devel/setup.bash + +# Load the gs_usb kernel module if not already loaded +if ! lsmod | grep -q gs_usb; then + echo "Loading gs_usb module..." + sudo modprobe gs_usb +else + echo "gs_usb module already loaded." +fi + +# Set up the can0 device with a specified bitrate if not already set +# Check if can0 is already up with the correct settings +current_bitrate=$(ip -details link show can0 | grep -oP 'bitrate \K[^ ]+' || echo "down") + +if [[ $current_bitrate != "500000" ]]; then + echo "Setting up CAN0 interface..." + sudo ip link set can0 up type can bitrate 500000 + if [ $? -eq 0 ]; then + echo "CAN0 interface setup successful." + else + echo "Failed to set up CAN0 interface." >&2 + exit 2 + fi +else + echo "CAN0 interface already set up with correct bitrate." +fi + +# Launch the ROS nodes +echo "Launching ROS nodes..." +roslaunch bunker_bringup bunker_robot_base.launch