speed up ROS controller loop rate

10 views (last 30 days)
I am using a MATLAB 2021a.
I made a sliding mode controller to control a robot in a simulation. I have been following several of the examples mainly the feedback example.
However I would really like to run my controller much faster thjen 0.02s I like to increase this by an order of magnitude. 0.02s is rather slow.
How can I increase the loop speed and make sure its stable?

Accepted Answer

Abhijeet Gadkari
Abhijeet Gadkari on 1 Jun 2021
Edited: Abhijeet Gadkari on 1 Jun 2021
Hello Nathaniel,
Simulink simulation honors the sample time set by you in the model. So, reducing sample time of the model would run your algorithm at a higher frequency in simulation. There are 2 ways to achieve this.
  1. You can set the sample time parameter for all the source blocks in your model to your desired frequency,
  2. Set all source blocks to inherit sample time, setting the value in block parameters to -1, and set the FixedStepSize parameter of your Simulink model as shown below (using either MATLAB Command
set_param('robotROSFeedbackControlExample20b','FixedStepSize','0.01');
or Simulink Configuration Parameters)
Set FixedStepSize
However, the stability would depend on many factors and since Simulation is running on a host computer, the resource contention may affect your Simulation (may be if you shutdown everything else except Simulink simulation). Especially for Simulink model containing ROS (Publish, Subscribe) blocks, there is an inherent overhead of converting the ROS messages that could also affect your throughput.
While selecting the sample time, you need to consider the controller algorithm complexity and account for the ROS message to Simulink bus conversion. For instance, verify if your controller algorithm finishes processing loop within the desired sample time. You can use Simulink Profiler to get this information.
Moreover, deploying the Simulink model as a node would provide more stable execution, since that would run as a standalone application on your robot. But that too has its limitation on how fast you can schedule a thread on Linux. Typically 1 ms is widely accepted limit of most desktop Linux systems. Beyond this limit, the desktop operating system cannot sustain real-time execution (meeting the deadline) of your algorithm.
Let me know if you need further information.
-Abhijeet
  2 Comments
Nathaniel Goldfarb
Nathaniel Goldfarb on 3 Jun 2021
Thank you for the help. I have been working through the provided examples.
I am running into a compile error that I am not sure the of the source. Since it does not appear when I just run the model.
Top model targets built:
Model Action Rebuild Reason
===============================================================================
sliding_controller2 Failed Code generation information file does not exist.
0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 28.545s
Unrecognized message type rbdl_server/RBDLInverseDynamics. Use rosmsg list to see available types.
I can see my ros messages here:
rbdl_server/RBDLInverseDynamicsRequest
rbdl_server/RBDLInverseDynamicsResponse
Abhijeet Gadkari
Abhijeet Gadkari on 3 Jun 2021
Edited: Abhijeet Gadkari on 3 Jun 2021
Hello Nathaniel,
I've attached a snap-shot of a simple model that uses the custom message, that you provided in your previous post.
Service call example
I was able to generate code for this model in R2021a MATLAB.
Could you share your Simulink model?
-Abhijeet

Sign in to comment.

More Answers (1)

Nathaniel Goldfarb
Nathaniel Goldfarb on 3 Jun 2021
Here is my model. Thankyou for all the help
  3 Comments
Nathaniel Goldfarb
Nathaniel Goldfarb on 3 Jun 2021
Edited: Nathaniel Goldfarb on 3 Jun 2021
Thankyou for the help. I made a simplifed model and submitted a custom service ticket.
Also I have attached my simplified model with just the service call.
Nathaniel Goldfarb
Nathaniel Goldfarb on 4 Jun 2021
I think I found the problem, as per the website:
Code Generation with Custom messages
Custom message and service types can be used with ROS Simulink blocks for generating C++ code for a standalone ROS node. The generated code (.tgz archive) will include Simulink definitions for the custom messages, but it will not include the ROS custom message packages. When the generated code is built in the destination Linux System, it expects the custom message packages to be available in the catkin workspace or on the ROS_PACKAGE_PATH. Ensure that you either install or copy the custom message package to your Linux system before building the generated code.
I think that this might be causing an issue.

Sign in to comment.

Categories

Find more on Custom Message Support in Help Center and File Exchange

Tags

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!