Create ROS topics and nodes in Simulink

4 Ansichten (letzte 30 Tage)
Silvia Della Torre
Silvia Della Torre am 29 Sep. 2023
Beantwortet: Anurag am 25 Okt. 2023
Hello,
I'm trying to create a Simulink model using the ROS network. My PC is the master of the network, and there is also a remote device: a Raspberry Pi 4. A USB3 camera is connected to Raspberry Pi4, it works with its own drivers. What I've done since now is the following: on the Raspberry I run a file named camera.launch (included in the drivers package), it creates nodes and topics for the camera. Using the subscriber block in Simulink I subscribe one of the topics created to exctrat the image, also using ros read image block and viewer block to display the image. Then I process the image with a blob detection. What I would like to do next is publish the image processed to the ROS network. To do this I use the publisher block. The problem is how can I create a new topic and node if needded, to send the image processed to? Is it possible to this in Simulink?
Also, during the simulation time the video viewer shows a video and not a single image. How can I obtain a single image from ros read image or the viewer video? I see in the latter one there is a snapshot key but how can I do this automatically within press that key?
Thank you
Silvia

Antworten (1)

Anurag
Anurag am 25 Okt. 2023
Hi Silvia,
I understand that you want to publish the processed image back to the ROS Network, and capture and publish single images, possibly by utilizing the "snapshot key" feature within the viewer block.
To create a new topic and node for publishing please follow the below steps:
  • In Simulink, you can use the "Publisher" block to send messages to a ROS topic. Add a new "Publisher" block to your model.
  • In the "Publisher" block parameters, you can specify the topic name and message type. To create a new topic, provide a unique topic name.
  • You can create a new node to manage the publishing. In Simulink, you can do this in the "Model Configuration Parameters" by specifying a new node name under the "Node name" parameter.
  • Connect the output of your image processing block to the input of the "Publisher" block. This way, the processed image will be sent to the specified ROS topic.
To capture a single image from the video feed please follow the below steps:
  1. In Simulink, add a "Trigger" block to your model.
  2. Configure the Trigger block to trigger at a specific time or condition.
  3. Add a "Switch" block to your model. Connect the "Switch" block to the output of the "Trigger" block and to the "rosread" block. The "Switch" block can be used to control the flow of data based on the trigger signal.
  4. When the "Trigger" block triggers, it will allow data to flow from the "rosread" block to the "Publisher" block, effectively capturing and publishing a single image.
For more information on the “Publisher”, “Trigger”, “Switch” and “rosread” blocks, please refer to the following documentation links:
  1. Publisher: https://in.mathworks.com/help/ros/ref/publish.html
  2. Trigger: https://in.mathworks.com/help/simulink/ug/triggered-subsystems.html
  3. Switch: https://in.mathworks.com/help/simulink/slref/switch.html
  4. rosread: https://in.mathworks.com/help/ros/ref/readscanblock.html
Hope this helped.
Regards,
Anurag

Kategorien

Mehr zu Publishers and Subscribers finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by