autowarefoundation / AWSIM-Labs

Open source simulator for self-driving vehicles
https://autowarefoundation.github.io/AWSIM-Labs/
Other
15 stars 13 forks source link

Add feature to spawn NPC from RVIZ #65

Closed mitsudome-r closed 3 months ago

mitsudome-r commented 6 months ago

Description

We could add a feature to AWSIM to receive a dummy perception message from RVIZ to spawn an NPC vehicle at user's demands just like in this tutorial: https://autowarefoundation.github.io/autoware-documentation/main/tutorials/ad-hoc-simulation/planning-simulation/#placing-dummy-objects

SujayAmberkar commented 5 months ago

I'm getting this message when I listen to the /simulation/dummy_perception_publisher/object_info, here the position is around 81000 & 49000 for x and y whenever I create a dummy NPC in rviz.

  1. Should I be using this position?
  2. Should it be converted?
initial_state:
  pose_covariance:
    pose:
      position:
        x: 81383.5859375
        y: 49919.77734375
        z: 0.0
      orientation:
        x: 0.0
        y: 0.0
        z: 0.2974268081526713
        w: 0.95474462229023
mozhoku commented 5 months ago

@SujayAmberkar you can check out this.

https://github.com/autowarefoundation/AWSIM-Labs/blob/a99f67e1261df08d405de16883d8e000a1140485/Assets/AWSIM/Scripts/Sensors/Gnss/GnssSensor.cs#L73

I'm not sure if it does anything else with the coordinate values.

xmfcx commented 5 months ago

Message should be added as a custom message:

SujayAmberkar commented 5 months ago

@mozhoku I want to create a new custom message but I'm unsure if it'll cause any problems. And you're working on an issue of replacing older messages with new ones so I wanted to know what I should take care of while creating a new custom message. By reading that issue I could only understand that it's something related to the change of names.

mozhoku commented 4 months ago

@SujayAmberkar if you are adding a new custom message it shouldn't affect anything. I will be replacing the current message types used by the simulation so that it can communicate with the main autoware_universe branch after the msg changes. For example: autoware_auto_perception_msgs => autoware_perception_msg.

xmfcx commented 4 months ago

@SujayAmberkar do you have any updates on this feature? We would like to speed up this feature's development, it is important for the planning team.

SujayAmberkar commented 4 months ago

@xmfcx Hello, extremely sorry for the delay. I'll finish this as soon as possible. I'm facing a problem here. I cannot access the position inside the message after adding a custom message in Unity and writing the following code.

initial_state:
  pose_covariance:
    pose:
      position:
        x: 81383.5859375
        y: 49919.77734375
        z: 0.0
      orientation:
        x: 0.0
        y: 0.0
        z: 0.2974268081526713
        w: 0.95474462229023
public class RVIZNPCSpawner : MonoBehaviour
    {
        [SerializeField] string NPCSpawnerTopic = "/simulation/dummy_perception_publisher/object_info";

        // Subscriber
        ISubscription<dummy_perception_publisher.msg.Object> NPCSpawnerSubscriber;

        void Start()
        {
            // Define default QoS settings
            QoSSettings qosSettings = new QoSSettings();

            // Initialize the ROS2 node and create the subscription
            NPCSpawnerSubscriber = SimulatorROS2Node.CreateSubscription<dummy_perception_publisher.msg.Object>(
                NPCSpawnerTopic, NPCSpawnerCallback, qosSettings.GetQoSProfile());
        }

        /// <summary>
        /// Callback method to handle incoming messages
        /// </summary>
        /// <param name="msg">Received Object message</param>
        void NPCSpawnerCallback(dummy_perception_publisher.msg.Object msg)
        {
            Debug.Log(msg.initial_state.pose_covariance.pose.position.x);        }

        void OnDestroy()
        {
            // Clean up the subscription when the GameObject is destroyed
            SimulatorROS2Node.RemoveSubscription<dummy_perception_publisher.msg.Object>(NPCSpawnerSubscriber);
        }
    }

I get this error, error CS1061: 'Object' does not contain a definition for 'initial_state' and no accessible extension method 'initial_state' accepting a first argument of type 'Object' could be found (are you missing a using directive or an assembly reference?)

SujayAmberkar commented 4 months ago

Solved the problem in the previous comment. Here's a video demo of the work so far, NPC Vehicles and Pedestrians are spawned properly but vehicles do not move. https://www.youtube.com/watch?v=eyjrpyz1Mq8

SujayAmberkar commented 4 months ago

@xmfcx I've added a feature to make the vehicle move in its forward direction once it's spawned. But here's the problem, since we want to remove the rigid body component the vehicle goes into the ground after moving some distance maybe because the ground is not levelled. Is there a reason for removing the rigid body? Initial pose: Screenshot from 2024-07-12 20-01-04

After some time: image

xmfcx commented 4 months ago

Why remove the rigid body? I've suggested removing the colliders. Or colliders could have their layers set accordingly https://docs.unity3d.com/Manual/LayerBasedCollision.html

SujayAmberkar commented 4 months ago

Ahh ok, my bad. I got confused.

SujayAmberkar commented 4 months ago

Features Added:

https://github.com/user-attachments/assets/79b67a5c-9c50-4333-8237-658994f09ae8

SujayAmberkar commented 4 months ago

Here is the draft PR https://github.com/autowarefoundation/AWSIM-Labs/pull/118