Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Resolved Problem importing custom ROS msgs

Discussion in 'Robotics' started by d_pepley, Feb 3, 2022.

  1. d_pepley

    d_pepley

    Joined:
    Oct 2, 2020
    Posts:
    18
    Hello,

    I am having issues with important customer msgs and srvs for ROS2. This issue only appeared recently. Basically, I go through the process outlined in https://github.com/Unity-Technologies/ROS-TCP-Connector/blob/main/MessageGeneration.md.

    In my xml file I have the package named ros_test. So everything appears fine at first. I get a RosMessage folder that contains RosTest/srv and RosTest/msg. The files are also recognized by my C# scripts for when I go to use the new msg types.

    However, when I go to actually run the simulation I get the following error:
    SysCommand.publish - Unknown message class 'ros_test/Vector3'
    UnityEngine.Debug:LogError (object)
    Unity.Robotics.ROSTCPConnector.ROSConnection:ReceiveSysCommand (string,string) (at Library/PackageCache/com.unity.robotics.ros-tcp-connector@c27f00c6cf/Runtime/TcpConnector/ROSConnection.cs:680)
    Unity.Robotics.ROSTCPConnector.ROSConnection:Update () (at Library/PackageCache/com.unity.robotics.ros-tcp-connector@c27f00c6cf/Runtime/TcpConnector/ROSConnection.cs:587)

    I was not getting this error when I did testing with this a month ago. It seems to be looking for a class called ros_test, that it can't find.

    Can anyone help with this? It's become a major issue for me.
    I also attempted to upgrade to ROSTCPConnector and Ednpoint 0.7 from 0.6. Had the issue in both versions.
     
  2. d_pepley

    d_pepley

    Joined:
    Oct 2, 2020
    Posts:
    18
    So I have found a solution to this error. It actually has to do with the ROS2 module, not Unity. Basically, the msg I was trying to create was left out of my CMakeBuild list. So as a result, the Ros2Endpoint server was not able to find this message type.

    So steps to fix if you receive the error in Unity "unknown message class '<your class name'" is
    Go you your ROS2 package, double check that you have included your message in the CMakeList
    Rebuild the package with colcon build.
    Resource the package.
    Now run your Ros2endpoint and things should be working properly
     
    cpereira and panserzap like this.
  3. vipulsareen660

    vipulsareen660

    Joined:
    May 15, 2023
    Posts:
    2
    I also have the same issue can you help me to solve that :



    i have imported and built the message package through ros unity tcp and it was fine . I established the unity ros connection it was working fine i created a publisher in ros which is first subscribing the data from the px4 then publishing it to the different node .I created the subscription node in unity to subscribe the data but when i play the scene its shows the "error =
    SysCommand.subscribe - Unknown message class 'px4_msgs/SensorCombined'
    UnityEngine.Debug:LogError (object)
    Unity.Robotics.ROSTCPConnector.ROSConnection:ReceiveSysCommand (string,string) (at ./Library/PackageCache/com.unity.robotics.ros-tcp-connector@3288e188a2/Runtime/TcpConnector/ROSConnection.cs:681)
    Unity.Robotics.ROSTCPConnector.ROSConnection:Update () (at ./Library/PackageCache/com.unity.robotics.ros-tcp-connector@3288e188a2/Runtime/TcpConnector/ROSConnection.cs:588)"
    I am attaching both publisher and subscriber file .Can someone help me to solve this problem



    subscriber node which I have made in unity:


    using UnityEngine;


    using Unity.Robotics.ROSTCPConnector;
    using RosPos = RosMessageTypes.Px4.SensorCombinedMsg;

    public class RosSub : MonoBehaviour
    {
    public GameObject cube;
    void Start()
    {
    ROSConnection.GetOrCreateInstance().Subscribe<RosPos>("data", PosChange);
    }

    void PosChange(RosPos posMessage)
    {
    // Handle received sensor data here
    float gyroX = posMessage.gyro_rad[0];
    float gyroY = posMessage.gyro_rad[1];
    float gyroZ = posMessage.gyro_rad[2];

    // Example: Rotate the object based on gyro data
    transform.Rotate(new Vector3(gyroX, gyroY, gyroZ) * Time.deltaTime);
    }
    }



    subscribe and publisher node created in ros which is subscribing the px4 data and publishing that :



    #include <rclcpp/rclcpp.hpp>
    #include <px4_msgs/msg/sensor_combined.hpp>

    /**
    * @brief Sensor Combined uORB topic data callback
    */
    class SensorCombinedListener : public rclcpp::Node
    {
    public:
    explicit SensorCombinedListener() : Node("sensor_combined_listener")
    {
    rmw_qos_profile_t qos_profile = rmw_qos_profile_sensor_data;
    auto qos = rclcpp::QoS(rclcpp::QoSInitialization(qos_profile.history, 5), qos_profile);

    subscription_ = this->create_subscription<px4_msgs::msg::SensorCombined>("/fmu/out/sensor_combined", qos,
    [this](const px4_msgs::msg::SensorCombined::UniquePtr msg) {
    std::cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
    std::cout << "RECEIVED SENSOR COMBINED DATA" << std::endl;
    std::cout << "=============================" << std::endl;
    std::cout << "ts: " << msg->timestamp << std::endl;
    std::cout << "gyro_rad[0]: " << msg->gyro_rad[0] << std::endl;
    std::cout << "gyro_rad[1]: " << msg->gyro_rad[1] << std::endl;
    std::cout << "gyro_rad[2]: " << msg->gyro_rad[2] << std::endl;
    std::cout << "gyro_integral_dt: " << msg->gyro_integral_dt << std::endl;
    std::cout << "accelerometer_timestamp_relative: " << msg->accelerometer_timestamp_relative << std::endl;
    std::cout << "accelerometer_m_s2[0]: " << msg->accelerometer_m_s2[0] << std::endl;
    std::cout << "accelerometer_m_s2[1]: " << msg->accelerometer_m_s2[1] << std::endl;
    std::cout << "accelerometer_m_s2[2]: " << msg->accelerometer_m_s2[2] << std::endl;
    std::cout << "accelerometer_integral_dt: " << msg->accelerometer_integral_dt << std::endl;
    });
    }

    private:
    rclcpp::Subscription<px4_msgs::msg::SensorCombined>::SharedPtr subscription_;

    };

    int main(int argc, char *argv[])
    {
    std::cout << "Starting sensor_combined listener node..." << std::endl;
    setvbuf(stdout, NULL, _IONBF, BUFSIZ);
    rclcpp::init(argc, argv);
    rclcpp::spin(std::make_shared<SensorCombinedListener>());

    rclcpp::shutdown();
    return 0;
    }



    I have imported the same message package which comes with px4 so that i can publish the px4 data to ros2