ROS와 Matlab(2017b) 연동하기

2019. 7. 18. 16:21Robotics SW/ROS

Interfacing MATLAB and ROS.pdf
0.91MB

연구를 위해 Matlab의 기능과 ROS를 연동해야 하는 경우가 있어 찾아보니 이미 Matlab에서 훌륭하게 관련 기능이 지원되고 있어 여기 정리한다. 첨부된 것은 Mathworks에서 공식적으로 2014년에 발표된 자료로 이를 활용하면 Matlab과 ROS를 연동해 사용하는 것이 가능하다. 사용법은 정말 간단했다. Matlab내에서 ros node연결을 위한 명령어와 종료를 위한 명령어만 숙지하면 된다.

  • "rosinit" 명령어: Matlab내에서 ROS node 실행
    • 이 때, 이미 실행 중인 roscore가 있으면 해단 roscore에 연결이 되고, 실행 중인 roscore가 없을 경우, 새로 roscore를 띄운다.
  • "rosshutdown" 명령어: session 종료

마지막으로 본 글 마지막에 Mathworks에서 제공하는 Webinar와 Youtube 동영상 Link를 넣었으니 참고하면 좋을듯 하다.

[관련 Links]

https://kr.mathworks.com/help/robotics/examples/get-started-with-ros.html

 

Get Started with ROS - MATLAB & Simulink - MathWorks 한국

아래 MATLAB 명령에 해당하는 링크를 클릭하셨습니다. 이 명령을 MATLAB 명령 창에 입력해 실행하십시오. 웹 브라우저에서는 MATLAB 명령을 지원하지 않습니다.

kr.mathworks.com

[아래 내용은 위 페이지에서 발췌한 기본 ROS 연동 방법]

  • 자세한 사용방법은 위 링크 참고

Initialize ROS Network

Use rosinit to initialize ROS. By default, rosinit creates a ROS master in MATLAB and starts a "global node" that is connected to the master. The "global node" is automatically used by other ROS functions.

rosinit

Initializing ROS master on http://bat800207glnxa64:36681/. Initializing global node /matlab_global_node_61183 with NodeURI http://bat800207glnxa64:39841/

Use rosnode list to see all nodes in the ROS network. Note that the only available node is the global node created by rosinit.

rosnode list

/matlab_global_node_61183

Use exampleHelperROSCreateSampleNetwork to populate the ROS network with three additional nodes and sample publishers and subscribers.

exampleHelperROSCreateSampleNetwork

Use rosnode list again, and observe that there are three new nodes (node_1, node_2 and node_3).

rosnode list

/matlab_global_node_61183 /node_1 /node_2 /node_3

A visual representation of the current state of the ROS network is shown below. Use it as a reference when you explore this sample network in the remainder of the example.

The MATLAB global node is disconnected since it currently does not have any publishers, subscribers or services.

Topics

Use rostopic list to see available topics in the ROS network. Observe that there are three active topics: /pose, /rosout, and /scan. rosout is a default logging topic that is always present in the ROS network. The other two topics were created as part of the sample network.

rostopic list

/pose /rosout /scan

Use rostopic info to get specific information about a specific topic. The command below shows that /node_1 publishes (sends messages to) the /pose topic, and /node_2 subscribes (receives messages from) that topic (see Exchange Data with ROS Publishers and Subscribers for more information).

rostopic info /pose

Type: geometry_msgs/Twist Publishers: * /node_1 (http://bat800207glnxa64:45189/) Subscribers: * /node_2 (http://bat800207glnxa64:35097/)

Use rosnode info to get information about a specific node. The command below show that node_1 publishes to /pose and /rosout topics, and subscribes to the /scan topic.

rosnode info /node_1

Node: [/node_1] URI: [http://bat800207glnxa64:45189/] Publications (2 Active Topics): * /pose * /rosout Subscriptions (1 Active Topics): * /scan Services (0 Active):

Services

ROS Services provide a mechanism for "procedure calls" across the ROS network. A service client sends a request message to a service server, which processes the information in the request and returns with a response message (see Call and Provide ROS Services).

Use rosservice list to see all available service servers in the ROS network. The command below shows that two services (/add and /reply) are available.

rosservice list

/add /reply

Use rosservice info to get information about a specific service.

rosservice info /add

Node: /node_3 URI: rosrpc://bat800207glnxa64:34777/ Type: roscpp_tutorials/TwoInts Args: A B

Messages

Publishers, subscribers, and services use ROS messages to exchange information. Each ROS message has an associated message type that defines the datatypes and layout of information in that message (See Work with Basic ROS Messages).

Use rostopic type to see the message type used by a topic. The command below shows that the /pose topic uses messages of type geometry_msgs/Twist.

rostopic type /pose

geometry_msgs/Twist

Use rosmsg show to view the properties of a message type. The geometry_msgs/Twist message type has two properties, Linear and Angular. Each property is a message of type geometry_msgs/Vector3, which in turn has three properties of type double.

rosmsg show geometry_msgs/Twist

% This expresses velocity in free space broken into its Linear and Angular parts. Vector3 Linear Vector3 Angular

rosmsg show geometry_msgs/Vector3

% This represents a vector in free space. double X double Y double Z

Use rosmsg list to see the full list of message types available in MATLAB.

Shut Down ROS Network

Use exampleHelperROSShutDownSampleNetwork to remove the sample nodes, publishers, and subscribers from the ROS network. This command is only needed if the sample network was created earlier using exampleHelperROSStartSampleNetwork.

exampleHelperROSShutDownSampleNetwork

Use rosshutdown to shut down the ROS network in MATLAB. This shuts down the ROS master that was started by rosinit and deletes the global node. It is recommended to use rosshutdown once you are done working with the ROS network.

rosshutdown

Shutting down global node /matlab_global_node_61183 with NodeURI http://bat800207glnxa64:39841/ Shutting down ROS master on http://bat800207glnxa64:36681/.

[Webinar & Video Demo]

https://kr.mathworks.com/videos/matlab-and-simulink-robotics-arena-getting-started-with-matlab-and-ros-1508263034047.html

 

Getting Started with MATLAB and ROS Video

Join Sebastian Castro and Pulkit Kapur as they show how Robotics System Toolbox can help you connect MATLAB and the Robot Operating System (ROS).

kr.mathworks.com