- Find the IP address of your virtual machine (VM) by running ifconfig or ip addr in the terminal. Your VM's IP address will be listed under eth0.
- Ping your VM from the host machine (where MATLAB is installed) by running the following command in the host's terminal: $ ping <VM_IP_address>.
- If you are unable to ping your VM, try changing the Network Adapter setting to "NAT Adapter" or "Bridge Adapter." Repeat the steps until you can successfully ping the VM.
- Try connecting to the VM from your host via SSH by running the command in host terminal: $ ssh username@<VM_IP_address>
- Once connected, try using ros2device with the same VM IP address.
How can I connect MATLAB on Windows to ROS2 on VirtualBox Ubuntu?
조회 수: 15 (최근 30일)
이전 댓글 표시
Hello!
I am trying to connect MATLAB/Simulink to my ROS2 Humble simulations which I am running on Ubuntu 22.04 with VirtualBox. I have looked at almost all resources / videos / exchange answers regarding this topic but none seem to work for me. One of the things I tried to do is rosinit with Ubuntu's IP address, but I receive this error: "The value of the ROS_IP environment variable, Windows_PC_IP, is an invalid IP address. Check the IP for correctness." I am not sure how to fix this. Using ros2device gives another error: "Error using ros.codertarget.internal.ssh2client. Error connecting to SSH server at (IP address)." I have ssh installed on Ubunutu, so I am not exactly sure where the issue is.
Does anyone know of a simple way to do this? Is it even possible / worth it? I am trying to create a control system for a robotic arm, and I was hoping to use Simulink for this, which is why I am trying to go on this journey.
댓글 수: 1
Abhishek
2025년 3월 4일
편집: Abhishek
2025년 3월 4일
rosinit won't work for ROS 2, as it is used to launch a global node for ROS 1 and is not required for ROS 2.
To address the issue with ros2device:
Also, try creating a ROS 2 node in your VM with publisher/subscriber and check if you are able to see node/topics in MATLAB.
In the VM, run the following commands in terminal to publish a message to '/chatter' topic:
$ source /opt/ros/jazzy/setup.bash
$ export ROS_DOMAIN_ID=0
$ ros2 topic pub /chatter std_msgs/msg/String "{data: 'Hello, ROS 2'}" -r 1
In MATLAB, execute the following command in the MATLAB command window:
ros2 topic list
Verify that the /chatter topic is available in the output list. This will ensure that communication is working properly.
답변 (1개)
aditi bagora
2025년 3월 4일
Hi Jasmine,
I understand that you are trying to connect MATLAB/Simulink to my ROS2 Humble simulations on Ubuntu 22.04 with VirtualBox. The error clearly states that there is an issue when connecting using the IP you are providing.To help resolve this, please follow these troubleshooting steps:
- Ensure that the network adapter for your Ubuntu VM is set to "Bridged Adapter" or "NAT Network" if you need your VM to communicate with the host machine. This allows your VM to be on the same network as your host.
- Find the IP address of your Ubuntu VM by running ifconfig or ip addr in the terminal. Use this IP address for rosinit.
- Ensure that on your Ubuntu VM, set the ROS 2 environment variables correctly.
- From your host machine, try connecting to the Ubuntu VM via SSH using a terminal (ssh <username>@<Ubuntu_VM_IP>) to ensure connectivity. If you face issues, check the firewall settings on your Ubuntu VM and ensure port 22 is open.
- Ensure that the MATLAB version you are using is compatible with ROS 2 Humble. Refer to the MathWorks' documentation for the supported ROS 2 distributions: ROS Toolbox System Requirements.
Hope this helps in resolving the issue.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!