spike package
Subpackages
- spike.scenario package
- Submodules
- spike.scenario.abaqus module
- spike.scenario.commands module
ScenarioCommands
ScenarioCommands.s_shared_timer
ScenarioCommands.__init__()
ScenarioCommands.reset()
ScenarioCommands.configure()
ScenarioCommands.give()
ScenarioCommands.__statuslight_on()
ScenarioCommands.__statuslight_off()
ScenarioCommands.__colorsensor_light_up()
ScenarioCommands.__lightmatrix_show_image()
ScenarioCommands.__lightmatrix_set_pixel()
ScenarioCommands.__lightmatrix_write()
ScenarioCommands.__lightmatrix_off()
ScenarioCommands.__speaker_beep()
ScenarioCommands.__speaker_start_beep()
ScenarioCommands.__speaker_stop()
ScenarioCommands.__speaker_set_volume()
ScenarioCommands.__motorpair_set_stop_action()
ScenarioCommands.__motor_set_stall_detection()
ScenarioCommands.__motor_set_stop_action()
- spike.scenario.components module
ScenarioComponents
ScenarioComponents.s_logger
ScenarioComponents.__init__()
ScenarioComponents.reset()
ScenarioComponents.configure()
ScenarioComponents.register()
ScenarioComponents.update_from_data()
ScenarioComponents.update_from_mecanics()
ScenarioComponents.__register_motor()
ScenarioComponents.__register_motorpair()
ScenarioComponents.__register_colorsensor()
ScenarioComponents.__register_forcesensor()
ScenarioComponents.__register_distancesensor()
ScenarioComponents.__register_button()
ScenarioComponents.__register_lightmatrix()
ScenarioComponents.__register_motion_sensor()
ScenarioComponents.__register_speaker()
ScenarioComponents.__register_statuslight()
ScenarioComponents.__register_timer()
- spike.scenario.data module
- spike.scenario.dynamics module
ScenarioDynamics
ScenarioDynamics.s_shared_timer
ScenarioDynamics.s_logger
ScenarioDynamics.__init__()
ScenarioDynamics.reset()
ScenarioDynamics.configure()
ScenarioDynamics.current()
ScenarioDynamics.move
ScenarioDynamics.start_tank
ScenarioDynamics.move_tank
ScenarioDynamics.start_tank_at_power
ScenarioDynamics.set_degrees_counted()
ScenarioDynamics.run_to_position
ScenarioDynamics.run_to_degrees_counted
ScenarioDynamics.run_for_rotations
ScenarioDynamics.run_for_degrees
ScenarioDynamics.run_for_seconds
ScenarioDynamics.start
ScenarioDynamics.start_at_power
ScenarioDynamics.stop
ScenarioDynamics.extrapolate()
ScenarioDynamics.__compute_motor_speeds_from_steering()
ScenarioDynamics.__update_kinematics()
ScenarioDynamics.__check_pair()
ScenarioDynamics.__check_configuration()
ScenarioDynamics.__modulo_dir()
- spike.scenario.ground module
- spike.scenario.model module
ScenarioModel
ScenarioModel.s_topics
ScenarioModel.s_parts_to_connect
ScenarioModel.s_ports
ScenarioModel.s_logger
ScenarioModel.__init__()
ScenarioModel.configure()
ScenarioModel.altitude()
ScenarioModel.ports()
ScenarioModel.by_port()
ScenarioModel.by_type()
ScenarioModel.all()
ScenarioModel.__check_configuration()
ScenarioModel.__read()
ScenarioModel.__convert_pose()
ScenarioModel.__add_port_to_parts()
ScenarioModel.__organize_parts()
- spike.scenario.parts module
ScenarioPart
ScenarioPartMotor
ScenarioPartMotor.s_speed_abaqus
ScenarioPartMotor.s_ids
ScenarioPartMotor.configure()
ScenarioPartMotor.__init__()
ScenarioPartMotor.reset()
ScenarioPartMotor.speed
ScenarioPartMotor.degrees
ScenarioPartMotor.wheel
ScenarioPartMotor.clockwise
ScenarioPartMotor.export()
ScenarioPartMotor.command()
ScenarioPartMotor.radius()
ScenarioPartMotor.side()
ScenarioPartMotor.is_pairable()
ScenarioPartMotor.extrapolate()
ScenarioPartWheel
ScenarioPartWheel.s_wheel_radius_abaqus
ScenarioPartWheel.s_ids
ScenarioPartWheel.s_sides
ScenarioPartWheel.configure()
ScenarioPartWheel.__init__()
ScenarioPartWheel.side
ScenarioPartWheel.radius
ScenarioPartWheel.speed
ScenarioPartWheel.set_side()
ScenarioPartWheel.export()
ScenarioPartWheel.distance()
ScenarioPartColorSensor
ScenarioPartHub
ScenarioPartForceSensor
ScenarioPartDistanceSensor
- spike.scenario.scenario module
ScenarioThreadData
ScenarioThreadData.s_shared_timer
ScenarioThreadData.s_modes
ScenarioThreadData.s_logger
ScenarioThreadData.__init__()
ScenarioThreadData.reset()
ScenarioThreadData.reinitialize()
ScenarioThreadData.configure()
ScenarioThreadData.register_component()
ScenarioThreadData.is_started()
ScenarioThreadData.step()
ScenarioThreadData.command()
ScenarioThreadData.get_status()
ScenarioThreadData.get_components()
ScenarioThreadData.set_shall_continue()
ScenarioThreadData.shall_continue()
ScenarioThreadData.run()
ScenarioThreadData.__check_configuration()
Scenario
- spike.scenario.timer module
- Module contents
Submodules
spike.colorsensor module
Color sensor mock API
- class spike.colorsensor.ColorSensor(port)
Bases:
object
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
- s_css3_to_spike_colormap = {'aliceblue': 'white', 'antiquewhite': 'white', 'aqua': 'cyan', 'aquamarine': 'cyan', 'beige': 'white', 'black': 'black', 'blue': 'blue', 'blueviolet': 'violet', 'brown': 'red', 'burlywood': 'yellow', 'cadetblue': 'cyan', 'chartreuse': 'green', 'chocolate': 'red', 'coral': 'red', 'cornflowerblue': 'blue', 'crimson': 'red', 'darkblue': 'blue', 'darkcyan': 'cyan', 'darkgray': 'black', 'darkgreen': 'green', 'darkkhaki': 'yellow', 'darkmagenta': 'violet', 'darkorchid': 'violet', 'darkred': 'red', 'darksalmon': 'red', 'darkseagreen': 'green', 'darkslateblue': 'blue', 'darkslategray': 'black', 'darkturquoise': 'cyan', 'darkviolet': 'violet', 'deeppink': 'red', 'deepskyblue': 'blue', 'dimgray': 'black', 'dodgerblue': 'blue', 'firebrick': 'red', 'floralwhite': 'white', 'forestgreen': 'green', 'fuschia': 'violet', 'ghostwhite': 'white', 'gold': 'yellow', 'goldenrod': 'yellow', 'gray': 'black', 'green': 'green', 'greenyellow': 'green', 'honeydew': 'white', 'hotpink': 'red', 'indianred': 'red', 'indigo': 'violet', 'ivory': 'white', 'khaki': 'yellow', 'lavender': 'violet', 'lavenderblush': 'white', 'lawngreen': 'green', 'lemonchiffon': 'yellow', 'lightblue': 'blue', 'lightcoral': 'red', 'lightcyan': 'cyan', 'lightgoldenrodyellow': 'yellow', 'lightgray': 'white', 'lightgreen': 'green', 'lightpink': 'red', 'lightsalmon': 'red', 'lightseagreen': 'cyan', 'lightskyblue': 'blue', 'lightslategray': 'white', 'lightsteelblue': 'blue', 'lightyellow': 'yellow', 'lime': 'green', 'limegreen': 'green', 'linen': 'white', 'magenta': 'violet', 'maroon': 'red', 'mediumaquamarine': 'cyan', 'mediumblue': 'blue', 'mediumorchid': 'violet', 'mediumpurple': 'violet', 'mediumseagreen': 'green', 'mediumslateblue': 'blue', 'mediumspringgreen': 'green', 'mediumturquoise': 'cyan', 'mediumvioletred': 'red', 'midnightblue': 'blue', 'mintcream': 'white', 'mistyrose': 'white', 'moccasin': 'yellow', 'navajowhite': 'white', 'navy': 'blue', 'oldlace': 'white', 'olive': 'green', 'olivedrab': 'green', 'orange': 'yellow', 'orangered': 'red', 'orchid': 'violet', 'palegoldenrod': 'yellow', 'palegreen': 'green', 'paleturquoise': 'cyan', 'palevioletred': 'red', 'papayawhip': 'yellow', 'peachpuff': 'yellow', 'peru': 'yellow', 'pink': 'red', 'plum': 'violet', 'powderblue': 'blue', 'purple': 'violet', 'red': 'red', 'royalblue': 'blue', 'saddlebrown': 'red', 'salmon': 'red', 'seagreen': 'green', 'seashell': 'white', 'sienna': 'red', 'silver': 'black', 'skyblue': 'blue', 'slateblue': 'blue', 'slategray': 'black', 'snow': 'white', 'springgreen': 'green', 'steelblue': 'blue', 'tan': 'yellow', 'teal': 'cyan', 'thistle': 'violet', 'tomato': 'red', 'turquoise': 'cyan', 'violet': 'violet', 'white': 'white', 'whitesmoke': 'white', 'yellow': 'yellow', 'yellowgreen': 'green'}
- s_allowed_colors = {'black', 'blue', 'cyan', 'green', 'red', 'violet', 'white', 'yellow'}
- __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
spike.control module
High resolution timer with a milliseconds resolution emulating spike timer interfaces on standard python
- spike.control.equal_to(a, b)
Default function for wait_until function :meta private:
- class spike.control.Timer
Bases:
object
Timer mocking class
- __init__()
Contructor
- now()
Retrieves the “right now” time of the Timer.
- Returns:
the current time, specified in seconds.
- Return type:
integer
- reset()
Sets the Timer to “0.”
- spike.control.wait_for_seconds(seconds)
Waits for a specified number of seconds before continuing the program.
- Parameters:
seconds (float) – time to wait in seconds
- Raises:
TypeError – seconds is not a number
ValueError – seconds is not at least 0
- spike.control.wait_until(get_value_function, operator_function=<function equal_to>, target_value=True)
Waits until the condition is true before continuing with the program.
- Parameters:
get_value_function (callable) – a function that returns the current value to be compared to the target value.
operator_function (callable) – a function that compares two arguments. The first argument will be the result of get_value_function(), and the second argument will be target_value. The function will compare both values and return the result.
target_value (any type) – any object that can be compared by operator_function.
- Raises:
TypeError – get_value_function or operator_function is not callable or operator_function does not compare two arguments.
spike.distancesensor module
Distance sensor mock API
- class spike.distancesensor.DistanceSensor(port)
Bases:
object
Distance 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
- s_cm_to_inches = 0.39370079
- s_max_distance = 200
- s_max_distance_short_range = 50
- __init__(port)
Contructor
- Parameters:
port (string ('A','B','C','D','E' or 'F')) – the hub port to which the sensor is connected
- get_distance_cm(short_range=False)
Retrieves the measured distance in centimeters.
- Parameters:
short_range (boolean) – whether or not to use short range mode. Short range mode increases accuracy, but it can only detect nearby objects.
- Raises:
TypeError – short_range is not a boolean
- Returns:
The measured distance or “none” if the distance can’t be measured.
- Return type:
float
- get_distance_inches(short_range=False)
Retrieves the measured distance in inches.
- Parameters:
short_range (boolean) – whether or not to use short range mode. Short range mode increases accuracy, but it can only detect nearby objects.
- Raises:
TypeError – short_range is not a boolean
- Returns:
The measured distance or “none” if the distance can’t be measured.
- Return type:
float
- get_distance_percentage(short_range=False)
Retrieves the measured distance as a percentage.
- Parameters:
short_range (boolean) – whether or not to use short range mode. Short range mode increases accuracy, but it can only detect nearby objects.
- Raises:
TypeError – short_range is not a boolean
- Returns:
The measured distance or “none” if the distance can’t be measured.
- Return type:
integer [0,100]
- wait_for_distance_farther_than(distance, unit='cm', short_range=False)
Waits until the measured distance is greater than the specified distance.
- Parameters:
distance (float) – the target distance to be detected from the sensor to an object.
unit (string (cm, in, %)) – the unit in which the distance is measured.
short_range (boolean) – whether or not to use short range mode. Short range mode increases accuracy, but it can only detect nearby objects.
- Raises:
TypeError – distance is not a number or unit is not a string or short_range is not a boolean.
ValueError – unit is not one of the allowed values.
- wait_for_distance_closer_than(distance, unit='cm', short_range=False)
Waits until the measured distance is less than the specified distance.
- Parameters:
distance (float) – the target distance to be detected from the sensor to an object.
unit (string (cm, in, %)) – the unit in which the distance is measured.
short_range (boolean) – whether or not to use short range mode. Short range mode increases accuracy, but it can only detect nearby objects.
- Raises:
TypeError – distance is not a number or unit is not a string or short_range is not a boolean.
ValueError – unit is not one of the allowed values.
- light_up_all(brightness=100)
Lights up all of the lights on the Distance Sensor at the specified brightness.
- Parameters:
brightness (integer [0,100]) – the specified brightness of all of the lights.
- Raises:
TypeError – brightness is not an integer
- light_up(right_top, left_top, right_bottom, left_bottom)
Sets the brightness of the individual lights on the Distance Sensor.
- Parameters:
right_top (integer [0,100]) – the brightness of the light that’s above the right part of the Distance Sensor.
left_top (integer [0,100]) – the brightness of the light that’s above the left part of the Distance Sensor.
right_bottom (integer [0,100]) – the brightness of the light that’s below the right part of the Distance Sensor.
left_bottom (integer [0,100]) – the brightness of the light that’s below the left part of the Distance Sensor.
- Raises:
TypeError – brightness is not an integer
- __get_distance()
Returns current distance in cm
- Returns:
distance in centimeters
- Return type:
float
- __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(distance)
Update the distance from scenario data
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:
distance (float) – distance in centimeters
- c_set_lights(right_top, left_top, right_bottom, left_bottom)
Light distance sensor LEDs
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:
right_top (integer [0,100]) – the brightness of the light that’s above the right part of the Distance Sensor.
left_top (integer [0,100]) – the brightness of the light that’s above the left part of the Distance Sensor.
right_bottom (integer [0,100]) – the brightness of the light that’s below the right part of the Distance Sensor.
left_bottom (integer [0,100]) – the brightness of the light that’s below the left part of the Distance Sensor.
- 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
spike.forcesensor module
Force sensor mock APi
- class spike.forcesensor.ForceSensor(port)
Bases:
object
Force 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
- s_force_for_being_pressed = 2
- s_max_force = 10
- __init__(port)
Contructor
- Parameters:
port (string ('A','B','C','D','E' or 'F')) – the hub port to which the sensor is connected
- wait_until_pressed()
Waits until the Force Sensor is pressed.
- wait_until_released()
Waits until the Force Sensor is released.
- is_pressed()
Tests whether the button on the sensor is pressed.
- Returns:
True if the sensor is pressed, False otherwise
- Return type:
boolean
- get_force_newton()
Retrieves the measured force, in newtons.
- Returns:
the measured force, specified in newtons
- Return type:
float
- get_force_percentage()
Retrieves the measured force as a percentage of the maximum force.
- Returns:
the measured force, given as a percentage.
- Return type:
integer [0,100]
- 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(force)
Update the force from scenario data
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:
force (integer) – force in newton
- 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.
- Parameters:
port (string) – the component port
spike.hub module
Hub mock API
spike.lightmatrix module
Hub light matrix mock API
- class spike.lightmatrix.LightMatrix
Bases:
object
Hub light matrix mocking class
Class is accessed simultaneously by the user side thread and the ground truth update thread. It is therefore protected by a mutex
- s_lightmatrix_images = {'A': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'ANGRY': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'ARROW_E': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'ARROW_N': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'ARROW_NE': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'ARROW_NW': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'ARROW_S': [0, 0, 0,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 0, 0, 0]}
- __init__()
Contructor
- show_image(image, brightness=100)
Shows an image on the Light Matrix.
- Parameters:
image (string (ANGRY, ARROW_E, ARROW_N, ARROW_NE, ARROW_NW, ARROW_S, ARROW_SE, ARROW_SW, ARROW_W, ASLEEP, BUTTERFLY, CHESSBOARD, CLOCK1, CLOCK10, CLOCK11, CLOCK12, CLOCK2, CLOCK3, CLOCK4, CLOCK5, CLOCK6, CLOCK7, CLOCK8, CLOCK9, CONFUSED, COW, DIAMOND, DIAMOND_SMALL, DUCK, FABULOUS, GHOST, GIRAFFE, GO_RIGHT, GO_LEFT, GO_UP, GO_DOWN, HAPPY, HEART, HEART_SMALL, HOUSE, MEH, MUSIC_CROTCHET, MUSIC_QUAVER, MUSIC_QUAVERS, NO, PACMAN, PITCHFORK, RABBIT, ROLLERSKATE, SAD, SILLY, SKULL, SMILE, SNAKE, SQUARE, SQUARE_SMALL, STICKFIGURE, SURPRISED, SWORD, TARGET, TORTOISE, TRIANGLE, TRIANGLE_LEFT, TSHIRT, UMBRELLA, XMAS, YES)) – the name of the image to display
brightness (integer [0,100]) – brightness of the image
- Raises:
TypeError – image is not a string or brightness is not an integer
ValueError – image is not one of the allowed values.
- set_pixel(x, y, brightness=100)
Sets the brightness of one pixel (one of the 25 LEDs) on the Light Matrix.
- Parameters:
x (integer [0,4]) – pixel position, counting from the left.
y (integer [0,4]) – pixel position, counting from the top.
brightness (integer [0,100]) – brightness of the pixel
- Raises:
TypeError – x, y or brightness is not an integer.
ValueError – x, y is not within the allowed range of 0-4.
- write(text)
Displays text on the Light Matrix, one letter at a time, scrolling from right to left. Your program will not continue until all of the letters have been shown.
- Parameters:
text (string) – text to display
- off()
Turns off all of the pixels on the Light Matrix.
- __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_set_pixel(x, y, brightness=100)
Pixel lighting 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.
- Parameters:
x (integer [0,4]) – pixel position, counting from the left.
y (integer [0,4]) – pixel position, counting from the top.
brightness (integer [0,100]) – brightness of the pixel
- c_show_image(image, brightness=100)
Image displaying 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.
- Parameters:
image (string (ANGRY, ARROW_E, ARROW_N, ARROW_NE, ARROW_NW, ARROW_S, ARROW_SE, ARROW_SW, ARROW_W, ASLEEP, BUTTERFLY, CHESSBOARD, CLOCK1, CLOCK10, CLOCK11, CLOCK12, CLOCK2, CLOCK3, CLOCK4, CLOCK5, CLOCK6, CLOCK7, CLOCK8, CLOCK9, CONFUSED, COW, DIAMOND, DIAMOND_SMALL, DUCK, FABULOUS, GHOST, GIRAFFE, GO_RIGHT, GO_LEFT, GO_UP, GO_DOWN, HAPPY, HEART, HEART_SMALL, HOUSE, MEH, MUSIC_CROTCHET, MUSIC_QUAVER, MUSIC_QUAVERS, NO, PACMAN, PITCHFORK, RABBIT, ROLLERSKATE, SAD, SILLY, SKULL, SMILE, SNAKE, SQUARE, SQUARE_SMALL, STICKFIGURE, SURPRISED, SWORD, TARGET, TORTOISE, TRIANGLE, TRIANGLE_LEFT, TSHIRT, UMBRELLA, XMAS, YES)) – the name of the image to display
brightness (integer [0,100]) – brightness of the image
- c_write(text)
Text writing function (letters are displayed one by one)
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:
text (string) – text to display
- c_off()
Shut down all the pixel of the light matrix
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_get_matrix()
Return matrix state
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:
5x5 array containing each pixel state
- Return type:
list
spike.motionsensor module
Hub motion sensor mock API
- class spike.motionsensor.MotionSensor
Bases:
object
Motion 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
- s_gestures = ['shaken', 'tapped', 'doubletapped', 'falling']
- __init__()
Contructor
- get_roll_angle()
Retrieves the Hub’s roll angle. Roll is the rotation around the front-back (longitudinal) axis.
- Returns:
the roll angle, specified in degrees.
- Return type:
integer [-180,180]
- get_pitch_angle()
Retrieves the Hub’s pitch angle. Pitch is the rotation around the left-right (transverse) axis.
- Returns:
the pitch angle, specified in degrees.
- Return type:
integer [-180,180]
- get_yaw_angle()
Retrieves the Hub’s yaw angle. Yaw is the rotation around the front-back (vertical) axis
- Returns:
the yaw angle, specified in degrees.
- Return type:
integer [-180,180]
- reset_yaw_angle()
Sets the yaw angle to “0.”
- get_gesture()
Retrieves the most recently-detected gesture.
- Returns:
last gesture
- Return type:
string
- was_gesture(gesture)
Tests whether a gesture has occurred since the last time was_gesture() was used, or since the beginning of the program (for the first use).
- Parameters:
gesture (string ("shaken","tapped","double-tapped","falling","none")) – the name of the gesture.
- Raises:
ValueError – gesture is not one of the allowed values.
TypeError – gesture is not a string
- Returns:
True if the gesture has occurred since the last time was_gesture() was called, otherwise False.
- Return type:
boolean
- get_orientation()
Retrieves the Hub’s current orientation.
- Returns:
the hub current orientation
- Return type:
string (‘front’,’back’,’up’,’down’,’leftside’,’rightside’)
- wait_for_new_gesture()
Waits until a new gesture happens.
- wait_for_new_orientation()
Waits until the Hub’s orientation changes.
The first time this method is called, it will immediately return the current value. After that, calling this method will block the program until the Hub’s orientation has changed since the previous time this method was called.
- Returns:
the hub new orientation
- Return type:
string (‘front’,’back’,’up’,’down’,’leftside’,’rightside’)
- 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(yaw, pitch, roll, gesture)
Update the current orientation from scenario data
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:
yaw (integer [-180,180]) – the yaw angle, specified in degrees.
pitch (integer [-180,180]) – the pitch angle, specified in degrees.
roll (integer [-180,180]) – the roll angle, specified in degrees.
gesture (string ("shaken","tapped","double-tapped","falling","none")) – the name of the gesture.
- Raises:
ValueError – Invalid gesture
spike.motor module
Motor mock API
- class spike.motor.Motor(port)
Bases:
object
Motor mocking class
Class is accessed simultaneously by the user side thread and the ground truth update thread. It is therefore protected by a mutex
- s_max_speed = 100
- s_max_steering = 100
- s_max_power = 100
- s_min_position = 0
- s_max_position = 359
- s_motor_directions = ['shortest path', 'clockwise', 'counterclockwise']
- s_motor_stop_actions = ['coast', 'hold', 'brake']
- __init__(port)
Contructor
- Parameters:
port (string ('A','B','C','D','E' or 'F')) – the hub port to which the motor is connected
- run_to_position(degrees, direction='shortest path', speed=None)
Runs the motor to an absolute position.
The sign of the speed will be ignored (i.e., absolute value), and the motor will always travel in the direction that’s been specified by the “direction” parameter. If the speed is greater than “100,” it will be limited to “100.”
- Parameters:
degrees (integer [0,359]) – the target position.
direction (string ("Shortest path" could run in either direction, depending on the shortest distance to the target. "Clockwise" will make the motor run clockwise until it reaches the target position. "Counterclockwise" will make the motor run counterclockwise until it reaches the target position.)) – the direction to use to reach the target position.
speed (integer [0,100]. If no value is specified, it will use the default speed that’s been set by set_default_speed().) – the motor’s speed
- Raises:
TypeError – degrees or speed is not an integer or direction is not a string.
ValueError – direction is not one of the allowed values or degrees is not within the range of 0-359 (both inclusive).
- run_to_degrees_counted(degrees, speed=None)
Runs the motor until the number of degrees counted is equal to the value that has been specified by the “degrees” parameter.
The sign of the speed will be ignored (i.e., absolute value), and the motor will always travel in the direction that’s been specified by the “direction” parameter. If the speed is greater than “100,” it will be limited to “100.”
- Parameters:
degrees (integer) – the target degrees counted.
speed (integer [0,100]. If no value is specified, it will use the default speed that’s been set by set_default_speed().) – the motor’s speed
- Raises:
TypeError – degrees or speed is not an integer.
- run_for_degrees(degrees, speed=None)
Runs the motor for a specified number of degrees.
- Parameters:
degrees (integer) – the number of degrees that the motor should run.
speed (integer [-100,100]. If no value is specified, it will use the default speed that’s been set by set_default_speed().) – the motor’s speed
- Raises:
TypeError – degrees or speed is not an integer.
- run_for_rotations(rotations, speed=None)
Runs the motor for a specified number of rotations.
- Parameters:
degrees (float) – the number of rotations that the motor should run.
speed (int [-100,100]. If no value is specified, it will use the default speed that’s been set by set_default_speed().) – the motor’s speed
- Raises:
TypeError – rotations is not a number or speed is not an integer.
- run_for_seconds(seconds, speed=None)
The number of seconds for which the motor should run.
- Parameters:
seconds (float) – the number of rotations that the motor should run.
speed (int [-100,100]. If no value is specified, it will use the default speed that’s been set by set_default_speed().) – the motor’s speed
- Raises:
TypeError – seconds is not a number or speed is not an integer.
- start(speed=None)
Starts running the motor at a specified speed.
The motor will keep moving at this speed until you give it another motor command or when your program ends.
- Parameters:
speed (integer [-100,100]. If no value is specified, it will use the default speed that’s been set by set_default_speed().) – the motor’s speed
- Raises:
TypeError – speed is not an integer.
- stop()
Stops the motor.
What the motor does after it stops depends on the action that’s been set in set_stop_action(). The default value of set_stop_action() is “coast.”
- start_at_power(power)
Starts running the motor at a specified power level.
The motor will keep moving at this speed until you give it another motor command or when your program ends.
- Parameters:
power (int [-100,100].) – power of the motor
- Raises:
TypeError – power is not an integer.
- get_speed()
Retrieves the motor speed.
- Returns:
current motor speed
- Return type:
int [-100,100]
- get_default_speed()
Retrieves the motor default speed.
- Returns:
current motor default speed value
- Return type:
int [-100,100]
- get_position()
Retrieves the motor position. This is the clockwise angle between the moving marker and the zero-point marker on the motor.
- Returns:
the motor’s position.
- Return type:
integer [0,359]
- was_stalled()
Tests whether the motor was stalled.
- Returns:
True if the motor has stalled since the last time was_stalled() was called, otherwise false.
- Return type:
boolean
- was_interrupted()
Tests whether the motor was interrupted.
- Returns:
True if the motor was interrupted since the last time was_interrupted() was called, otherwise false.
- Return type:
boolean
- get_degrees_counted()
Retrieves the number of degrees that have been counted by the motor.
- Returns:
Current counted degrees
- Return type:
integer
- set_default_speed(speed)
Sets the default motor speed. This speed will be used when you omit the speed argument in one of the other methods, such as run_for_degrees. Setting the default speed does not affect any motors that are currently running. It will only have an effect when another motor method is called after this method. If the value of default_speed is outside of the allowed range, the default speed will be set to “-100” or “100” depending on whether the value is negative or positive.
- Parameters:
speed (integer [-100,100]) – the default speed value.
- Raises:
TypeError – default_speed is not an integer
- set_degrees_counted(degrees_counted)
Sets the “number of degrees counted” to the desired value.
- Parameters:
degrees_counted (integer) – new degrees value
- Raises:
TypeError – degrees_counted is not an integer
- set_stall_detection(stop_when_stalled)
Turns stall detection on or off.
Stall detection senses when a motor has been blocked and can t move. If stall detection has been enabled and a motor is blocked, the motor will be powered off after two seconds and the current motor command will be interrupted. If stall detection has been disabled, the motor will keep trying to run and programs will “get stuck” until the motor is no longer blocked.
Stall detection is enabled by default.
- Parameters:
stop_when_stalled (boolean) – choose “true” to enable stall detection or “false” to disable it.
- set_stop_action(action)
Sets the default behavior when a motor stops.
- Parameters:
action (string (coast,brake,hold)) – the desired motor behavior when the motor stops.
- __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(value)
Update the motor from scenario data
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:
value (float) – current motor degrees value
- c_set_stall_detection(stop_when_stalled)
Turns stall detection on or off.
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:
stop_when_stalled (boolean) – True to enable stall detection or False to disable it.
- c_set_stop_action(action)
Sets the default behavior when a motor stops.
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:
action (string (coast,brake,hold)) – the desired motor behavior when the motor stops.
- 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
spike.motorpair module
Motor pair mock API
- class spike.motorpair.MotorPair(left_port, right_port)
Bases:
object
MotorPair mocking class
Class is accessed simultaneously by the user side thread and the ground truth update thread. It is therefore protected by a mutex
- s_cm_to_inches = 0.39370079
- s_max_speed = 100
- s_max_steering = 100
- s_max_power = 100
- s_motorpair_units = ['cm', 'in', 'rotations', 'degrees', 'seconds']
- s_motor_stop_actions = ['hold', 'coast', 'brake']
- __init__(left_port, right_port)
Contructor
- Parameters:
left_port (string ('A','B','C','D','E' or 'F')) – The port on which the left motor is located
right_port (string ('A','B','C','D','E' or 'F')) – The port on which the right motor is located
- move(amount, unit='cm', steering=0, speed=None)
Start both motors simultaneously to move a Driving Base.
Steering = “0” makes the Driving Base go straight. Negative numbers make the Driving Base turn left. Positive numbers make the Driving Base turn right.
The program will not continue until the specified value is reached.
If the value of steering is equal to “-100” or “100,” the Driving Base will perform a rotation on itself (i.e., “tank move”) at the default speed of each motor.
If the value of steering is outside of the allowed range, the value will be set to “-100” or “100,” depending on whether the value is positive or negative.
If speed is outside of the allowed range, the value will be set to “-100” or “100,” depending on whether the value is positive or negative.
If the speed is negative, the Driving Base will move backward instead of forward. Likewise, if the “amount” is negative, the Driving Base will move backward instead of forward. If both the speed and the “amount” are negative, the Driving Base will move forward.
When the specified unit is “cm” or “in,” the “amount” of the unit parameter is equal to the horizontal distance that the Driving Base will travel before stopping. The relationship between the motor rotations and distance traveled can be adjusted by calling set_motor_rotation().
When the “unit” is “rotations” or “degrees,” the “amount” parameter value specifies how much the motor axle will turn before stopping.
When the “unit” is “seconds,” the “amount” parameter value specifies the duration that the motors will run before stopping.
- Parameters:
amount (float) – The quantity to move in relation to the specified unit of measurement.
unit (string (cm,in,rotations,degrees,seconds)) – The unit of measurement specified for the “amount” parameter.
speed (int [-100,100]) – The speed at which the Driving Base will move while performing a curve.
steering (int [-100,100]) – The steering direction (-100 to 100). “0” makes the Driving Base move straight. Negative numbers make the Driving Base turn left. Positive numbers make the Driving Base turn right.
- Raises:
TypeError – amount, left_speed or right_speed is not a number or unit is not a string.
ValueError – unit is not one of the allowed values.
- start(steering=0, speed=None)
Start both motors simultaneously to move a Driving Base.
Steering = “0” makes the Driving Base go straight. Negative numbers make the Driving Base turn left. Positive numbers make the Driving Base turn right.
The program flow is not interrupted. This is most likely interrupted by sensor input and a condition.
If the value of steering is equal to “-100” or “100,” the Driving Base will perform a rotation on itself (i.e., “tank move”) at the default speed of each motor.
If the value of “steering” is outside of the allowed range, the value will be set to “-100” or “100,” depending on whether the value is positive or negative.
If speed is outside of the allowed range, the value will be set to “-100” or “100,” depending on whether the value is positive or negative.
If the speed is negative, the Driving Base will move backward instead of forward. Likewise, if the “amount” is negative, the Driving Base will move backward instead of forward. If both the speed and the “amount” are negative, the Driving Base will move forward.
- Parameters:
speed (int [-100,100]) – The speed at which the Driving Base will move while performing a curve.
steering (int [-100,100]) – The steering direction (-100 to 100). “0” makes the Driving Base move straight. Negative numbers make the Driving Base turn left. Positive numbers make the Driving Base turn right.
- Raises:
TypeError – steering or speed is not an integer
- stop()
Stops both motors simultaneously, which will stop a Driving Base.
The motors will either actively hold their current position or coast freely depending on the option that’s been selected by set_stop_action().
- move_tank(amount, unit='cm', left_speed=None, right_speed=None)
Moves the Driving Base using differential (tank) steering.
The speed of each motor can be controlled independently for differential (tank) drive Driving Bases.
When the specified unit is “cm” or “in,” the “amount” of the unit parameter is equal to the horizontal distance that the Driving Base will travel before stopping. The relationship between the motor rotations and distance traveled can be adjusted by calling set_motor_rotation().
When the “unit” is “rotations” or “degrees,” the “amount” parameter value specifies how much the motor axle will turn before stopping.
When the “unit” is “seconds,” the “amount” parameter value specifies the duration that the motors will run before stopping.
If left_speed or right_speed is outside of the allowed range, the value will be set to “-100” or “100” depending on whether the value is positive or negative.
If one of the speeds (i.e., left_speed or right_speed) is negative, the negative-speed motor will run backward instead of forward. If the “amount” parameter value is negative, both motors will rotate backward instead of forward. If both of the speed values (i.e., left_speed and right_speed) are negative and the “amount” parameter value is negative, both motors will rotate forward.
The program will not continue until the specified value is reached.
- Parameters:
amount (float) – The quantity to move in relation to the specified unit of measurement.
unit (string (cm,in,rotations,degrees,seconds)) – The unit of measurement specified for the “amount” parameter.
left_speed (int [-100,100]) – The speed of the left motor.
right_speed (int [-100,100]) – The speed of the right motor.
- Raises:
TypeError – amount, left_speed or right_speed is not a number or unit is not a string.
ValueError – unit is not one of the allowed values.
- start_tank(left_speed=None, right_speed=None)
Starts moving the Driving Base using differential (tank) steering.
The speed of each motor can be controlled independently for differential (tank) drive Driving Bases.
If left_speed or right_speed is outside of the allowed range, the value will be set to “-100” or “100” depending on whether the value is positive or negative.
If the speed is negative, the motors will move backward instead of forward.
The program flow is not interrupted. This is most likely interrupted by sensor input and a condition.
- Parameters:
left_speed (int [-100,100]) – The speed of the left motor.
right_speed (int [-100,100]) – The speed of the right motor.
- Raises:
TypeError – left_speed or right_speed is not an integer
- start_at_power(power, steering=0)
Starts moving the Driving Base without speed control.
The motors can also be driven without speed control. This is useful when using your own control algorithm (e.g., a proportional line-follower).
If the steering is outside of the allowed range, the value will be set to “-100” or “100” depending on whether the value is positive or negative.
If the power is outside of the allowed range, the value will be set to “-100” or “100” depending on whether the value is positive or negative.
If the power is negative, the Driving Base will move backward instead of forward.
The program flow is not interrupted. This can most likely be interrupted by sensor input and a condition.
- Parameters:
power (int [-100,100]) – The amount of power to send to the motors.
steering (int [-100,100]) – The steering direction (-100 to 100). “0” makes the Driving Base move straight. Negative numbers make the Driving Base turn left. Positive numbers make the Driving Base turn right.
- Raises:
TypeError – steering or power is not an integer
- start_tank_at_power(left_power, right_power)
Starts moving the Driving Base using differential (tank) steering without speed control.
The motors can also be driven without speed control. This is useful when using your own control algorithm (e.g., a proportional line-follower).
If the left_power or right_power is outside of the allowed range, the value will be rounded to “-100” or “100” depending on whether the value is positive or negative.
If the power is a negative value, the corresponding motor will move backward instead of forward.
The program flow is not interrupted. This can most likely be interrupted by sensor input and a condition.
- Parameters:
left_power (int [-100,100]) – The power of the left motor.
right_power (int [-100,100]) – The power of the right motor.
- Raises:
TypeError – left_power or right_power is not an integer
- get_default_speed()
Retrieves the default motor speed. — :return: The motors default speed :rtype: int [-100,100]
- set_motor_rotation(amount, unit='cm')
Sets the ratio of one motor rotation to the distance traveled.
If there are no gears used between the motors and the wheels of the Driving Base, the “amount” is the circumference of one wheel.
Calling this method does not affect the Driving Base if it’s already running. It will only have an effect the next time one of the move or start methods is used.
- Parameters:
amount (float) – The distance that the Driving Base moves when both motors move one rotation each, 17.6 default (5.6 diameter wheel)
unit (string (cm,in)) – The unit of measurement specified for the “amount” parameter.
- Raises:
TypeError – amount is not a number or unit is not a string.
ValueError – unit is not one of the allowed values.
- set_default_speed(speed)
Sets the default motor speed.
If speed is outside of the allowed range, the value will be set to “-100” or “100” depending on whether the value is positive or negative.
Setting the speed will not have any effect until one of the move or start methods is called, even if the Driving Base is already moving.
- Parameters:
speed (int(-100,100)) – The default motor speed.
- Raises:
TypeError – speed is not a number
- set_stop_action(action)
Sets the motor action that will be used when the Driving Base stops.
If the action is “brake,” the motors will stop quickly and be allowed to turn freely.
If the action is “hold,” the motors will actively hold their current position and cannot be turned manually.
If the action is set to “coast,” the motors will stop slowly and can be turned freely.
Setting the “stop” action does not take immediate effect on the motors. The setting will be saved and used whenever stop() is called or when one of the move methods has completed without being interrupted.
- Parameters:
action (string (coast, hold, brake)) – The desired action of the motors when the Driving Base stops.
- Raises:
TypeError – action is not a string
ValueError – action is not one of the allowed values
- __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_set_stop_action(action)
Sets the action to be performed on stop
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:
action (string (coast, hold, brake)) – The desired motor behavior when the motor stops.
- property left
Returns left motor
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:
Left motor port, None if not set
- Return type:
spike.speaker module
Hub speaker mock API
- class spike.speaker.Speaker
Bases:
object
Hub speaker mocking class
Class is accessed simultaneously by the user side thread and the ground truth update thread. It is therefore protected by a mutex
- s_max_volume = 100
- s_min_note = 44
- s_max_note = 123
- __init__()
Contructor
- beep(note=60, seconds=0.2)
Plays a beep on the Hub.
- Parameters:
note (float) – The MIDI note number
seconds (float) – Beep duration in seconds
- Raises:
TypeError – note is not a number or seconds is not a number.
ValueError – note is not within the allowed range of 44-123
- start_beep(note=60)
Starts playing a beep.
The beep will play indefinitely until stop() or another beep method is called.
- Parameters:
note (float) – The MIDI note number
- Raises:
TypeError – note is not a number.
ValueError – note is not within the allowed range of 44-123
- stop()
Stops any sound that is playing.
- get_volume()
Retrieves the value of the speaker volume.
This only retrieves the volume of the Hub, not the programming app.
- Returns:
The speaker volume
- Return type:
int [0,100]
- set_volume(volume)
Sets the speaker volume. If the assigned volume is out of range, the nearest volume (i.e., 0 or 100) will be used instead. This only sets the volume of the Hub, not the programming app.
- Parameters:
volume (int [0,100]) – The new volume percentage.
- Raises:
TypeError – volume is not a number.
- __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_beep(note=60, seconds=0.2)
Plays a beep on the Hub.
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:
note (float) – The MIDI note number
seconds (float) – Beep duration in seconds
- c_start_beep(note=60)
Plays a beep on the Hub.
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:
note (float) – The MIDI note number
- c_stop()
Stops the beep
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_set_volume(volume)
Sets the speaker volume.
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:
volume (int [0,100]) – The new volume percentage.
spike.statuslight module
Hub status light mock API
- class spike.statuslight.StatusLight
Bases:
object
Hub status light mocking class
Class is accessed simultaneously by the user side thread and the ground truth update thread. It is therefore protected by a mutex
- s_status_light_colors = ['azure', 'black', 'blue', 'cyan', 'green', 'orange', 'pink', 'red', 'violet', 'yellow', 'white']
- __init__()
Contructor
- on(color='white')
Sets the color of the light
- Parameters:
color (string) – the light color
- Raises:
TypeError – color is not a string
ValueError – color is not one of the allowed values
- off()
Turns off the light
- __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_on(color)
Switch on 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.
- Parameters:
color (string) – The light color
- c_off()
Switch off 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_get_color()
Returns current color
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 light current color
- Return type:
string
- c_get_status()
Returns current status
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:
True if light is on, false otherwise
- Return type:
string
Module contents
spike API mocking import