MATLAB Answers

Simulink/ROS: Publishing JointTrajectory Messages for end effector positions

조회 수: 42(최근 30일)
Ehtisham ul Hasan
Ehtisham ul Hasan 9 Mar 2021
댓글: charles guo 5 May 2021 11:09
I have a human model in Gazebo ROS.The controller is joint trajectory that works fine in ROS environment. Now I have to add a controller but that in Simulink ROS toolbox. Instead of sending Joint Positions I want to send End Effector positions. In other words I am working in Task Space and not in Joint Space. I am unable to access positions from joint trajectory blank message and could not find a solution for quite a while now.
I request if anyone can help me in this regard. I have gone through a question posted in 2017 with title
Simulink/ROS: Publishing JointTrajectory Messages
but it plans in joint space and inputs joint positions. I have to send position commands to my arm group to perform point to point trajectroy planing in Task space(cartesian space). Any help would be appreciated.
As an initial step, I have broken down my problem to first publish one joint position that is to my gripper finger. For this purpose I have used the idea mentioned in the above post highlighted in bold for my gripper joint movement. I do not get any erros in Matlab but I am getting the following error repeatedly in my ROS terminal and hence my joint is not actuated.
Dropping all 1 trajectory point(s), as they occur before the current time. Last point is 0s in the past.
I dont understand why this is happening. Anyhelp would be appreciated please. As if this gets published to the joint and it finally gets actuated, I can eventually take it up further to reach the bigger goal of planning in Cartesian Space.


Remo Pillat
Remo Pillat 12 Mar 2021
Hi Ehtisham,
Please take a look at the "Control PR2 Arm Movements" example in Robotics System Toolbox. It shows how to create a JointTrajectory message and assign the relevant data (see the rGoalMsg.Trajectory variable in the example). You should be able to extrapolate from that for your own robot, e.g. assign the right joint names.
The example also shows how to use Inverse Kinematics in MATLAB to find the right joint positions for your desired end effector pose.
Once you have it working in MATLAB, you should be able to port this to Simulink pretty easily (there are existing blocks for all the functionality you need).
Hope this help.
  댓글 수: 7
Ehtisham ul Hasan
Ehtisham ul Hasan 16 Mar 2021
With regard to your previous comment. Just a refresher, as I think I have not been able to explain correctly. The rosaction in the from of m-file (as per PR2 example) works fine for my model. I get the error what i shared but the execution takes place from m-file as desired for said joint positions.
Hope it gets easier to understand now.
(My concern at the moment is if something works from an m-file regardless of the error, then it should eventually work from simulink through matlab function blocks.)

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

Ehtisham ul Hasan
Ehtisham ul Hasan 18 Mar 2021
Following through number of posts and documentation I am currently at the following stage. I found from a mathwork post and at the following link that though /opt/ros/kinetic/share although holds scattered msg packages but can be given as folderpath in rosgenmsg(foderpath).
I am using ROS Kinetic and Matlab 2020a on Ubuntu 16.04 OS and I did the following in matlab
>> rosgenmsg('/opt/ros/kinetic/share')
Unrecognized function or variable 'rosgenmsg'.
Did you mean:
>> ros2genmsg('/opt/ros/kinetic/share')
Identifying message files in folder '/opt/ros/kinetic/share'..Done.
Error using ros.ros2.internal.createOrGetLocalPython (line 55)
Could not find Python version 3.7 or higher on your system. If you have multiple versions of python, use
pyversion to set the path to the executable for the version of Python to use.
Error in ros2genmsg (line 53)
ros.ros2.internal.createOrGetLocalPython(); %ensure python is available
>> pyenv
ans =
PythonEnvironment with properties:
Version: "2.7"
Executable: "/usr/bin/python"
Library: ""
Home: "/usr"
Status: NotLoaded
ExecutionMode: InProcess
Please note I am using ROS1 and not ROS2 but matlab did not read rosgenmsg command and instead asked for ros2genmsg command and even then did not work.
Please help sort out this issue.
  댓글 수: 12
charles guo
charles guo 5 May 2021 11:09
Well done! Great appreciation for your help.

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




Community Treasure Hunt

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

Start Hunting!

Translated by