Using the code from rosserial_arduino it is possible to use an arduino to as a ROS Node. Matlab initially complicates the issue by using the USB for its external mode, which prevents ROS publishing or subscribing over rosserial.
This is circumvented using the #define USE_STM32_HW_SERIAL to make ROS use the Arduino MEGA Serial Port 1. Note that an additional Serial Port Cable such as a DELOCK 83116 is needed to provide the second connection.
Due to the memory requirements, this currently only works on Arduino MEGA 2560.
Prior to deploying software to Arduino, the sfun_ros_interface.mexw64 needs to be made. In the Matlab command window run:
Assuming you already have ROS installed in either WSL or Linux, (I use ROS in WSL without any problems at all), start up three terminals with your ROS installation and catkin workspace sourced, and then in the three terminals run:
"sudo chmod 666 /dev/ttyS11"
"rosrun rosserial_python serial_node.py /dev/ttyS11"
where /dev/ttyS11 needs to be modified for the serial port your computer is using for connecting with Serial Port 1 of the Arduino MEGA
When everything is working correctly
"rostopic echo adc"
To subscribe to and view the values of the 6 adc channels being published to ROS
"rostopic pub toggle_led std_msgs/Empty --once"
To activate the LED on the arduino and enable the Servo Outputs
" rostopic pub robot_link_1 std_msgs/UInt16 300 --once"
To set the output to servo 1 to 300.
Note 1: This is only a demo program to show how ROS can be used to link with other parts of Simulink such as a state machine.
Note 2: The Software is prepared with ROS Kinetic. If you want to use it with any other ROS Version, or add in custom messages, you will need to patch the files with those you generate in ROS through:
"rosrun rosserial_arduino make_libraries.py ." as demonstrated in the rosserial_arduino Tutorial.
Note that these files cannot necessarily be directly copied across but will need to be modified, for instance to remove all Serial.print calls, to prevent ROS trying to use the same serial port as MATLAB.
This Submission includes code from rosserial_arduino, written by Michael Ferguson, Adam Stambler and published under BSD.
SMEAC (2021). ROS Deployed on Arduino running in External Mode in Simulink (https://www.mathworks.com/matlabcentral/fileexchange/69554-ros-deployed-on-arduino-running-in-external-mode-in-simulink), MATLAB Central File Exchange. Retrieved .
@Mohamed Khaled, If you want your board to have a Simulink model running as well, you could use this model. If you just want an Arduino program and have it respond to the messages, use rosserial directly. The advantage from this program, is that you have debug possibilities, where you can look at the variables on the board in real time using displays or scopes.
I working on a project for prototype of new robotic. I have a raspberry pi and i know already there is a siumlink box for ros on raspberry pi, but my question is : if i have another board ( ardunio or teensy ) connected with raspberry pi with serial port, and i want to publish a message from this board and make raspberry pi subscribe this message, is it possible to do that with your example, or shouldl i publish the teensy message through ros kinetic on raspberry pi and use the ros simulink to subscribe the message ?
I assumed that i install ros kinetic on raspberry pi also i installed rosserial_arduino or rosserial_teensy depending on which board i will use.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!