How to get RGB values using MATLAB LEGO Mindstorms EV3 color sensor?

6 visualizaciones (últimos 30 días)
Amanda Bsaibes
Amanda Bsaibes el 12 de Mzo. de 2016
Comentada: Katie Red el 1 de Mzo. de 2018
I know that readColor() will output the color that is read from the color sensor but I was wondering if there is any way to output the actual RGB values that is read.

Respuestas (1)

Matthew Kuo
Matthew Kuo el 21 de Abr. de 2016
Yes! Go to the folder C:\MATLAB\SupportPackages\R2015a\legomindstormsev3io\toolbox\realtime\targets\ev3io. Yours may be slightly different depending on where you installed it and what version of Matlab you have. Open colorSensor.m and scroll down until you see
methods (Hidden = true)
result = readColorRGB(obj,format)
Delete the line that says (Hidden = true). Now when you call readColorRGB, you will get a struct with the RGB values. For example:
result = readColorRGB(mycolorsensor);
% result(1) is the red value, result(2) is the green value, result(3) is the blue value
  2 comentarios
Deepansh Bhatia
Deepansh Bhatia el 1 de Mzo. de 2018
Hey! I was looking for this solution, and I went to the colorSensor.m file but I found this:
methods (Static, Hidden = true)
% convert color ID to string
function result = convertColorID(id)
switch id
case 0
result = 'none';
case 1
result = 'black';
case 2
result = 'blue';
case 3
result = 'green';
case 4
result = 'yellow';
case 5
result = 'red';
case 6
result = 'white';
case 7
result = 'brown';
otherwise
result = 'none';
end
end
end %END of static methods
What exactly do I delete in order to get RGB values? Thanks.
Katie Red
Katie Red el 1 de Mzo. de 2018
It should be line 89 . I found the same thing you found at first . It's there .

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Support Package for LEGO MINDSTORMS EV3 Hardware en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by