Skip to content

Hamster ​

Instance declaration ​

When you add a Hamster block to the workspace, the following instance declaration is automatically inserted into the Python code:

python
hamster = Hamster(0)
# When there are multiple instances
hamster_1 = Hamster(1)

Parameters ​

NameKindDescriptionRange / TypeDefault
indexDropdown optionInstance number (starting from 0)Integer 0 or greater0

Set wheel speed ​

Determines the wheel speed. The speed ranges from -100 to 100.

set_wheel_speed

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionWheel to controlleft, right, both-
speedInput (block)Wheel speedInteger -100 to 100, 0: stop-

Python ​

python
hamster = Hamster(0)

hamster.set_wheel_speed('both', 50)

Move for a time ​

Moves for the specified time at the current wheel speed.
If the wheel speed has not been set, it moves forward at the default speed.
If wait is checked, execution waits until the movement is complete.

move_time

Parameters ​

NameKindDescriptionRange / TypeDefault
dataInput (block)Time to move (seconds)Real number 0 or greater-
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
hamster = Hamster(0)

# wait = TRUE
hamster.move_time(5, wait=True)
# wait = FALSE
hamster.move_time(0.5, wait=False)

Change wheel speed ​

Changes the wheel speed of Hamster.
The new wheel speed is the current wheel speed plus the speed you enter.
The newly set wheel speed is clamped to the range -100 to 100.

change_speed

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionWheel to controlleft, right, both-
speedInput (block)Amount of speed changeInteger -200 to 200-

Python ​

python
hamster = Hamster(0)

hamster.change_wheel_speed('both', 10)

Stop ​

Stops the movement of Hamster.
The speed of both wheels of Hamster is reset to 0.

stop

Parameters ​

(none)

Python ​

python
hamster = Hamster(0)

hamster.stop()

Move forward one step on the board ​

Moves one step at a time on the board as configured.

grid_move

Parameters ​

(none)

Python ​

python
hamster = Hamster(0)

hamster.grid_move()

Turn once on the board ​

Rotates 90 degrees on the board in the specified direction.

grid_turn

Parameters ​

NameKindDescriptionRange / TypeDefault
directionDropdown optionDirection of rotationleft, right-

Python ​

python
hamster = Hamster(0)

hamster.grid_turn('left')

Trace a line with the sensor ​

Hamster uses its floor sensor to follow a line of a particular color.

trace_mode

Parameters ​

NameKindDescriptionRange / TypeDefault
floorDropdown optionFloor sensor to trace withleft, right, center-
lineDropdown optionLine colorblack, whiteblack

Python ​

python
hamster = Hamster(0)

hamster.trace_line('left', 'black')

Move through an intersection and stop at the next one ​

Hamster moves in the specified direction at an intersection, then keeps moving until it meets the next intersection.
If wait is checked, execution waits until the movement is complete.

trace_until_grid

Parameters ​

NameKindDescriptionRange / TypeDefault
directionDropdown optionDirection to take at the intersectionleft, right, forward, u-turn (uturn)-
lineDropdown optionLine colorblack, whiteblack
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
hamster = Hamster(0)

hamster.trace_intersection('left', 'black', wait=True)

Set line trace speed ​

Sets the line trace speed. The speed ranges from 1 to 10.

set_trace_speed

Parameters ​

NameKindDescriptionRange / TypeDefault
dataInput (block)Line trace speedInteger 1 to 10-

Python ​

python
hamster = Hamster(0)

hamster.set_trace_speed(5)

Stop line tracing ​

Ends the line tracing function of Hamster.

stop_trace

Parameters ​

(none)

Python ​

python
hamster = Hamster(0)

hamster.stop_trace()

Set LED color ​

Sets the LED color.

set_led_color

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionLED to controlleft, right, both-
colorDropdown optionColorblack, blue, green, cyan, red, magenta, yellow, white-

Python ​

python
hamster = Hamster(0)

hamster.set_led_color('both', 'red')

Turn off LED ​

Removes the LED color.

turn_off

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionLED to controlleft, right, bothboth

Python ​

python
hamster = Hamster(0)

hamster.turn_off('both')

Set sound buzz ​

Sets the buzzer sound of Hamster to the specified frequency.
The frequency range that can produce sound is 1.0 Hz to 6553.5 Hz.
If you enter a value outside this range, no buzzer sound is produced.

sound_buzz

Parameters ​

NameKindDescriptionRange / TypeDefault
hzInput (block)Frequency (Hz)Real number 0 to 6553.5-

Python ​

python
hamster = Hamster(0)

hamster.sound_buzz(440)

Play a note ​

Hamster plays the specified note.

sound_note

Parameters ​

NameKindDescriptionRange / TypeDefault
noteDropdown optionNoteDo (C), Do# (C#), Re (D), Re# (D#), Mi (E), Fa (F), Fa# (F#), Sol (G), Sol# (G#), La (A), La# (A#), Si (B)-
octaveDropdown optionOctave1, 2, 3, 4, 5, 6, 74

Python ​

python
hamster = Hamster(0)

hamster.sound_note('D', 5)

Sound off ​

Turns off the sound of Hamster.

sound_off

Parameters ​

(none)

Python ​

python
hamster = Hamster(0)

hamster.sound_off()

Wheel speed value ​

The speed of a particular wheel

wheel_speed

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionWheel to readleft, right-

Python ​

python
hamster = Hamster(0)

hamster.wheel_speed('left')

Proximity sensor value ​

The value of a particular proximity sensor

proximity

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionSensor position to measureleft, right-

Python ​

python
hamster = Hamster(0)

hamster.proximity('left')

Floor sensor value ​

The value of a particular floor sensor

floor

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionSensor position to measureleft, right, center-

Python ​

python
hamster = Hamster(0)

hamster.floor('left')

Gravitational acceleration value ​

The gravitational acceleration value along a particular axis

acceleration

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionAxis to measurex, y, z-

Python ​

python
hamster = Hamster(0)

hamster.acceleration('x')

Brightness sensor value ​

The brightness sensor value

light

Parameters ​

(none)

Python ​

python
hamster = Hamster(0)

hamster.light()

Temperature sensor value ​

The temperature sensor value

temperature

Parameters ​

(none)

Python ​

python
hamster = Hamster(0)

hamster.temperature()

Signal strength value ​

The signal strength

signal_strength

Parameters ​

(none)

Python ​

python
hamster = Hamster(0)

hamster.signal_strength()

Battery voltage ​

The battery voltage

battery

Parameters ​

(none)

Python ​

python
hamster = Hamster(0)

hamster.battery()

Whether the state has changed ​

Whether the state of the robot has changed

state_change

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionKind of state0 to 6 (see the table below)-
unitCondition
0acceleration('x') > 5000
1acceleration('x') < -5000
2acceleration('y') > 5000
3acceleration('y') < -5000
4acceleration('z') > 0
5acceleration('z') < -3000
6proximity('left') > 50 or proximity('right') > 50

Python ​

python
hamster = Hamster(0)

# unit = 0
hamster.acceleration('x') > 5000
# unit = 6
hamster.proximity('left') > 50 or hamster.proximity('right') > 50

Set I/O port input mode ​

Sets the input mode of an I/O port.

io_mode

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionI/O portA ('a'), B ('b'), both-
optionDropdown optionI/O modeanalog_input, digital_input, digital_input_pullup, digital_input_pulldown, analog_input_voltage, servo_output, pwm_output, digital_output-

Python ​

python
hamster = Hamster(0)

hamster.io_mode('both', 'analog_input')

Set I/O port output value ​

Sets the output value of the specified I/O port.

set_output

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionI/O portA ('a'), B ('b'), both-
dataInput (block)Output valueInteger 0 to 180-

Python ​

python
hamster = Hamster(0)

hamster.set_output('both', 90)

Change I/O port output value ​

Changes the output value of the specified I/O port.

change_output

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionI/O portA ('a'), B ('b'), both-
dataInput (block)Amount of output changeInteger-

Python ​

python
hamster = Hamster(0)

hamster.change_output('a', 10)

Open / close the gripper ​

Opens or closes the gripper of Hamster.
Depending on the unit value, one of two methods is called.

gripper

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionActionclose, open-

Python ​

python
hamster = Hamster(0)

# unit = "open"
hamster.open_gripper()
# unit = "close"
hamster.close_gripper()

Set shooter angle ​

Sets and controls the shooter angle. The angle ranges from 0 to 180.

shooter

Parameters ​

NameKindDescriptionRange / TypeDefault
dataInput (block)Shooter angleInteger 0 to 180-

Python ​

python
hamster = Hamster(0)

hamster.shooter(45)

I/O port input value ​

Returns the input value of an I/O port of Hamster.

input

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionI/O portA ('a'), B ('b')-

Python ​

python
hamster = Hamster(0)

hamster.get_input('a')