MATLAB on the host with Simulink Target for Arduino
In this example, MATLAB is running on a desktop computer to find the ball, calculate the necessary control commands and then communicate via UDP with an Arduino to control the motors. The buildExecutable function is used to convert host function into an executable.
Step 1: Deploy the Simulink target model to the Arduino
Open and build the model called targetArduinoSimulink.slx.
Step 2: Run the MATLAB host function on the host computer
Open and run the function called hostMatlab.m
Step 3: Generate an executable out of the MATLAB host function
Stop the function "hostMatlab.m" by clicking on the MATLAB Command Window and pressing ctrl+c.
Run the following command in the MATLAB Command Window:
Step 4: Run the executable hostMatlab.exe in a terminal
Step 5: Run the Simulink target model in External Mode
Set the model to external mode by selecting "External" from the Simulink Mode dropdown.
This will run the code on the Arduino while enabling the user to tune and monitor any signal from the model. In this case, the user will see the motor commands being sent to the Servo Write blocks.
Note: Try not to run the MATLAB host function and the Simulink target model in external mode at the same time. They will interfere with each other.
The options are:
- Run MATLAB host function on the host computer
- Build the target model on the Arduino
- Run MATLAB host executable on the host computer
- Run the target model in External Mode on the Arduino