Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

getting a NullReferenceException when importing a UR3 robot instead of Niryo_one robot

Discussion in 'Robotics' started by Sriramrex, Jan 20, 2024.

  1. Sriramrex

    Sriramrex

    Joined:
    Nov 17, 2023
    Posts:
    1
    Hello there,

    I have recently tried with Niryo_one robot which was in " Unity robotics hub" repository and tried this tutorial of Pick and place and it's all works fine. But now I am trying to implement the same strategy for the UR3 robot and did imported using URDF importer but the problem I was facing is ( after all the initial setup that was done as similar to the mentioned tutorials of Pick and place in Unity robotics hub) . I could successfully establish the connection with ros but now I could get a error as:
    NullReferenceException: Object reference not set to an instance of an object
    V_1_SourceDestinationPublisher.Start () (at Assets/Scripts/V_1_SourceDestinationPublisher.cs:46)

    so I went to the SouceDestinationPublisher code which is :

    using System;
    using RosMessageTypes.Geometry;
    using RosMessageTypes.NiryoMoveit;
    using Unity.Robotics.ROSTCPConnector;
    using Unity.Robotics.ROSTCPConnector.ROSGeometry;
    using Unity.Robotics.UrdfImporter;
    using UnityEngine;
    public class V_1_SourceDestinationPublisher : MonoBehaviour
    {
    const int k_NumRobotJoints = 6;
    public static readonly string[] LinkNames =
    { "base_link/base_link_inertia/shoulder_link", "upper_arm_link", "/forearm_link", "/wrist_1_link", "/wrist_2_link", "/wrist_3_link" };
    // Variables required for ROS communication
    [SerializeField]
    string m_TopicName = "/niryo_joints";
    [SerializeField]
    GameObject m_NiryoOne;
    [SerializeField]
    GameObject m_Target;
    [SerializeField]
    GameObject m_TargetPlacement;
    readonly Quaternion m_PickOrientation = Quaternion.Euler(90, 90, 0);
    // Robot Joints
    UrdfJointRevolute[] m_JointArticulationBodies;
    // ROS Connector
    ROSConnection m_Ros;
    void Start()
    {
    // Get ROS connection static instance
    m_Ros = ROSConnection.GetOrCreateInstance();
    m_Ros.RegisterPublisher<NiryoMoveitJointsMsg>(m_TopicName);
    m_JointArticulationBodies = new UrdfJointRevolute[k_NumRobotJoints];
    var linkName = string.Empty;
    for (var i = 0; i < k_NumRobotJoints; i++)
    {
    linkName += LinkNames;
    m_JointArticulationBodies = m_NiryoOne.transform.Find(linkName).GetComponent<UrdfJointRevolute>();
    }
    }
    public void Publish()
    {
    var sourceDestinationMessage = new NiryoMoveitJointsMsg();
    for (var i = 0; i < k_NumRobotJoints; i++)
    {
    sourceDestinationMessage.joints = m_JointArticulationBodies.GetPosition();
    }
    // Pick Pose
    sourceDestinationMessage.pick_pose = new PoseMsg
    {
    position = m_Target.transform.position.To<FLU>(),
    orientation = Quaternion.Euler(90, m_Target.transform.eulerAngles.y, 0).To<FLU>()
    };
    // Place Pose
    sourceDestinationMessage.place_pose = new PoseMsg
    {
    position = m_TargetPlacement.transform.position.To<FLU>(),
    orientation = m_PickOrientation.To<FLU>()
    };
    // Finally send the message to server_endpoint.py running in ROS
    m_Ros.Publish(m_TopicName, sourceDestinationMessage);
    }
    }

    I was getting an error in this particular line ( Bold text) and also I changed the respective link names according to my new imported robot . May I could please know What it means and how to resolve it.

    Any Ideas and solutions are highly appreciated and welcome.

    And sorry If I had not made my point clear of understandable
    I am open for your suggestions

    Thank you very much