Closed DrTom closed 1 year ago
Nice! To access raw values, you can also just use the existing PUPDevice
class.
Since you can use it in Python, you could fairly easily extend the color sensor class that way without building a custom firmware. https://docs.pybricks.com/en/latest/iodevices/pupdevice.html
You can also experiment with all the modes that way to see what they do.
Would you be interested in a pull request or maybe add this on your behalf to pybricks?
Thanks for offering this. I think we'll stick with the unified HSV
approach across the API, and provide the PUPDevice
class for any customization.
Thanks for pointing to the generic PUBDevice. Here is an example how to read the RGB values (maybe it is useful for somebody in the future):
from pybricks.iodevices import PUPDevice
from pybricks.parameters import Port
PBDRV_LEGODEV_MODE_PUP_COLOR_SENSOR__RGB_I = 5 # read 4x int16_t
color_sensor_device = PUPDevice(Port.F)
r, g, b, _ = color_sensor_device.read(PBDRV_LEGODEV_MODE_PUP_COLOR_SENSOR__RGB_I)
print(r, g, b)
Much easier than building a custom firmware I guess. Getting the proper mode constant might be the trickiest part; e.g. here https://github.com/pybricks/pybricks-micropython/blob/6d1d9050b23a4bdc5ab426a12965b2f69946b7ae/lib/pbio/include/pbdrv/legodev.h#L316
For further experimentation, have a look at the ambient HSV mode :)
We found it valuable to (sometimes) work with raw RGB values instead of HSV/HLS for the following reasons:
Here is a patch https://github.com/DrTom/pybricks-micropython/commit/09b9b161ed3aab4b7865231bc619bd324e452b04 which implements this for the colorsensor provided with the spike sets.
Would you be interested in a pull request or maybe add this on your behalf to pybricks?
As for a PR: I have no idea how good this implementation is. It works though. I have access to the ColorDistanceSensor and could try to extend it for that one, too.