ll7 / robot_sf_ll7

robot_sf in the ll7 namespace.
GNU General Public License v3.0
1 stars 1 forks source link

'NoneType' object has no attribute 'robot_action' #27

Open ll7 opened 5 months ago

ll7 commented 5 months ago
python scripts/debug_random_policy.py 
2024-05-29 09:44:18.757 | INFO     | robot_sf.render.sim_view:__post_init__:86 - Initializing the simulation view.
Traceback (most recent call last):
  File "/workspaces/robot_sf_ll7/scripts/debug_random_policy.py", line 34, in <module>
    benchmark()
  File "/workspaces/robot_sf_ll7/scripts/debug_random_policy.py", line 11, in benchmark
    env.render()
  File "/workspaces/robot_sf_ll7/robot_sf/gym_env/robot_env.py", line 206, in render
    self.sim_ui.render(state)
  File "/workspaces/robot_sf_ll7/robot_sf/render/sim_view.py", line 253, in render
    self._add_text(state.timestep, state)
  File "/workspaces/robot_sf_ll7/robot_sf/render/sim_view.py", line 389, in _add_text
    f'RobotAction: {state.action.robot_action}',
AttributeError: 'NoneType' object has no attribute 'robot_action'
ll7 commented 5 months ago

The error message 'NoneType' object has no attribute 'robot_action' suggests that state.action is None at the time when state.action.robot_action is being accessed.

To fix this issue, you should add a check to ensure that state.action is not None before trying to access its robot_action attribute. Here's a proposed fix:

# Before
f'RobotAction: {state.action.robot_action}',

# After
f'RobotAction: {state.action.robot_action if state.action is not None else "None"}',

This change will print "None" for the RobotAction if state.action is None, preventing the AttributeError.

If state.action should not be None at this point in your code, you may have a bug elsewhere that is causing state.action to be None. In that case, you should debug your code to find out why state.action is None.