본문 바로가기

카테고리 없음

(bash) ydlidar launch 실행 스크립트 (라즈베리파이4/우분투 24.04/ROS2 Jazzy)

#!/bin/bash

# ydlidar launch를 실행하는 긴 명령을 자동화한 것
# 라이다가 사용할 장치명
device='/dev/ttyUSB0'
# 사용권한 chmod 777 결과에 해당
keyword='*crwxrwxrwx*'

# 해당 장치가 있는지 확인, 없으면 종료
if [[ ! -c $device ]]; then
  echo "$device not exist. exit..."
  exit
fi

# 장치가 있다면 권한을 조사해서 777이 아니라면 chmod 777을 해준다.
echo "$device is exsit. checking the permissions..."
str=$(ls -l $device | cut -d' ' -f 1) # 리스트에서 'crwx......' 문구만 뽑아낸다.
if [[ $str == $keyword ]]; then  # crwx...... 가 crwxrwxrwx 라면 777이므로 OK
  echo "permissions OK."
else
  echo "permissions not OK. 'sudo chmod 777 $device' needed. I'm doing this."
  sudo chmod 777 $device
fi 

# 요건이 충족되었으므로 프로그램 실행
echo "let's start the main program."

# ROS2용 환경 변수 불러오기
source /opt/ros/jazzy/setup.bash
source $HOME/ydlidar_ws/install/setup.bash
ros2 launch ydlidar_ros2_driver ydlidar_launch_view.py