A bug in sensor.py file
FrankTianTT opened this issue · comments
Hi, thank you for your brilliant job.
I find a small bug in the class BoxSpaceSensor in sensor.py, as follows
if isinstance(lower_bound, float):
self._lower_bound = np.full(shape, lower_bound, dtype=dtype)
else:
self._lower_bound = np.array(lower_bound)
but in the class BasePositionSensor in robot_sensors.py, the default parameters of constructor are
def __init__(self,
lower_bound: _FLOAT_OR_ARRAY = -100,
upper_bound: _FLOAT_OR_ARRAY = 100,
name: typing.Text = "BasePosition",
dtype: typing.Type[typing.Any] = np.float64) -> None:
"""Constructs BasePositionSensor.
Args:
lower_bound: the lower bound of the base position of the robot.
upper_bound: the upper bound of the base position of the robot.
name: the name of the sensor
dtype: data type of sensor value
"""
super(BasePositionSensor, self).__init__(
name=name,
shape=(3,), # x, y, z
lower_bound=lower_bound,
upper_bound=upper_bound,
dtype=dtype)
So, you know, the result of isinstance(lower_bound, float)
is False
for BasePositionSensor, so BasePositionSensor._lower_bound
become a float, but it should be a list, for example, [x, y, z]
.
So when I add sensor_wrappers.HistoricSensorWrapper(wrapped_sensor=robot_sensors.BasePositionSensor(), num_history=5)
to the sensors, the observation returned by the step
add 15
, but env.observation_space.shape[0]
only add 5
!
I think it should help to correct class BoxSpaceSensor as follows
if isinstance(lower_bound, float) or isinstance(lower_bound, int):
self._lower_bound = np.full(shape, lower_bound, dtype=dtype)
else:
self._lower_bound = np.array(lower_bound)
Thanks again for your outstanding work :)
Thanks for the report. Do you mind creating a pull request?