Search Unity

How to add sensor data into observation?

Discussion in 'ML-Agents' started by enzodtz, Apr 2, 2021.

  1. enzodtz

    enzodtz

    Joined:
    Aug 21, 2020
    Posts:
    7
    So I have a
    RayPerceptionSensorComponent2D
    and I thought that it would automatically send the data to the observation. I think that I was wrong, since I got one warning telling me that the observation size was smaller than what was expected.

    I researched a lot, and rode the docs and the forum, but was not able to find how to extract data from the sensors.

    Github: https://github.com/Unity-Technologi...ronment-Design-Agents.md#raycast-observations
    Unity: https://docs.unity.cn/Packages/com....s.Sensors.RayPerceptionSensorComponent2D.html

    What I have now, is the component into the gameObject, and a variable with it:
    raySensor = gameObject.GetComponent<RayPerceptionSensorComponent2D>()
    , but could not find a function to extract that raw data and add it into the sensor of the
    CollectObservations
    method.

    How can I do this?

    Thanks a lot.
     
  2. enzodtz

    enzodtz

    Joined:
    Aug 21, 2020
    Posts:
    7
    I'm trying to fix the "rode" but its giving me an error, sorry about that
     
  3. ruoping_unity

    ruoping_unity

    Unity Technologies

    Joined:
    Jul 10, 2020
    Posts:
    134
    hey sorry for the late reply I somehow missed your post.

    The sensors will automatically collect observations and send it to the trainer. You don't have to do anything extra except for configuring the sensor for your case.

    The reason you're seeing that warning is because you specified a non-zero observation size in the behavior parameters. You only need to set it when you're using "Vector observations" by implementing the CollectObservations() method in agent. Agent.CollectObservations() is used when you want to collect observations manually without a sensor, usually for things like agent's position, velocity, etc. The ObservationSize should be the same size as the data recorded in CollectObservations(), and if you're not doing anything there you should set it to 0.
     
    Atilli, tjumma and ademord like this.