c4ev3 / EV3-API

EV3-API for Programming the LEGO Mindstorms EV3 in C
http://c4ev3.github.io
GNU General Public License v2.0
70 stars 21 forks source link

Color sensor mode 4 missing #11

Closed Tcm0 closed 4 years ago

Tcm0 commented 6 years ago

The 4th mode of the color sensor "RGB" is not supported. You can use it to read the actual R, G and B values and not only one out of 7 colors. It's also not officially supported by lego but there is a way to use it in the official software: http://mindcuber.com/mindcub3r/mindcub3r.html Monobrick supports it, too: https://github.com/Larsjep/monoev3/blob/release/MonoBrickFirmware/Sensors/EV3ColorSensor.cs

a3f commented 6 years ago

Patches to add this functionality are welcome.

Tcm0 commented 6 years ago

Why is your personal drive to add stuff to this library so low, just asking?

a3f commented 6 years ago

I don't have an EV3.

DanieleBenedettelli commented 5 years ago

Hello. I would like to use C4EV3 with my students to program robots for Robocup Junior, and we need this sensor mode. Has it been added to the API? is there any reference to add it to the library? I tried to understand the ev3_sensor.c code but I miss some firmware background.

Thanks

a3f commented 5 years ago

Hello,

it hadn't been added, but I have taken a look at how ev3dev has done it and created the https://github.com/c4ev3/EV3-API/tree/wip-color-rgb-mode branch, which adds COL_COLOR_RGB, which I think should do what you want (ReadSensor should return a 32 bit integer with 0x00RRGGBB, ReadSensorData should return a pointer to a buffer with uint16_t rgb[3];. As mentioned above, I don't have an EV3 to test (and the API wasn't written by me either), so please test and report back if it works!

l-yc commented 5 years ago

Hi there, I tried out COL_COLOR_RGB but it seems not to work. The returned R-value flips wildly between ~0 and ~200, while the G and B values are stuck at ~100-200. They seem to be unaffected by what the sensor is pointed at.

Not sure if this would be useful but I tried reading calling ReadSensorData to get the raw values as data and parsing it as 8 bytes instead. data[0] now gives a value that seems to correlate with what the sensor is pointed at while other values are either stuck or flipping rapidly between a few values.

Did anyone have any luck getting this to work?

JakubVanek commented 4 years ago

This is now fixed: https://github.com/c4ev3/EV3-API/blob/6a7fe639354cca3fd29b388afa9a025fcd753000/API/sensors/c4ev3_compatibility.c#L95

Tcm0 commented 4 years ago

This is now fixed:

https://github.com/c4ev3/EV3-API/blob/6a7fe639354cca3fd29b388afa9a025fcd753000/API/sensors/c4ev3_compatibility.c#L95

Is it already merged into the main branch?

JakubVanek commented 4 years ago

Yup, the improvement has landed in the master branch (PR #48).

There is now also a more convenient API that can be used for the same purpose:

Tcm0 commented 4 years ago

Nice. I'll close this then.