#Robotics Using the EV3 Colour Sensor in RGB mode


David Meego - Click for blog homepageThis fourth article covers a really cool trick for working with the EV3 colour sensor. It resolves a couple of issues that I discovered when I first started working with Lego Mindstorms EV3.

The Robocup Junior Australia Rescue competition uses tiles to create the line following course. The starting point for the tiles is the Robocup Junior Rescue Field mat from Modern Teaching Aids which can be used whole or cut into 15 tiles.

While the NXT colour sensor in colour mode was very forgiving with its colour detection (for green in particular), the EV3 colour sensor was less forgiving and would not always return green when looking at the green shortcut squares on the course tiles. The issue was that Lego made the EV3 sensor very good at identifying the Lego colours, but it was now less accurate for other shades of the colours.

The other issue was using brightness mode for line following and then having to swap to colour mode to look for shortcuts. The NXT colour sensor could not swap quickly between modes, and even though the EV3 sensor can swap faster between modes, having the sensor flickering continuously between modes is not optimal.

While researching for a solution, I found about the MindCub3r for Lego Mindstorms EV3. So, why would a Rubik’s Cube solving robot be important? Well, it needed to be able to identify non Lego colours so it could read the colours from the cube. To achieve this they created a custom block which enables an additional “hidden” mode on the sensor that allows the Red, Green and Blue colour values to be returned. This RGB mode allows your program to decide what ranges of RGB values are needed to identify each colour.

Using this RGB mode allows you to select a single colour to use for line following (as per Reflected Light mode) and at the same time be able to see colours (as per Colour mode but more flexible).

EV3 Basic natively has support for this RGB mode and so you can use it without needing anything additional installed.

Below are some examples based on the Two Sensor simple line follower from the previous article:

The examples are for a Lego Mindstorms robot with the motors plugged into ports B & C and the sensors plugged into ports 1 & 3. They are using the red value to control the line following.

EV3

Note: The three values returned by the custom block range between 0 and 255 and you will need to take readings and adjust your trigger points accordingly.

EV3 Basic

'  ** Simple Bot 2 **

'  By David Musgrave

'  http://WinthropDC.com

'  Last Modified: 13-Jul-2017

' ** Setup Starts Here *******************************************************************************************************

' Initialise Variables
Clicks = ""
Finished = "False"
Left  = Vector.Init(3,0)
Right = Vector.Init(3,0)

' ** Main Program Starts Here *******************************************************************************************************

Sensor.SetMode(1, 4) '  Color to RGB
Sensor.SetMode(3, 4) '  Color to RGB

' Program Main Loop
Finished = "False"
While Finished = "False"
  ' Read sensors
  Left  = Sensor.ReadRaw(1, 3)
  Right = Sensor.ReadRaw(3, 3)

  If Left[0] >= 100 Then
    If Right[0] >= 100 Then
      Motor.StartSync("BC", 50, 50)
    Else
      Motor.StartSync("BC", -25, 50)
    EndIf
  Else
    If Right[0] >= 100 Then
      Motor.StartSync("BC", 50, -25)
    Else
      Motor.Stop("BC", "True")
    EndIf
  EndIf

  ' Check for Button
  Clicks = Buttons.GetClicks()
  If Text.IsSubText(Clicks, "E") Then
    Finished = "True"
  EndIf
EndWhile ' Finished

' End Program
Motor.Stop("BC", "True")

Note: The three raw values returned from the sensor will be approximately in the range from 0 to 800 and you will need to take readings and adjust your trigger points accordingly.

Language Support

The custom block from Mindcuber.com only is set up for the Language English-US. If you install it and it says that the display name is missing when you point at the block in the toolbar, copy the English-US text for the language you need.  For example to get it to work for English-UK (GB):

Locate the ColorSensorRGB folder in one of the locations below (depending on version of the software installed – Education or Home):

C:\Program Files (x86)\LEGO Software\LEGO MINDSTORMS Edu EV3\Resources\Blocks\ColorSensorRGB

C:\Program Files (x86)\LEGO Software\LEGO MINDSTORMS Home EV3\Resources\Blocks\ColorSensorRGB

In both the help and strings folders, copy the en-US folder and rename it to the appropriate name for your language, in this case en-GB.

If you are unsure what to name the folder, have look in the Blocks\LEGO\strings folder to see what language your current installation is using.

More Information

For more information on robotics and the EV3 Basic extensions to Microsoft Small Basic, check out the following links:

In the next article, we will discuss how to use the Mindsensors Sensor Multiplexer with EV3 Basic.

Enjoy

David

This article was originally posted on http://www.winthropdc.com/blog.

Advertisements

Please post feedback or comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s