MATLAB Answers

Having trouble building custom ROS msgs in MATLAB 2020a

53 views (last 30 days)
Jiyo Palatti
Jiyo Palatti on 24 Jun 2020
Answered: Julius Sustarevas on 24 Oct 2020 at 17:11
Hi,
I am having trouble building custom ROS msgs and adding them to availabe msg definitions in MATLAB.
I am getting the follwing error.
Building custom message files for the following packages:
carla_common
carla_msgs
carla_ros_bridge
:rosjava_messages is spawning subprojects: [carla_common, carla_msgs, carla_ros_bridge]
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "mavenRepository" on "org.ros.gradle_plugins.RosPluginExtension_Decorated@6aef4eb8", value: "".
Deprecated dynamic property "mavenRepository" created in multiple locations.
:carla_common:bugfixtask
:carla_common:generateSources
:carla_common:compileJava UP-TO-DATE
:carla_common:processResources UP-TO-DATE
:carla_common:classes UP-TO-DATE
:carla_common:jar
:carla_common:assemble
:carla_common:compileTestJava UP-TO-DATE
:carla_common:processTestResources UP-TO-DATE
:carla_common:testClasses UP-TO-DATE
:carla_common:test UP-TO-DATE
:carla_common:check UP-TO-DATE
:carla_common:build
:carla_msgs:bugfixtask
:carla_msgs:generateSources
:carla_msgs:compileJavawarning: [options] bootstrap class path not set in conjunction with -source 1.6
/home/jiyo/workspace/autonomous-overtaking/autonomous-overtaking/matlab_gen/build/rosjava_build/carla_msgs/build/generated-src/carla_msgs/CarlaEgoVehicleStatus.java:12: error: cannot find symbol
geometry_msgs.Accel getAcceleration();
^
symbol: class Accel
location: package geometry_msgs
/home/jiyo/workspace/autonomous-overtaking/autonomous-overtaking/matlab_gen/build/rosjava_build/carla_msgs/build/generated-src/carla_msgs/CarlaEgoVehicleStatus.java:13: error: cannot find symbol
void setAcceleration(geometry_msgs.Accel value);
^
symbol: class Accel
location: package geometry_msgs
2 errors
1 warning
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':carla_msgs:compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 2.958 secs
An error occurred while building custom messages. See the full error message above.
Possible reasons for the error:
1. The msg or srv files may have syntax errors.
2. The dependencies on other message packages may not be declared correctly in the build_depends tags in the package.xml.
3. Messages packages declared as dependencies may not be available.
4. The custom message packages may be missing a build dependency on "message_generation".
See the ROS Custom Messages documentation for more information.
I figured that the geometry_msgs available in MATLAB are old and don't contain new definitons, therefore I built the geometry_msgs alone forst and added it to the MATLAB. I am able to see them in the rosmsg list
geometry_msgs/Accel
geometry_msgs/AccelStamped
geometry_msgs/AccelWithCovariance
geometry_msgs/AccelWithCovarianceStamped
geometry_msgs/Inertia
geometry_msgs/InertiaStamped
geometry_msgs/Point
geometry_msgs/Point
geometry_msgs/Point32
geometry_msgs/Point32
geometry_msgs/PointStamped
geometry_msgs/PointStamped
geometry_msgs/Polygon
geometry_msgs/Polygon
geometry_msgs/PolygonStamped
geometry_msgs/PolygonStamped
geometry_msgs/Pose
geometry_msgs/Pose
geometry_msgs/Pose2D
geometry_msgs/Pose2D
geometry_msgs/PoseArray
geometry_msgs/PoseArray
geometry_msgs/PoseStamped
geometry_msgs/PoseStamped
geometry_msgs/PoseWithCovariance
geometry_msgs/PoseWithCovariance
geometry_msgs/PoseWithCovarianceStamped
geometry_msgs/PoseWithCovarianceStamped
geometry_msgs/Quaternion
geometry_msgs/Quaternion
geometry_msgs/QuaternionStamped
geometry_msgs/QuaternionStamped
geometry_msgs/Transform
geometry_msgs/Transform
geometry_msgs/TransformStamped
geometry_msgs/TransformStamped
geometry_msgs/Twist
geometry_msgs/Twist
geometry_msgs/TwistStamped
geometry_msgs/TwistStamped
geometry_msgs/TwistWithCovariance
geometry_msgs/TwistWithCovariance
geometry_msgs/TwistWithCovarianceStamped
geometry_msgs/TwistWithCovarianceStamped
geometry_msgs/Vector3
geometry_msgs/Vector3
geometry_msgs/Vector3Stamped
geometry_msgs/Vector3Stamped
geometry_msgs/Wrench
geometry_msgs/Wrench
geometry_msgs/WrenchStamped
geometry_msgs/WrenchStamped
I am still getting the error when building. Please let me know what I am doing wrong

  0 Comments

Sign in to comment.

Accepted Answer

Cam Salzberger
Cam Salzberger on 24 Jun 2020
Hello Jiyo,
Seeing each of the geometry_msgs show up twice is rosmsg list is indicative of an issue, not the building of it working. If you need to override existing message definitions, there is a different procedure to follow. Please see these steps for details.
Alternatively, you may be able to just add the new geometry_msgs messages that were missing (e.g. Accel), if it is acceptable to keep the old definitions for the existing messages.
-Cam

  5 Comments

Show 2 older comments
Cam Salzberger
Cam Salzberger on 6 Jul 2020
Hello Jiyo,
  • I'm not sure why you are running into this issue. When I tested following these steps to replace geometry_msgs, I also saw the double messages listed in "rosmsg list", but everything else was usuable. Just to be completely clear, here are the steps I followed:
  • Add geometry_msgs package to my current directory
  • Checked to make sure package.xml was in format 1
  • Ran:
rosgenmsg(pwd)
  • Edited the javaclasspath.txt file that was linked from the instructions
  • Added these lines to the file:
<before>
C:\path\to\folder\matlab_gen\jar\geometry_msgs-1.13.0.jar
  • Restarted MATLAB
  • Deleted the folder matlab_gen\msggen\+ros\+custom\+msggen\+geometry_msgs. Note that this is slightly different than the instructions in the link, as there used to be a +robotics package folder before ROS Toolbox became its own thing.
  • Reran
rosgenmsg(pwd)
  • Restarted MATLAB
  • Added the new message definitions MATLAB files to path (you probably want to do savepath as well):
addpath('C:\path\to\folder\matlab_gen\msggen')
  • Rehashed all MATLAB files including those in the toolbox to make sure newest definitions are being picked up (this is also slightly different from the linked instructions):
rehash toolboxcache
  • Tested creating a geometry_msgs/Accel message object, which worked
  • Added carla_msgs package to current folder. To be clear, you could probably have added carla_msgs in during the second run of rosgenmsg, but I wanted to do this as cleanly as possible.
  • Checked that it used package.xml format 1 as well
  • Ran:
rosgenmsg(pwd)
  • Updated javaclasspath.txt again so it now looks like:
<before>
C:\path\to\folder\matlab_gen\jar\geometry_msgs-1.13.0.jar
C:\path\to\folder\matlab_gen\jar\carla_msgs-1.0.1.jar
  • Restarted MATLAB
  • Made sure the "matlab_gen\msggen" folder was still on the path (I had to add it again, but if you saved the path, it should be fine)
  • Rehashed the toolbox again, just to be sure:
rehash toolboxcache
  • Created an instance of a carla_msgs/CarlaActorList message
So if you could try again, adding the new geometry_msgs definitions in first. Make sure that you are restarting MATLAB after adding the JAR files to the javaclasspath, then delete the MATLAB files and rerun rosgenmsg. Only after you confirm that geometry_msgs works fine, please then add carla_msgs.
If that still doesn't do the trick, then it may be a platform-specific issue. Are you on Linux or Mac, and which version?
-Cam
Jiyo Palatti
Jiyo Palatti on 7 Jul 2020
Hi Cam,
Thanks for your reply.
I tried your steps again. I am able generate custom ROS msgs for geometry_msgs.
I am also able to create a geometry_msgs/Accel message object using
msg = rosmessage('geometry_msgs/Accel')
But when I next tried to generate custom ROs custom msgs for carla package, I get the following error.
Checking subfolder "carla_msgs" for custom messages.
Building custom message files for the following packages:
carla_msgs
:rosjava_messages is spawning subprojects: [carla_msgs]
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "mavenRepository" on "org.ros.gradle_plugins.RosPluginExtension_Decorated@6e1b9411", value: "".
:carla_msgs:bugfixtask
:carla_msgs:generateSources
:carla_msgs:compileJavawarning: [options] bootstrap class path not set in conjunction with -source 1.6
/home/jiyo/workspace/autonomous-overtaking/custom_msgs/carla/matlab_gen/build/rosjava_build/carla_msgs/build/generated-src/carla_msgs/CarlaEgoVehicleStatus.java:12: error: cannot find symbol
geometry_msgs.Accel getAcceleration();
^
symbol: class Accel
location: package geometry_msgs
/home/jiyo/workspace/autonomous-overtaking/custom_msgs/carla/matlab_gen/build/rosjava_build/carla_msgs/build/generated-src/carla_msgs/CarlaEgoVehicleStatus.java:13: error: cannot find symbol
void setAcceleration(geometry_msgs.Accel value);
^
symbol: class Accel
location: package geometry_msgs
2 errors
1 warning
FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':carla_msgs:compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 3.915 secs
An error occurred while building custom messages. See the full error message above.
Possible reasons for the error:
1. The msg or srv files may have syntax errors.
2. The dependencies on other message packages may not be declared correctly in the build_depends tags in the package.xml.
3. Messages packages declared as dependencies may not be available.
4. The custom message packages may be missing a build dependency on "message_generation".
See the ROS Custom Messages documentation for more information.
This indicates that the newly generated geometry_msgs doesn't seem to register and subsequent rosgenmsg commands don't pick previously generated msgs.
My javaclasspath.txt is as follows -
<before>
/home/jiyo/workspace/autonomous-overtaking/custom_msgs/geometry/matlab_gen/jar/geometry_msgs-1.13.0.jar
Adding the lines to the javaclasspath.txt doesn't seem to make any difference. I removed those lines and restarted MATLAB and tried generating the Accel msg and it still succeeds for some reason.
In regards to your query regarding platform, the detatils are as follows.
OS: Ubuntu 18.04.4 LTS
java -version
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu218.04)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-2ubuntu218.04, mixed mode, sharing)
MATLAB version 2019b (also tried with MATLAB 2020a)
Let me know if anymore details are required.
Cam Salzberger
Cam Salzberger on 7 Jul 2020
Hey Jiyo,
Your folder structure here:
/home/jiyo/workspace/autonomous-overtaking/custom_msgs/geometry/matlab_gen/jar/geometry_msgs-1.13.0.jar
is making me wonder if this is causing an issue. When I initially built the geometry_msgs package, my folder structure looked like:
current_dir/
|-geometry_msgs/
| |-msg/
| | '-".msg" files
| |-CMakeLists.txt
| '-package.xml
'-matlab_gen/
When I added the carla_msgs package, I did so in the same folder as geometry_msgs. Keeping all custom message packages in one folder is recommended here:
At any time, there should only be one custom messages folder on the MATLAB path. This folder can contain multiple packages, but it is recommended that you keep them all in one unique folder.
current_dir/
|-carla_msgs/
|-geometry_msgs/
'-matlab_gen/
I'm thinking it may be possible that splitting it up like this could cause the interdependency finding to fail?
custom_msgs/
|-carla/
| |-carla_msgs/
| '-matlab_gen/
'-geometry/
|-geometry_msgs/
'-matlab_gen/
-Cam

Sign in to comment.

More Answers (2)

Jiyo Palatti
Jiyo Palatti on 10 Jul 2020
Hi Cam,
The fix you mentioned above has fixed the issue. I moved both of the msgs folder to the same parent directory and msg generation is working.
I was under the impression that once the custom ROS msgs are generated and added to the path (java & matlab), it will be used for future custom ROS msg generation.
Thanks for your help.

  1 Comment

Cam Salzberger
Cam Salzberger on 13 Jul 2020
Hey Jiyo,
I'm glad to hear that resolved the issue. I am not completely sure about the intracacies of rosjava message library generation, but if it is anything like standard catkin and colcon then there is a different rule for message dependencies. Packages that depend on other packages need to all be built in the same build command, or otherwise added to the library path through back-end variables. The library path update can be done for the built-in messages shipping with MATLAB, but any other custom messages with dependencies need to all be together.
It's really just easier to put all custom message packages in the same location to prevent issues like this.
-Cam

Sign in to comment.


Julius Sustarevas
Julius Sustarevas on 24 Oct 2020 at 17:11
Thanks for this, I was able to update visualiation msgs to melodic and send to rviz.
I'd like to submit a feature request for this process to be easier. The different jar files for full ros-desktop-intstall messages could ship with matlab for hydro,indigo,kinetic,melodic. etc. Some type of automatic reloading of different jar files for kinetic, melodic msg definitions.
btw std_msgs do not buil at all using this procedure(I think its the known Header bug)

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!