matrx-software / matrx

Human-Agent Teaming Rapid Experimentation Software
https://www.matrx-software.com
MIT License
10 stars 3 forks source link

Navigator `get_all_waypoints` does not return updated waypoints #316

Closed thaije closed 2 years ago

thaije commented 2 years ago

Describe the bug Calling navigator.get_upcoming_waypoints() returns the waypoints still to navigate to, however this list is not updated with regards to the current agent location. So they are atleast 1 tick old. This is the same for navigator.get_upcoming_waypoints() and navigator.get_current_waypoint().

The reason for this is that the agent location and waypoints are only updated here in the __get_route function which is only called by the get_move_action function.

So if you fetch the next move action everything is good, but calling any of the navigator functions returns old information.

To Reproduce Run a scenario with a navigating agent (such as the example simple case, and call navigator.get_upcoming_waypoints() before the navigator.get_move_action() in the agent.

Expected behavior get_upcoming_waypoint and other functions should return up to date info.

Additional context A temporary workaround is to call the function yourself, e.g. something like this:

# in your (custom) agent 

def initialize(self): 
    ... 
    self.navigator = Navigator(....)
    ...

def decide_on_action(self, state):
    ....
navigator = 
# manually update the waypoints, temp workaround
agent_location = self.agent_properties["location"]
self.navigator._Navigator__update_waypoints(agent_location)

# get the upcoming waypoints
for wp in self.navigator.get_upcoming_waypoints():
            print(wp [1])

action = self.navigator.get_move_action(self.state_tracker)
thaije commented 2 years ago

This is fixed. It did require a small change in how the get_current_waypoint, get_upcoming_waypoints, and get_all_waypoints navigator functions are used. From now in they require the self.state_tracker to be passed as a parameter as well, like so:

def decide_on_action(self, state):
    # new is the self.state_tracker that is required for this function. 
    upcoming_waypints = self.navigator.get_upcoming_waypoints(self.state_tracker)

    move_action = self.navigator.get_move_action(self.state_tracker)
    return move_action, {"action_duration": self.move_speed}

These functions are still available without passing the state_tracker but it throws a DeprecationWarning. Reason for the warning and not just throwing an error is because this bug will be fixed in a new minor release of MATRX and thus should not break anyone's code outright.