Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical bug in RGBSensor where the nbit_max attribute was not properly initialized, causing it to inherit the incorrect default value from the parent Sensor class (1023 for 10-bit) instead of computing the value based on the configured bit depth from the sensor configuration file.
Key Changes:
- Added explicit initialization of
self.nbit_max = 2**self.bit - 1inRGBSensor.__init__()after reading the bit depth from the config file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| self.res = config["sensor_res"] | ||
| self.pixel_size = 2 / math.sqrt(self.res[0] ** 2 + self.res[1] ** 2) | ||
| self.bit = config["bit"] | ||
| self.nbit_max = 2**self.bit - 1 |
There was a problem hiding this comment.
Remove trailing whitespace at the end of this line.
| self.res = config["sensor_res"] | ||
| self.pixel_size = 2 / math.sqrt(self.res[0] ** 2 + self.res[1] ** 2) | ||
| self.bit = config["bit"] | ||
| self.nbit_max = 2**self.bit - 1 |
There was a problem hiding this comment.
Consider adding a test to verify that RGBSensor correctly initializes nbit_max based on the bit depth from the config file. For example, a test could create an RGBSensor with a 14-bit config and verify that self.nbit_max equals 16383 (2^14 - 1) instead of the default 1023 (2^10 - 1). This would prevent regression of this critical bug.
Fix critical bug where
RGBSensordoes not initializeself.nbit_max, causing it to inherit the incorrect default value from the parentSensorclass (1023 for 10-bit instead of the configured bit depth).