How can I use a custom ROS service type?

4 views (last 30 days)
ryuhhh
ryuhhh on 28 Mar 2023
Commented: Ayush on 3 Apr 2023
Hi,
I am working on linux/ROS/Simulink enviroment.
I am trying to implement the communication between my python program and a simulink model using ROS Service.
For this, I made a service package and build was done successfully. But, I cannot find my service type in the blank message block.
Class is chosen as Service Request.
How can I add my service type to the type list of the blank message block?
Thanks.
  1 Comment
Ayush
Ayush on 3 Apr 2023
To add your custom ROS service type to the type list of the blank message block in Simulink, you need to follow these steps:
  • In your ROS package directory, navigate to the "srv" folder where your custom service definition files are located.
  • Compile your service definition file
  • Source your ROS environment by running the following command:
$ source ~/catkin_ws/devel/setup.bash
  1. In Simulink, open the "Message" library browser by clicking on the "Library Browser" button in the Simulink toolbar, and then selecting "Simulink Libraries" -> "Simulink" -> "Commonly Used Blocks" -> "Signal Routing" -> "Message".
  2. In the Message library browser, locate the "Blank Message" block and drag it into your Simulink model.
  3. Double-click on the "Blank Message" block to open the block parameters dialog box.
  4. In the "Data type" field, click on the "..." button to open the "Data Type Assistant" dialog box.
  5. In the "Data Type Assistant" dialog box, select "ROS Toolbox" as the "Source" and "Service Request" as the "Class".
  6. In the "Service name" field, type the name of your custom ROS service.
  7. Click on the "OK" button to close the "Data Type Assistant" dialog box.
  8. Click on the "Apply" button to save the changes to the "Blank Message" block.
  9. Your custom ROS service type should now be available in the type list of the "Blank Message" block. Select your custom ROS service type from the list and click on the "OK" button to close the block parameters dialog box.
  10. You can now use the "Blank Message" block with your custom ROS service type in your Simulink model.

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!