스터디/스터디 과제

1. Writing a Simple Publisher and Subscriber (C++)

금잔디명예소방관 2022. 2. 8. 15:05

http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29

 

ROS/Tutorials/WritingPublisherSubscriber(c++) - 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 a publisher ("talker") node which will continually broadcast a message. Change directory into the beginner_tutorials package, you cr

wiki.ros.org

 

이걸보고 실행시켜오는게 과제

 

지난번 수업때 파이썬 과제를 열심히 보고 대부분 따라했다

 

~$ cs

 

$ catkin_create_pkg cpp_hello_world rospy std_msgs

 

$ cd cpp_hello_world/

 

$ ls

 

하면 아래에 cmake include pkg src 이렇게 네개가 뜸

 

$ mkdir scripts

 

$ cd scripts

 

스크립트 디렉토리를 들어가서 vsc를 열어 talker.cpp 와 listener.cpp 파일을 만들고 링크에서 복사한다

 

$ chmod +x talker.cpp

$ chmod +x listener.cpp

 

까먹지말기

 

그리고 cmake 파일에 들어가서 

 

https://www.youtube.com/watch?v=vtoJg7LbxJI 

이 영상처럼 고치기만 했는데...........................

 

터미널 네개를 켜서 파이썬 파일과 똑같이 실행했는데 토커와 리스너가 진행되지 않았다

$ cm 을 했는데 cm 까지는 무사히 떳으나

토커 리스너 실행을 실패하고 원래 터미널로 돌아오니까

 

CMake Error at cpp_hello_world/CMakeLists.txt:16 (add_executable):
  Cannot find source file:

    src/listener.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx


CMake Error at cpp_hello_world/CMakeLists.txt:13 (add_executable):
  Cannot find source file:

    src/talker.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx


CMake Error: CMake can not determine linker language for target: listener
CMake Error: Cannot determine link language for target "listener".
CMake Error: CMake can not determine linker language for target: talker
CMake Error: Cannot determine link language for target "talker".
-- Generating done
-- Build files have been written to: /home/mj/catkin_ws/build
Invoking "cmake" failed

 

으아악

 

 

-------------------------------------------------------------------------------------------------------------------------

220210

 

 

 

성공~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

원인은 rospy pkg를 깐거랑

뜬금없는 rosrun할때 확장자 이름을 적은게 문제였다 

전체적으로 정리를 하면

 

$ cs

$ catkin_create_pkg cpp_hello_world roscpp std_msgs

 

$ cd cpp_hello_world

$ cd src

 

여기서 vsc켜서 토커 리스너 각자 복붙하기

 

$ chmod +x talker.cpp

$ chmod +x listener.cpp

 

저 유투브아저씨 참고해서 cmakelist.txt 편집

 

$ cm

 

이러면 거의 완료

 

터미널 네개켜서

하나는 roscore

두개는 $ cs 해서 

$ rosrun cpp_hello_world talker.cpp

$ rosrun cpp_hello_world listener.cpp

 

여기서 .cpp가 문제였다

이거 ㅇ지우자마자 잘됨 아아아아아ㅏㄱ~~~~~~~~~~~~~~!

 

그리고 다른 한 터미널에서 rqt_graph 하면

위에 사진처럼 성공이다

 

힘드네...