일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- 환경설정
- mariaDB
- 오늘도 우라라 펫 공략
- MSG
- C++
- Subscribe
- LeetCode
- ubuntu
- JungOl
- C언어
- 그랑사가
- Linux
- 오늘도 우라라
- 반복문
- 마리아 DB
- 오늘도 우라라 공략
- ros
- 리눅스
- install opencv-4.4.0 on ubuntu 22.04
- mysql
- 오늘도 우라라 펫
- 우분투
- publish
- 등차수열
- topic
- while
- 토픽
- 기초
- 데이터 베이스
- 프로그래밍
- Today
- Total
하루의 쉼터
[ROS] ros::NodeHandle::advertise()에 관하여 본문
| ros::NodeHandle::advertise()에 관하여
읽기전에 Publish가 무엇인지 모른다면?
2019.09.16 - [프로그래밍 - 정의/ROS] - [ROS] ROS 용어 정리
[ROS] ROS 용어 정리
l ROS 기본 용어 정리 ROS란? Robot Operating System 의 약자로 로봇의 응용프로그램을 개발 하기 위한 운영체제와 같은 로봇 소프트웨어 플랫폼으로 제어, 센서, 인식, 메시지 파킹, 개발환경, 패키지관
changun516.tistory.com
0. 서론
ROS를 사용하는 경우, publish가 자주 사용되며 아래와 같은 코드를 많이 볼 수 있다.
ros::Publisher pub = nohandle.advertise<std_msgs::Empty>("my_topic", 1);
이는 ros wiki에도 Publishers and Subscribers 파트에도 나와있다.
그럼 이 코드 문장이 뜻하는 바를 자세히 알아보자.
이 글에서는 ROS WIKI - Publisher and Subscribers를 참고하여 조사해본다.
1. What is ros::NodeHandle::advertise?
서론에 나온 코드를 ROS WIKI, docs,ros.org 등을 참고하여 보면 아래와 같이 볼 수 있다.
template<class M>
ros::Publisher advertise(const std::string& topic, uint32_t queue_size, bool latch = false);
1.1 template<class M>
template<class M> | Topic Publish 할때 메시지 유형을 지정하는 템플릿 인수 |
이를 통해 매칭하여 보면 아래 그림과 같다.
1.2 반환형
Return Type | ros::Publisher |
advertise에서 빈 ros::Publisher를 반환하는 경우는 드물지만 존재하며 이에 대한 판단은 조건문을 사용하여 확인 가능하다.
예제 :
if(!pub){
...
}
else{
}
1.3 매개변수
const std::string& topic | 퍼블리쉬 할 토픽 이름 |
uint32_t queue_size | 퍼블리쉬 메시지 대기열의 크기, 오래된 메세지 부터 삭제 |
bool latch | 대기열에서 마지막 메세지 데이터를 전송 여부 |
* uint32_t queue_size 관련
* 참고
2021.07.22 - [프로그래밍 - 개발/ROS] - [ROS] Publishers and Subscribers Queue 에 관하여
[ROS] Publishers and Subscribers Queue 에 관하여
| Publisher, Subscriber Queue 에 관하여 0. 서론 ROS 개발을 하다보면 Publishers 와 Subscribers를 자주 사용하게 된다. ros::Publisher pub = nodehandler.advertise ("topic_name", 5); ros::Subscriber..
changun516.tistory.com
* bool latch 기본 값 : false
정적 데이터에서 추천
2. Overload
그렇다면 advertise에서 다른 형식으로 Overload하여 사용 하는 경우는 없는 지, latch처럼 기본값을 가지는 매개변수가 있는지 궁금할 것이다.
Reference Site 참고결과
Publisher ros::NodeHandle::advertise(AdvertiseOptions & ops)
AdvertiseOptions의 전체 범위를 사용하여 advertise를 함.
* http://docs.ros.org/en/diamondback/api/roscpp/html/structros_1_1AdvertiseOptions.html
roscpp: ros::AdvertiseOptions Struct Reference
ros::AdvertiseOptions Struct Reference Encapsulates all options available for creating a Publisher. More... #include List of all members. Public Member Functions AdvertiseOptions (const std::string &_topic, uint32_t _queue_size, const std::string &_md5su
docs.ros.org
template<class M >
Publisher ros::NodeHandle::advertise(const std::string & topic,
uint32_t queue_size,bool latch = false)
가장 일반적으로 사용하는 advertise
template<class M >
Publisher ros::NodeHandle::advertise(const std::string & topic,uint32_t queue_size,
const SubscriberStatusCallback & connect_cb,
const SubscriberStatusCallback & disconnect_cb = SubscriberStatusCallback(),
const VoidConstPtr & tracked_object = VoidConstPtr(),
bool latch = false)
Subscribe에서 연결 및 연결 해제 될 때 관련된 데이터 및 처리를 위해서 사용
const std::string& topic | 퍼블리쉬 할 토픽 이름 |
uint32_t queue_size | 퍼블리쉬 메시지 대기열의 크기, 오래된 메세지 부터 삭제 |
const SubscriberStatusCallback & connect_cb | Subscribe에서 연결 되는 경우 호출 |
const SubscriberStatusCallback & disconnect_cb | Subscribe에서 연결 해제 되는 경우 호출 |
const VoidConstPtr & tracked_objec | 콜백을 추적할 공유 포인터, 개체에 대한 추적 및 참고가 필요할 때 사용 |
bool latch | 대기열에서 마지막 메세지 데이터를 전송 여부 |
* Reference Site
http://wiki.ros.org/roscpp/Overview/Publishers%20and%20Subscribers
roscpp/Overview/Publishers and Subscribers - ROS Wiki
Publishing to a Topic See also: ros::NodeHandle::advertise() API docs, ros::Publisher API docs, ros::NodeHandle API docs Creating a handle to publish messages to a topic is done using the ros::NodeHandle class, which is covered in more detail in the NodeHa
wiki.ros.org
roscpp: ros::NodeHandle Class Reference
roscpp's interface for creating subscribers, publishers, etc. More... #include Publisher advertise (AdvertiseOptions &ops) template Publisher advertise (const std::string &topic, uint32_t queue_size, bool latch=false) Advertise a topic, simple versi
docs.ros.org
http://wiki.ros.org/rospy/Overview/Publishers%20and%20Subscribers#Choosing_a_good_queue_size
rospy/Overview/Publishers and Subscribers - ROS Wiki
Publishing to a topic See also: rospy.Publisher Code API You can create a handle to publish messages to a topic using the rospy.Publisher class. The most common usage for this is to provide the name of the topic and the message class/type of the topic. You
wiki.ros.org
http://docs.ros.org/en/diamondback/api/roscpp/html/structros_1_1AdvertiseOptions.html
roscpp: ros::AdvertiseOptions Struct Reference
ros::AdvertiseOptions Struct Reference Encapsulates all options available for creating a Publisher. More... #include List of all members. Public Member Functions AdvertiseOptions (const std::string &_topic, uint32_t _queue_size, const std::string &_md5su
docs.ros.org