일상 코딩
[ROS / catkins-tools] catkin-tools 환경설정 세팅 본문
1.설치
$ sudo apt install python3-osrf-pycommon
$ sudo apt install python3-catkin-tools
2. work space 폴더 생성
$ cd
$ mkdir -p ~/catkin_ws/src
3. catkin init & catkin build
$ cd catkin_ws
만약, 다른 폴더에서 catkin init을 했을시,
$ catkin clean --deinit
위 코드를 해당 폴더에서 실행시켜서 초기화 해준 후 아래 코드를 "catkin_ws" 폴더로 이동 후 실행한다.
출처 - https://answers.ros.org/question/66012/removing-catkin-workspace/
$ catkin init
$ catkin build
4. 패키지 생성
$ cd catkin_ws
$ catkin create pkg hello_world --catkin-deps std_msgs rosp
5. VSCode 환경설정
hello_world 폴더로 이동 후 VSCode 실행
$ cd ~/catkin_ws/src/hello_world/
$ code .
scripts 폴더 생성 후 이 폴더 내에서
print_turtle_pos.py 파일 생성
#!/usr/bin/env python
import rospy
from turtlesim.msg import Pose
def callback(data):
rospy.loginfo("Turtle Pose X : %s, Y : %s", data.x, data.y)
def print_turtle_pos():
rospy.init_node('print_turtle_pos', anonymous=False)
rospy.Subscriber("/turtle1/pose", Pose, callback)
rospy.spin()
if __name__ == "__main__":
print_turtle_pos()
맨위에
#!/usr/bin/env python 를 꼭 넣어준다.
ROS가 실행 시 python 환경을 지정하는 명령어이다.
6. print_turtle_pos.py 파일 실행 권한 부여.
$ cd ~/catkin_ws/src/hello_world/scripts
$ chmod +x print_turtle_pos.py
7. 패키지 빌드
$ cd ~/catkin_ws
$ catkin build hello_world
8. 패키지 인식 확인
$ cd ~/catkin_ws
$ roscd he
he 까지 입력하고 <TAB>을 눌러서 자동완성이 되는지 확인한다.
자동완성이 안된다면 패키지 인식이 안된 것이고 다음 단계를 실행한다.
9. 패키지 인식 방법
$ cd #홈으로 이동
$ nano ~/.bashrc
# ROS1
# echo "ROS1 activated"
source /opt/ros/noetic/setup.bash
source ~/catkin_ws/devel/setup.bash
# ROS2
# echo "ROS2 activated"
# source /opt/os/dashing/setup.bash
ctrl + O 저장 후
ctrl + X nano 나온다.
$ source ~/.bashrc
10. 실행
리눅스 환경에서 terminator 터미널에서 4분할 후 아래 명령어를 터미널 창마다 한개씩 실행한다.
1번 창
$ roscore
2번창
$ rosrun turtlesim turtlesim_node
3번창
$ rosrun hello_world print_turtle_pos.py
4번창 - 터미널 창에 마우스 클릭 후 방향키로 거북이 방향 조절한다.
$ rosrun turtlesim turtle_teleop_key
11. bag and publish
$ cd ~/catkin_ws/src/hello_world
$ mkdir bag
$ cd bag
$ rosbag record -a
12. 생성된 rosbag 파일 확인
파일명.bag.active로 되어있을 경우 ctrl+c로 취소 시킨 후 아래 코드 실행한다.
$ cd ~/catkin_ws/src/hello_world/bag
$ rosbag info 2021-12-04-16-39-54.bag
해당 ~/bag 폴더에서 아래 코드 실행
$ rqt_bag
왼쪽 상단 폴더로 bag 파일을 열어준다.
추가 터미널 alias 세팅
# alias
echo "nb is nano ~/.bashrc"
echo "sb is source ~/.bashrc"
echo "ca is conda activate"
echo "cde is conda deactivate"
echo ""
echo "gs = git status"
echo "gp = git pull"
echo "cw = cd ~/catkin_ws"
echo "cs = cd ~/catkin_ws/src"
echo "cm = cd ~/catkin_ws && catkin_make"
echo ""
echo "robot = ssh ubuntu@192.168.0.45"
echo "slam_gmapping = roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=gmapping"
echo "mapsave = rosrun map_server map_saver -f ~/map"
echo "joystick = roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch"
echo "navigation = roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=$HOME/map.yaml"
echo ""
echo "gazebo_empty_world = roslaunch turtlebot3_gazebo turtlebot3_empty_world.launch"
echo "gazebo_turtle_world = roslaunch turtlebot3_gazebo turtlebot3_world.launch"
echo "gazebo_house = roslaunch turtlebot3_gazebo turtlebot3_house.launch"
echo "gazebo_simulation = roslaunch turtlebot3_gazebo turtlebot3_simulation.launch"
echo "gazebo_rviz = roslaunch turtlebot3_gazebo turtlebot3_gazebo_rviz.launch"
echo "gazebo_autorace_2020 = roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch"
echo ""
echo "fake_turtle_node = roslaunch turtlebot3_fake turtlebot3_fake.launch"
echo ""
echo "camera_int_cali_action = roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch mode:=action"
echo "camera_ext_cali_action = roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch mode:=action"
echo "camera_ext_cali_calib = roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch mode:=calibration"
echo "camera_int_cali = roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch"
echo "camera_ext_cali = roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch"
echo ""
echo "auto_detect_lane = roslaunch turtlebot3_autorace_detect detect_lane.launch"
echo "auto_detect_lane_action = roslaunch turtlebot3_autorace_detect detect_lane.launch mode:=action"
echo "auto_detect_lane_calib = roslaunch turtlebot3_autorace_detect detect_lane.launch mode:=calibration"
echo "auto_race_driving = roslaunch turtlebot3_autorace_driving turtlebot3_autorace_control_lane.launch"
echo ""
echo "autorace_core_mission_traffic_light = roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=traffic_light"
echo "autorace_core_mission_intersection = roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=intersection"
echo "autorace_core_mission_construction = roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=construction"
echo "autorace_core_mission_parking = roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=parking"
echo "autorace_core_mission_level_crossing = roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=level_crossing"
echo "autorace_core_mission_tunnel = roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=tunnel"
alias nb="nano ~/.bashrc"
alias sb="source ~/.bashrc"
alias ca="conda activate"
alias cde="conda deactivate"
alias gs='git status'
alias gp='git pull'
alias cw='cd ~/catkin_ws'
alias cs='cd ~/catkin_ws/src'
alias cm='cd ~/catkin_ws && catkin_make'
alias robot="ssh ubuntu@192.168.0.45"
alias slam_gmapping='roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=gmapping'
alias slam_carto='roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=cartographer'
alias slam_karto='roslaunch turtlebot3_slam turtlebot3_slam.launch slam_methods:=karto'
alias mapsave='rosrun map_server map_saver -f ~/map'
alias joystick='roslaunch turtlebot3_teleop turtlebot3_teleop_key.launch'
alias navigation='roslaunch turtlebot3_navigation turtlebot3_navigation.launch map_file:=$HOME/map.yaml'
alias gazebo_empty_world='roslaunch turtlebot3_gazebo turtlebot3_empty_world.launch'
alias gazebo_turtle_world='roslaunch turtlebot3_gazebo turtlebot3_world.launch'
alias gazebo_house='roslaunch turtlebot3_gazebo turtlebot3_house.launch'
alias gazebo_simulation='roslaunch turtlebot3_gazebo turtlebot3_simulation.launch'
alias gazebo_rviz='roslaunch turtlebot3_gazebo turtlebot3_gazebo_rviz.launch'
alias gazebo_autorace_2020='roslaunch turtlebot3_gazebo turtlebot3_autorace_2020.launch'
alias fake_turtle_node='roslaunch turtlebot3_fake turtlebot3_fake.launch'
alias camera_int_cali='roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch'
alias camera_ext_cali='roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch'
alias camera_int_cali_action='roslaunch turtlebot3_autorace_camera intrinsic_camera_calibration.launch mode:=action'
alias camera_ext_cali_calib='roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch mode:=calibration'
alias camera_ext_cali_action='roslaunch turtlebot3_autorace_camera extrinsic_camera_calibration.launch mode:=action'
alias auto_detect_lane = 'roslaunch turtlebot3_autorace_detect detect_lane.launch'
alias auto_detect_lane_action='roslaunch turtlebot3_autorace_detect detect_lane.launch mode:=action'
alias auto_detect_lane_calib='roslaunch turtlebot3_autorace_detect detect_lane.launch mode:=calibration'
alias auto_detect_lane='roslaunch turtlebot3_autorace_detect detect_lane.launch'
alias auto_race_driving='roslaunch turtlebot3_autorace_driving turtlebot3_autorace_control_lane.launch'
alias autorace_core_mission_traffic_light='roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=traffic_light'
alias autorace_core_mission_intersection='roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=intersection'
alias autorace_core_mission_construction='roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=construction'
alias autorace_core_mission_parking='roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=parking'
alias autorace_core_mission_level_crossing='roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=level_crossing'
alias autorace_core_mission_tunnel='roslaunch turtlebot3_autorace_core turtlebot3_autorace_core.launch mission:=tunnel'
# ROS
export TURTLEBOT3_MODEL=burger
# ROS1
echo "ROS1 activated"
source /opt/ros/noetic/setup.bash
source ~/catkin_ws/devel/setup.bash
# ROS2
# echo "ROS2 activated"
# source /opt/os/dashing/setup.bash
# Arduino PATH
export PATH=$PATH:$HOME/Development/arduino-1.8.16
# kaggle
# GOlang PATH
export PATH=$PATH:/usr/local/go/bin
# ROS 통신 master / host 관계 설정
export ROS_MASTER_URI=http://192.168.0.33:11311
export ROS_HOSTNAME=192.168.0.22
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH