send
설명
예제
ROS 메시지를 만들고 보내고 받기
ROS 네트워크에서 메시지를 보내고 받을 publisher와 subscriber를 설정합니다.
ROS 네트워크에 연결합니다.
rosinit
Launching ROS Core... Done in 0.77453 seconds. Initializing ROS master on http://172.29.217.125:56013. Initializing global node /matlab_global_node_49233 with NodeURI http://dcc934856glnxa64:42035/ and MasterURI http://localhost:56013.
특정 토픽과 메시지 유형을 가진 publisher를 만듭니다. 이 publisher를 사용하여 보낼 디폴트 메시지를 반환할 수도 있습니다.
[pub,msg] = rospublisher('position','geometry_msgs/Point');
네트워크를 통해 보내기 전에 메시지를 수정합니다.
msg.X = 1; msg.Y = 2; send(pub,msg);
subscriber를 만들고 최신 메시지를 기다립니다. 보낸 메시지가 맞는지 확인합니다.
sub = rossubscriber('position')
sub = Subscriber with properties: TopicName: '/position' LatestMessage: [1x1 Point] MessageType: 'geometry_msgs/Point' BufferSize: 1 MessagePreprocessingEnabled: 0 NewMessageFcn: [] DataFormat: 'object'
pause(1); sub.LatestMessage
ans = ROS Point message with properties: MessageType: 'geometry_msgs/Point' X: 1 Y: 2 Z: 0 Use showdetails to show the contents of the message
ROS 네트워크를 종료합니다.
rosshutdown
Shutting down global node /matlab_global_node_49233 with NodeURI http://dcc934856glnxa64:42035/ and MasterURI http://localhost:56013. Shutting down ROS master on http://172.29.217.125:56013.
입력 인수
pub
— ROS publisher
Publisher
객체 핸들
ROS publisher로, Publisher
객체 핸들로 지정됩니다. rospublisher
를 사용하여 객체를 만들 수 있습니다.
msg
— ROS 메시지
Message
객체 핸들 | 구조체
ROS 메시지로, Message
객체 핸들 또는 구조체로 지정됩니다. rosmessage
를 사용하여 객체를 만들 수 있습니다.
참고
향후 릴리스에서 ROS Toolbox는 ROS 메시지에 대해 객체 대신 메시지 구조체를 사용할 예정입니다.
지금 메시지 구조체를 사용하려면 "DataFormat"
이름-값 인수를 "struct"
로 설정합니다. 자세한 내용은 ROS 메시지 구조체 항목을 참조하십시오.
확장 기능
C/C++ 코드 생성
MATLAB® Coder™를 사용하여 C 코드나 C++ 코드를 생성할 수 있습니다.
사용법 관련 참고 사항 및 제한 사항:
struct
메시지에 대해서만 지원됩니다.
버전 내역
R2019b에 개발됨R2021a: ROS 메시지 구조체
이제 메시지를 메시지 객체 속성과 일치하는 필드를 포함하는 구조체로 만들 수 있습니다. 구조체를 사용하면 일반적으로 ROS 메시지를 만들고, 업데이트하고, 사용하는 것이 훨씬 수월해지지만, 설정을 마친 메시지 필드에 대해서는 더 이상 유효성 검사가 이루어지지 않습니다. 구조체의 메시지 유형 및 대응하는 필드 값은 네트워크를 통해 전송될 때 유효성 검사가 이루어집니다.
ROS 메시지를 구조체로 사용하려면, publisher, subscriber 또는 기타 ROS 객체를 만들 때 "DataFormat"
이름-값 인수를 사용합니다. 이러한 객체에서 만들어진 모든 메시지는 구조체를 사용합니다.
pub = rospublisher("/scan","sensor_msgs/LaserScan","DataFormat","struct") msg = rosmessage(pub)
메시지를 구조체로 직접 만들 수도 있지만 publisher, subscriber 또는 기타 ROS 객체에 대한 데이터형을 "struct"
로 지정해야 합니다. ROS 객체는 여전히 메시지 객체를 기본적으로 사용합니다.
msg = rosmessage("/scan","sensor_msgs/LaserScan","DataFormat","struct") ... pub = rospublisher("/scan","sensor_msgs/LaserScan","DataFormat","struct")
향후 릴리스에서 ROS 메시지는 기본적으로 구조체를 사용하고 ROS 메시지 객체는 제거될 예정입니다.
자세한 내용은 Improve Performance of ROS Using Message Structures 항목을 참조하십시오.
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 MATLAB 명령을 지원하지 않습니다.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)