스터디/스터디 정리

20220203 스터디 정리

금잔디명예소방관 2022. 2. 4. 00:50

#1 우분투 명령어 정리

 

-새 디렉토리 생성

 

$ mkdir [디렉토리명]
$ mkdir -p [디렉토리명/디렉토리명/디렉토리명...] : 여러 디렉토리 생성

 

-디렉토리 이동

 

$ cd [디렉토리명] : 디렉토리로 이동

$ cd .. : 부모 디렉토리로 이동

 

-i : 파일 복사 시 동일 파일명이 있을 시에 사용자에게 덮어쓸 것인지를 물어봄
-f : 동일 파일명 발생 시에도 모두 강제적으로 복사함
-p : 원본 파일의 시간 및 소유 권한 보존
-r : 포함된 자식 디렉토리까지 모두 복사

 

-디렉토리 삭제

 

$ rm

 

-f : 디렉토리 안의 파일을 삭제할 때 사용자에게 확인을 요구하지 않음
-r : 인수 list 에서 지정한 디렉토리 혹은 그 아래의 subdirectory를 삭제
-i : whrite permission 이 없는 파일의 삭제를 위해 대화식으로 확인
-p : 디렉토리 dir-name과 비어있는 부모 디렉토리를 사용자가 제거할 수 있으며, 전체 경로명이 삭제되거나 어떤 이유로 인해 경로명의 일부가 남은 것과 무관하게 표준 출력에 메시지가 출력됨
-s -p : 선택항목 지정 시 표준 오류에 출력되는 메시지를 삭제

 

$ rmdir : 디렉토리 삭제

 

-파일 복사

 

$ cp [파일위치 및 파일이름] [목적지 파일위치 및 파일 이름]

 

-파일 이동 (파일 이름을 바꿀 때에도 사용)

 

$ mv [파일위치 및 파일이름] [목적지 파일위치 및 파일 이름]
$ mv [원래 파일 이름] [바꾸고 싶은 파일 이름]

 

-파일 내용 보기

 

$ cat [파일명] : (concatenate)

 

-현재 위치 확인

 

$ pwd : (print working directory)

 

뭐 더많았는데 기억안남 나중에 추가하겠습니다

 

#2 GIT과 우분투 연결

echo "# '내가만든 repository name' " >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin '사이트주소'
git push -u origin main 

 

이 문단 진행하다가 자기인증 하라고 하면 

 

git config --global user.name '아이디'

git config --global user.email '이메일'

 

git remote add origin '사이트주소'
git branch -M main
git push -u origin main

 

이렇게 하고 

마지막 문장 입력하면 

username for 어쩌구저쩌구

password for 어쩌구저쩌구 가 뜨면 정상이라고 한다

 

****************************

진행하다가 git init을 하면

 error: src refspec master does not match any.
error: failed to push some refs to '사이트주소'

 

이렇게 떠서 선생님들 몰래 구글링을 엄청 했지만 하나도 통하지 않았다

그래서 그냥 무시하고 다시 echo부터 시작하고 계속 무시했더니 진행 성공함

아마 다시 해봐야될듯 저장소가 달라서 그렇ㄷ다는데 그게 무슨소리에요

****************************

 

#3 ROS WIKI 튜토리얼 12번 실행하기

 

http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28python%29

 

ROS/Tutorials/WritingPublisherSubscriber(python) - ROS Wiki

Writing the Publisher Node "Node" is the ROS term for an executable that is connected to the ROS network. Here we'll create the publisher ("talker") node which will continually broadcast a message. Change directory into the beginner_tutorials package, you

wiki.ros.org

 

여기 참고해서 그대로 따라하기

아씨 우분투 사진 어케 캡쳐해!!!!!!!!!!!!!!!!!

 

$ cs 

 

~/catkin_ws/src로 들어가는거 까먹지 말자 소스파일로 들어가야함

 

$ catkin_create_pkg py_hello_world rospy std_msgs

 

이걸 실행하면

Created file py_hello_world/package.xml
Created file py_hello_world/CMakeLists.txt
Created folder py_hello_world/src
Successfully created files in /home/mj/catkin_ws/src/py_hello_world. Please adjust the values in package.xml.

 

대충 이렇게 뜸 그럼 package.xml이랑 CMakeLists.txt가 포함된 py_hello_world 파일이 만들어진다

 

$ cd py_hello_world/

 

들어가서 $ls 하면 

 

CMakeLists.txt  package.xml  src

 

이렇게 세개 생김

 

$ mkdir scripts
$ cd scripts

 

스크립트 디렉토리 만들고

만든 디렉토리로 이동

 

여기서 VSC를 열어야 하는데

익숙하게 $ code 를 치면 굳이 VSC안에 들어가서 또 디렉토리를 들어가야됨

그러느니 $ code . 를 쳐서 현재 위치에서 VSC 오픈해주자

 

   1 #!/usr/bin/env python
   2 # license removed for brevity
   3 import rospy
   4 from std_msgs.msg import String
   5 
   6 def talker():
   7     pub = rospy.Publisher('chatter', String, queue_size=10)
   8     rospy.init_node('talker', anonymous=True)
   9     rate = rospy.Rate(10) # 10hz
  10     while not rospy.is_shutdown():
  11         hello_str = "hello world %s" % rospy.get_time()
  12         rospy.loginfo(hello_str)
  13         pub.publish(hello_str)
  14         rate.sleep()
  15 
  16 if __name__ == '__main__':
  17     try:
  18         talker()
  19     except rospy.ROSInterruptException:
  20         pass

이거..복붇해주자

하나하나 해석하긴해야되는데 지금은 졸리니까 내일하겠습니다

..

욕안하고싶은데 방금 우분투에서 사진 꺼내다가 통째로 날아감 아놔

다시 시작하겠습니다.. 담배가져와

 

자 어쨋든 저거까지 하고 나오면 $ ls 하면 스크립트 안에 talker.py가 흰색글씨로 존재함을 보인다

여기서 executable 하게 하려면 

 

$ chmod +x talker.py

 

쳐주면 초록색이 되면서 실행가능하게 된다 ㅎㅎ

 

listener.py도 만들어줍시다

 

   1 #!/usr/bin/env python
   2 import rospy
   3 from std_msgs.msg import String
   4 
   5 def callback(data):
   6     rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data)
   7     
   8 def listener():
   9 
  10     # In ROS, nodes are uniquely named. If two nodes with the same
  11     # name are launched, the previous one is kicked off. The
  12     # anonymous=True flag means that rospy will choose a unique
  13     # name for our 'listener' node so that multiple listeners can
  14     # run simultaneously.
  15     rospy.init_node('listener', anonymous=True)
  16 
  17     rospy.Subscriber("chatter", String, callback)
  18 
  19     # spin() simply keeps python from exiting until this node is stopped
  20     rospy.spin()
  21 
  22 if __name__ == '__main__':
  23     listener()

 

주석 다빼고 알아서 넣으세요

아무튼

위에 executable하게 만드는 과정까지 똑같이 해준다

그럼 스크립트 파일 안에 토커랑 리스너 파이썬 파일이 실행가능해진다

 

시작하기전에 

$ cm 

해준다 이유는 나도 몰라 선생님이 하라고 하셨어 다음에 조사해올게요

 

그렇게 하면


Base path: /home/mj/catkin_ws
Source space: /home/mj/catkin_ws/src
Build space: /home/mj/catkin_ws/build
Devel space: /home/mj/catkin_ws/devel
Install space: /home/mj/catkin_ws/install
####
#### Running command: "cmake /home/mj/catkin_ws/src -DCATKIN_DEVEL_PREFIX=/home/mj/catkin_ws/devel -DCMAKE_INSTALL_PREFIX=/home/mj/catkin_ws/install -G Unix Makefiles" in "/home/mj/catkin_ws/build"
####
-- Using CATKIN_DEVEL_PREFIX: /home/mj/catkin_ws/devel
-- Using CMAKE_PREFIX_PATH: /home/mj/catkin_ws/devel;/opt/ros/melodic
-- This workspace overlays: /home/mj/catkin_ws/devel;/opt/ros/melodic
-- Found PythonInterp: /usr/bin/python2 (found suitable version "2.7.17", minimum required is "2") 
-- Using PYTHON_EXECUTABLE: /usr/bin/python2
-- Using Debian Python package layout
-- Using empy: /usr/bin/empy
-- Using CATKIN_ENABLE_TESTING: ON
-- Call enable_testing()
-- Using CATKIN_TEST_RESULTS_DIR: /home/mj/catkin_ws/build/test_results
-- Found gtest sources under '/usr/src/googletest': gtests will be built
-- Found gmock sources under '/usr/src/googletest': gmock will be built
-- Found PythonInterp: /usr/bin/python2 (found version "2.7.17") 
-- Using Python nosetests: /usr/bin/nosetests-2.7
-- catkin 0.7.29
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~  traversing 1 packages in topological order:
-- ~~  - py_hello_world
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'py_hello_world'
-- ==> add_subdirectory(py_hello_world)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mj/catkin_ws/build
####
#### Running command: "make -j2 -l2" in "/home/mj/catkin_ws/build"
####

 

이렇게 뜬다!

패스

 

자 그럼 이제 터미널 창 세개를 띄워서

첫번째 터미널 창에 $ roscore 

두번째 터미널 창에 $ rosrun py_hello_world talker.py 쳐놓기만 하고

세번째 터미널 창에 $ rosrun py_hello_world listener.py 치면

이제 두번째 세번째 순서대로 실행한다

그래프로 보고싶으면 터미널 창을 하나 더띄워서 $ rqt_graph

 

과제는 이걸 C++로 실행시키는거................

나 우째