RobotecAI / ros2-for-unity

High-performance ROS2 solution for Unity3D
Apache License 2.0
446 stars 58 forks source link

Cannot use custom messages in unity #110

Closed shwwoooo closed 2 months ago

shwwoooo commented 2 months ago

Hi, I am on Ubuntu 22.04 and using ROS humble. I built ros2-for-unity with custom messages by copying the messages source directories (the .msg and cmake files) to src/ros2cs/custom_messages. ros2-for-unity can be built, but when I copy the asset over to unity workspace and try to use the custom messages, unity complains 'GimbalCmd' does not contain a definition for 'position'. Here are my code in c# and msg files. subscriber.cs

gimbalSub = ros2Node.CreateSubscription<rm_interfaces.msg.GimbalCmd>("GimbalCtrl", msg => {
                   transform.localRotation = Quaternion.Euler(msg.position.pitch, msg.position.yaw, 0.0f);
                   });

GimbalCmd.msg

Gimbal position
Gimbal velocity

Gimbal.msg

float32 yaw
float32 pitch

Can anyone give some pointers in how to use custom messages? Thanks!

adamdbrw commented 2 months ago

Please check the generated messages. C# convention for field naming uses uppercase letters. msg.Position should work.

shwwoooo commented 2 months ago

Thank you for your quick response! Yes it works And I found out that it requires sourcing the built files from ros2-for-unity (install/setup.bash) or there will be runtime errors in Unity.