spike.colorsensor

Color sensor mock API

Classes

ColorSensor(port)

Color sensor mocking class

class spike.colorsensor.ColorSensor(port)

Color sensor mocking class

Class is accessed simultaneously by the user side thread and the ground truth update thread. It is therefore protected by a mutex

__init__(port)

Contructor

Parameters:

port (string ('A','B','C','D','E' or 'F')) – the hub port to which the sensor is connected

get_color()

Retrieves the detected color of a surface

Returns:

name of the color sensed

Return type:

string

get_ambiant_light()

Retrieves the intensity of the ambient light.

This causes the Color Sensor to change modes, which can affect your program in unexpected ways. For example, the Color Sensor can’t read colors when it’s in ambient light mode.

Returns:

The ambient light intensity.

Return type:

int [0,100]

get_reflected_light()

Retrieves the intensity of the reflected light.

Returns:

The reflected light intensity

Return type:

int [0,100]

get_rgb_intensity()

Retrieves the overall color intensity, and intensity of red, green, and blue

Returns:

red, green, blue and overall intensity

Return type:

tuple ([0,1024],[0,1024],[0,1024],[0,1024])

get_red()

Retrieves the color intensity of red.

Returns:

red intensity

Return type:

integer [0,1024]

get_green()

Retrieves the color intensity of green.

Returns:

green intensity

Return type:

integer [0,1024]

get_blue()

Retrieves the color intensity of blue.

Returns:

blue intensity

Return type:

integer [0,1024]

wait_until_color(color)

Waits until the Color Sensor detects the specified color.

Parameters:

color (string ("black","violet","blue","cyan","green","yellow","red","white")) – the name of the color

wait_for_new_color()

Waits until the Color Sensor detects a new color.

The first time this method is called, it immediately returns the detected color. After that, it waits until the Color Sensor detects a color that’s different from the color that was detected the last time this method was used.

Returns:

the name of the new color

Return type:

string (“black”,”violet”,”blue”,”cyan”,”green”,”yellow”,”red”,”white”)

light_up_all(brightness=100)

Lights up all of the lights on the Color Sensor at the specified brightness.

This causes the Color Sensor to change modes, which can affect your program in unexpected ways. For example, the Color Sensor can’t read colors when it’s in light up mode.

Parameters:

brightness (integer ([0,100%] - "0" is off, and "100" is full brightness.)) – the desired brightness of the lights on the Color Sensor, default = 100

Raises:

TypeError – brightness is not an integer

light_up(light_1, light_2, light_3)

Sets the brightness of the individual lights on the Color Sensor. This causes the Color Sensor to change modes, which can affect your program in unexpected ways. For example, the Color Sensor can’t read colors when it’s in light up mode.

Parameters:
  • light_1 (integer ([0,100%] - "0" is off, and "100" is full brightness.)) – the desired brightness of light 1.

  • light_2 (integer ([0,100%] - "0" is off, and "100" is full brightness.)) – the desired brightness of light 2.

  • light_3 (integer ([0,100%] - "0" is off, and "100" is full brightness.)) – the desired brightness of light 3.

Raises:

TypeError – light_1, light_2, or light_3 is not an integer.

__process_command(command)

Process command until over

Parameters:

command (generator function) – command to process

c_reset()

Reset function

Warning

This function is not part of the spike API. It is provided to update the component from scenario data and shall not be used by the end-user.

c_read(red, green, blue, ambiant, reflected)

Reads color from external source

Warning

This function is not part of the spike API. It is provided to update the component from scenario data and shall not be used by the end-user.

Parameters:
  • red (integer [0,1024]) – red intensity

  • green (integer [0,1024]) – green intensity

  • blue (integer [0,1024]) – blue intensity

  • ambiant (integer [0,1024]) – ambiant intensity

  • reflected (integer [0,1024]) – reflected intensity

c_set_lights(light1, light2, light3)

Lights intensity setter

Warning

This function is not part of the spike API. It is provided to update the component from scenario data and shall not be used by the end-user.

Parameters:
  • light1 (integer [0,100]) – light1 brightness

  • light2 (integer [0,100]) – light2 brightness

  • light3 (integer [0,100]) – light3 brightness

property port

Sets the component connection port

Warning

This function is not part of the spike API. It is provided to update the component from scenario data and shall not be used by the end-user.

Returns:

the component port

Return type:

string