Configuration of ROS Toolbox through CLI?

조회 수: 3 (최근 30일)
Sönke
Sönke 2024년 12월 11일
댓글: Divyam 2025년 1월 9일
Hello everyone,
my main question is in the title. For reference, I want to create a docker container running matlab to generate some standalone ROS2 nodes. This works fine until I have to set the path to the Python-executable. It seems to be only possible through the GUI. Am I mistaken here and is there maybe a way to set the executable and create the venv via CLI commands?
Best regards,
Sönke

답변 (1개)

Divyam
Divyam 2025년 1월 7일
Hi @Sönke,
If you wish to set the python environment for MATLAB sessions, you can start MATLAB in CLI mode and then use the "pyenv" function to select and load a Python interpreter.
% System Command
matlab -nodisplay -r "command"
% MATLAB Command
pyenv('Version', '<path-to-python>');
Alternatively, you could also use the "system" function to execute shell commands and create a virtual environment with the specific Python interpreter.
% Create a virtual environment
system('python -m venv <path-to-venv>');
% Activate the virtual environment
system('source <path-to-venv-bin-activate>');
To automate this process, the following Dockerfile template can be followed:
FROM <matlab version>
# Install Python and other dependencies
RUN <apt-get and apt-install>
# Copy your MATLAB script into the container
COPY your_script.m <path-to-your-script>
# Set the entrypoint to run MATLAB with your script
ENTRYPOINT ["matlab", "-nodisplay", "-r", "your_script"]
For more information regarding the "pyenv" function, refer to this documentation: https://www.mathworks.com/help/matlab/ref/pyenv.html
For more information regarding the "system" function, refer to this documentation: https://www.mathworks.com/help/ros/ref/system.html
  댓글 수: 2
Sönke
Sönke 2025년 1월 9일
편집: Sönke 2025년 1월 9일
Hello Divyam,
thanks for spending some time with my problem.
If I am not mistaken, there is a difference between the main python executable setting and the setting for the ROS Toolbox, where the python executable has to be set again. For the latter I cannot find a way to set the options through CLI.
Preference -> ROS Toolbox -> "Open ROS Toolbox Preferences" -> ROS System Requirements (python environment)
Divyam
Divyam 2025년 1월 9일
Hi @Sönke, you can set the python executable for ROS2 using the "pyenv" function as I mentioned before. Feel free to comment on this answer if you still face issues with using the "pyenv" function to set the python environment for ROS2.
Note: Since you are using ROS2 ensure that the python version is >= 3.7

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Publishers and Subscribers에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by