Kinds-of-Intelligence-CFI / animal-ai-python

Animal-AI Python
https://github.com/Kinds-of-Intelligence-CFI/animal-ai
MIT License
2 stars 0 forks source link

Raycast parser doesn't seem to be correctly attributing raycasts #7

Closed benaslater closed 3 weeks ago

benaslater commented 5 months ago

Describe the bug I am trying to train an agent to go towards an immovable block, which will cause it to fall into a pit and receive a reward (see below image, attached as pitLI-sanitycheck.txt

image

I initialise AAI with the following code

env: AnimalAIEnvironment = AnimalAIEnvironment(
    file_name=env_path,
    arenas_configurations=configuration_file,
    seed=env_seed,
    play=False,
    useCamera=False,
    useRayCasts=True,
    raysPerSide=int((totalRays-1)/2),
    rayMaxDegrees = 30,
    inference=True,
    base_port = random.randint(5000, 6000),
)

Where the value of totalRays is 9. I understand this to mean that the agent will have 4 rays to the left, 4 to the right and one directly ahead. I understand rayMaxDegrees=30 to mean that the rays will be spread out evenly over the 15 degrees to either side of the front of the agent.

If I use the raycast parser to parse the input seen in the first frame (shown approximately in the screenshot) I get:

ARENA : [0.         0.         0.         0.         0.         0.11258327
 0.10553324 0.10093942 0.        ]
IMMOVABLE : [0.00756976 0.00776975 0.00812335 0.00866603 0.00750501 0.
 0.         0.         0.00779   ]
MOVABLE : [0. 0. 0. 0. 0. 0. 0. 0. 0.]
GOODGOAL : [0. 0. 0. 0. 0. 0. 0. 0. 0.]

All the values seem reasonable except the final one in the IMMOVABLE list. This suggests to me that the agent is seeing an immovable block with it's furthest right ray. If I remove the protruding block from the arena (see below image, attached as pitLI-sanitycheck-altered.txt)

image

The agent only sees ARENA

ARENA : [0.09834133 0.10093942 0.10553326 0.11258331 0.0975     0.11258327
 0.10553324 0.10093942 0.09834133]
IMMOVABLE : [0. 0. 0. 0. 0. 0. 0. 0. 0.]
MOVABLE : [0. 0. 0. 0. 0. 0. 0. 0. 0.]
GOODGOAL : [0. 0. 0. 0. 0. 0. 0. 0. 0.]

This indicates that in the previous example the IMMOVABLE object being seen on the far right is the block that was removed.

Questions

To Reproduce Steps to reproduce the behavior: Run the provided configs (they need renaming to .yml files) and inspect the output of the raycast parser

Expected behavior A block is not seen on the far right in the raycast parser output

Version info Running with a version of python AAI pulled from pip in the last few weeks, and the unity version of AAI published on Oct 2, 2023

alhasacademy96 commented 5 months ago

So, lets analyse this:

  1. The total rays are 9 with raysPerSide calculated as: (totalRays-1)/2. This does imply as your conclusion that there are 4 rays on both sides.
  2. The rayMaxDegrees=30 setting means that the total field of view covered by the rays spans 60 degrees, centered on the agent's forward direction. This setup should not cause the rays to wrap around 360 degrees; they should be constrained within this 60-degree arc in front of the agent.
  3. as we know, geometry of your environment can significantly affect raycast results. For instance, if the protruding block is within the field of view of the far-right ray and close enough to the edge of this field, it might only be detected when it's positioned in a way that intersects with the ray's path. This could explain why the block is detected in one configuration and not after its removal.

Potential Misinterpretations or Technical Issues:

Ray Spread calculation: I think we need to ensure that the rays are evenly distributed across the specified arc. Misinterpretation might occur if the rays are not evenly spaced or if the field of view is not properly centered. Raycast parser accuracy: If there's a concern about the raycast parser's accuracy, it's essential to validate how the parser interprets raw raycast data. This involves ensuring that it correctly accounts for the angles and distances of objects detected by each ray. I will conduct a bit more testing on this point to rule this out.

alhasacademy96 commented 5 months ago

Having checked the unity setup, it seems the RAYS PER DIRECTION parameter is set to 3, meaning 7 total rays as opposed to 9. This could be the problem but I don't recall this parameter being modified in any way.

This could indicate the parameter is either overriding or being overridden.

github-actions[bot] commented 4 months ago

This issue is stale because it has been open for 45 days with no activity.