Generate and Deploy ROS 2 Nodes for Automated Parking Valet in Simulink
After simulating the ROS 2 nodes to verify all the components of the automated parking valet system as described in Simulate Automated Parking Valet with ROS 2 in Simulink, you can now generate code for those ROS 2 nodes and deploy them. Variant subsystem under each node will use publish and subscribe blocks to replace input and output ports.
Generate and deploy Behavioral Planner
, Path Planner
and Controller
node applications using exampleHelperROS2ValetDeployNodes
helper function. The helper function calls slbuild
(Simulink) command with the name of the Simulink model as input argument, for each model, to generate C++ code and deploy the application on the host computer.
Recent change in GNU may result in a compilation error for ROS2ValetPathPlannerExample model. If you encounter any compilation issues, follow these steps to update the model:
Open the
ROS2ValetPathPlannerExample.slx
model.Under the Modeling tab, click Model Settings.
In the Simulation Target panel, navigate to Code information > Linker flags.
Add
-Wl,--no-as-needed
. ClickOk
to apply the change.
exampleHelperROSValetLoadLocalizationData;
exampleHelperROS2ValetDeployNodes(); % generate C++ code and deploy the application for ROS 2 nodes
### Starting build procedure for: ROS2ValetBehavioralPlannerExample ### Generating code and artifacts to 'Model specific' folder structure ### Generating code into build folder: C:\Users\avijayar\OneDrive - MathWorks\Documents\MATLAB\ExampleManager\avijayar.myBdoc23a\ros-ex41987970\ROS2ValetBehavioralPlannerExample_ert_rtw ### Invoking Target Language Compiler on ROS2ValetBehavioralPlannerExample.rtw ### Using System Target File: Z:\25\avijayar.Bdoc23a.j2028781\matlab\rtw\c\ert\ert.tlc ### Loading TLC function libraries ......... ### Initial pass through model to cache user defined code ... ### Caching model source code ........................................................................... ### Writing header file ROS2ValetBehavioralPlannerExample_types.h ### Writing source file ROS2ValetBehavioralPlannerExample.cpp ### Writing header file ROS2ValetBehavioralPlannerExample_private.h ### Writing header file ROS2ValetBehavioralPlannerExample.h ### Writing header file rtwtypes.h . ### Writing header file rtGetNaN.h ### Writing source file rtGetNaN.cpp ### Writing header file rt_nonfinite.h ### Writing source file rt_nonfinite.cpp . ### Writing header file rtGetInf.h ### Writing source file rtGetInf.cpp ### Writing header file rtmodel.h ### Writing source file ROS2ValetBehavioralPlannerExample_data.cpp ### Writing source file ert_main.cpp ### TLC code generation complete (took 4.5s). .### Saving binary information cache. ### Using toolchain: Colcon Tools Creating a Python virtual environment.Done. Adding required Python packages to virtual environment.Done. Copying include folders.Done. Copying libraries.Done. ### Building 'ROS2ValetBehavioralPlannerExample': all Running colcon build in folder 'C:/Users/avijayar/OneDrive - MathWorks/Documents/MATLAB/ExampleManager/avijayar.myBdoc23a/ros-ex41987970'. Build in progress. This may take several minutes... Build succeeded.Success ### Successfully generated all binary outputs. ### Creating HTML report file index.html ### Successful completion of build procedure for: ROS2ValetBehavioralPlannerExample ### Simulink cache artifacts for 'ROS2ValetBehavioralPlannerExample' were created in 'C:\Users\avijayar\OneDrive - MathWorks\Documents\MATLAB\ExampleManager\avijayar.myBdoc23a\ros-ex41987970\ROS2ValetBehavioralPlannerExample.slxc'. Build Summary Top model targets built: Model Action Rebuild Reason ============================================================================================================================================ ROS2ValetBehavioralPlannerExample Code generated and compiled. Global variable #SL_Bus_ROSVariableLengthArrayInfo#ros2lib.sldd# changed. 1 of 1 models built (0 models already up to date) Build duration: 0h 2m 44.093s ### Starting build procedure for: ROS2ValetPathPlannerExample ### Generating code and artifacts to 'Model specific' folder structure ### Generating code into build folder: C:\Users\avijayar\OneDrive - MathWorks\Documents\MATLAB\ExampleManager\avijayar.myBdoc23a\ros-ex41987970\ROS2ValetPathPlannerExample_ert_rtw ### Generated code for 'ROS2ValetPathPlannerExample' is up to date because no structural, parameter or code replacement library changes were found. ### Recompiling code generation target for model ROS2ValetPathPlannerExample because a referenced model was recompiled. ### Using toolchain: Colcon Tools ### Building 'ROS2ValetPathPlannerExample': all Running colcon build in folder 'C:/Users/avijayar/OneDrive - MathWorks/Documents/MATLAB/ExampleManager/avijayar.myBdoc23a/ros-ex41987970'. Build in progress. This may take several minutes... Build succeeded.Success ### Successfully generated all binary outputs. ### Creating HTML report file index.html ### Successful completion of build procedure for: ROS2ValetPathPlannerExample Build Summary Top model targets built: Model Action Rebuild Reason ====================================================================================== ROS2ValetPathPlannerExample Code compiled. Compilation artifacts were out of date. 1 of 1 models built (0 models already up to date) Build duration: 0h 1m 56.515s ### Starting build procedure for: ROS2ValetControllerExample ### Generating code and artifacts to 'Model specific' folder structure ### Generating code into build folder: C:\Users\avijayar\OneDrive - MathWorks\Documents\MATLAB\ExampleManager\avijayar.myBdoc23a\ros-ex41987970\ROS2ValetControllerExample_ert_rtw ### Generated code for 'ROS2ValetControllerExample' is up to date because no structural, parameter or code replacement library changes were found. ### Recompiling code generation target for model ROS2ValetControllerExample because a referenced model was recompiled. ### Using toolchain: Colcon Tools ### Building 'ROS2ValetControllerExample': all Running colcon build in folder 'C:/Users/avijayar/OneDrive - MathWorks/Documents/MATLAB/ExampleManager/avijayar.myBdoc23a/ros-ex41987970'. Build in progress. This may take several minutes... Build succeeded.Success ### Successfully generated all binary outputs. ### Creating HTML report file index.html ### Successful completion of build procedure for: ROS2ValetControllerExample Build Summary Top model targets built: Model Action Rebuild Reason ===================================================================================== ROS2ValetControllerExample Code compiled. Compilation artifacts were out of date. 1 of 1 models built (0 models already up to date) Build duration: 0h 2m 7.4935s
VEHICLE_MODE=1; % switch variant subsystem in Vehicle node to use ROS 2 network open_system("ROS2ValetVehicleExample"); set_param("ROS2ValetVehicleExample","SimulationCommand","start");