Skip to content

HamsterS ​

Instance declaration ​

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

python
hamster_s = HamsterS(0)
# When there are multiple instances
hamster_s_1 = HamsterS(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_s = HamsterS(0)

hamster_s.set_wheel_speed('both', 50)

Move a distance ​

Moves the specified distance at the current wheel speed.
If the wheel speed has not been set, it moves forward at the default speed.
If the distance is 0, it keeps moving according to the current wheel speed.
If wait is checked, execution waits until the movement is complete.

move_distance

Parameters ​

NameKindDescriptionRange / TypeDefault
dataInput (block)Distance to moveReal number 0 or greater-
unitDropdown optionDistance unitcm, mm, inchcm
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
hamster_s = HamsterS(0)

hamster_s.move_distance(50, 'cm', wait=True)

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_s = HamsterS(0)

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

Turn in place ​

Sets the direction and angle to rotate in place.
If wait is checked, execution waits until the rotation is complete.

turn_degree

Parameters ​

NameKindDescriptionRange / TypeDefault
directionDropdown optionDirection of rotationleft, right-
dataInput (block)Angle of rotation (degrees)Real number 0 or greater-
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
hamster_s = HamsterS(0)

hamster_s.turn_degree('left', 90, wait=True)

Change wheel speed ​

Changes the wheel speed of HamsterS.
The new wheel speed is the current wheel speed plus the speed you enter.

change_speed

Parameters ​

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

Python ​

python
hamster_s = HamsterS(0)

hamster_s.change_wheel_speed('both', 10)

Stop ​

Stops the movement of HamsterS.

stop

Parameters ​

(none)

Python ​

python
hamster_s = HamsterS(0)

hamster_s.stop()

Is the wheel moving? ​

Returns true if the wheel is moving, and false if it is stopped.

wheel_moving

Parameters ​

(none)

Python ​

python
hamster_s = HamsterS(0)

hamster_s.wheel_moving()

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_s = HamsterS(0)

hamster_s.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_s = HamsterS(0)

hamster_s.grid_turn('left')

Pivot around the pen holder ​

When using the pen holder, sets the pivot point, direction, and angle of rotation.
If wait is checked, execution waits until the rotation is complete.

pivot

Parameters ​

NameKindDescriptionRange / TypeDefault
baseDropdown optionPivot pointleft pen (left_pen), right pen (right_pen), left wheel (left_wheel), right wheel (right_wheel)-
directionDropdown optionDirection of rotationforward, backward-
degreeInput (block)Angle of rotation (degrees)Real number 0 or greater-
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
hamster_s = HamsterS(0)

hamster_s.pivot('left_pen', 'forward', 90, wait=True)

Draw a circle around the pen holder ​

When drawing a circle with the pen holder, sets the pivot point, direction, radius, and angle of rotation.
If wait is checked, execution waits until the rotation is complete.

pivot_circle

Parameters ​

NameKindDescriptionRange / TypeDefault
baseDropdown optionPivot pointleft pen (left_pen), right pen (right_pen)-
directionDropdown optionDirection of rotationleft forward (left_forward), left backward (left_backward), right forward (right_forward), right backward (right_backward)-
degreeInput (block)Angle of rotation (degrees)Real number 0 or greater-
radiusInput (block)Radius of rotationReal number 0 or greater-
unitDropdown optionRadius unitcm, mm, inchcm
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
hamster_s = HamsterS(0)

hamster_s.pivot_circle('left_pen', 'left_forward', 90, 1, 'cm', wait=True)

Trace a line with the sensor ​

HamsterS 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_s = HamsterS(0)

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

Move through an intersection and stop at the next one ​

HamsterS 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 intersectionturn left (left), turn right (right), move forward (forward), u-turn (uturn)-
lineDropdown optionLine colorblack, whiteblack
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
hamster_s = HamsterS(0)

hamster_s.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_s = HamsterS(0)

hamster_s.set_trace_speed(5)

Set line trace gain ​

Sets the amount by which the line trace direction changes. The gain ranges from 1 to 10.

set_trace_gain

Parameters ​

NameKindDescriptionRange / TypeDefault
dataInput (block)Amount of direction changeInteger 1 to 10-

Python ​

python
hamster_s = HamsterS(0)

hamster_s.set_trace_gain(5)

Stop line tracing ​

Ends the line tracing function of HamsterS.

stop_trace

Parameters ​

(none)

Python ​

python
hamster_s = HamsterS(0)

hamster_s.stop_trace()

Set LED color ​

Sets the LED color of HamsterS.
When you pick a color from the color palette, it is converted to a color name (an English string) for the call. (The generated code uses a color name, not R, G, B numeric values.)

set_led_color

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionLED to controlleft, right, both-
colorColorPick from the color palette → converted to a color name (English)Color names: 'black', 'red', 'yellow', 'green', 'cyan', 'blue', 'magenta', 'white'-

Python ​

python
hamster_s = HamsterS(0)

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

Set LED color with a Color category block ​

Takes a Color category block ([R, G, B]) as input and sets the LED color.

set_led_color_with_block

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionLED to controlleft, right, both-
dataInput (color)A Color category block or an [R, G, B] array[0~255, 0~255, 0~255]-

Python ​

python
hamster_s = HamsterS(0)

hamster_s.set_led_color('both', *Utils.color_rgb(255, 128, 0))

Change LED color by RGB ​

Changes the LED color of HamsterS by the specified R, G, and B amounts.

change_by_rgb

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionLED to controlleft, right, both-
rInput (field)Amount of red changeInteger -255 to 2550
gInput (field)Amount of green changeInteger -255 to 2550
bInput (field)Amount of blue changeInteger -255 to 2550

Python ​

python
hamster_s = HamsterS(0)

hamster_s.change_led_color('both', 10, 0, 0)

Turn off LED ​

Removes the LED color.

turn_off

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionLED to controlleft, right, bothboth

Python ​

python
hamster_s = HamsterS(0)

hamster_s.turn_off('both')

Set sound buzz ​

Sets the buzzer sound of HamsterS to the specified frequency.
The frequency range that can produce sound is 122.1 Hz to 4186.0 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 122.1 to 4186.0 (0 otherwise)-

Python ​

python
hamster_s = HamsterS(0)

hamster_s.sound_buzz(440)

Play a note ​

HamsterS 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 optionOctave3, 4, 5, 6, 74

Python ​

python
hamster_s = HamsterS(0)

hamster_s.sound_note('D', 5)

Play a sound clip ​

HamsterS plays a particular sound clip.
If wait is checked, execution waits until playback is complete.

sound_clip

Parameters ​

NameKindDescriptionRange / TypeDefault
clipDropdown optionSound clip name'mute', 'beep', 'siren', 'engine', 'robot', 'march', 'birthday', 'happy', 'angry', 'sad', and so on-
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

python
hamster_s = HamsterS(0)

hamster_s.sound_clip('siren', wait=True)

Sound off ​

Turns off the sound of HamsterS.

sound_off

Parameters ​

(none)

Python ​

python
hamster_s = HamsterS(0)

hamster_s.sound_off()

Is a sound playing? ​

Returns true if a sound is playing, and false if it is not.

sound_playing

Parameters ​

(none)

Python ​

python
hamster_s = HamsterS(0)

hamster_s.sound_playing()

Wheel speed value ​

The speed of a particular wheel

wheel_speed

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionWheel to readleft, right-

Python ​

python
hamster_s = HamsterS(0)

hamster_s.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_s = HamsterS(0)

hamster_s.proximity('left')

Floor sensor value ​

The value of a particular floor sensor

floor

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionSensor position to measureleft, right-

Python ​

python
hamster_s = HamsterS(0)

hamster_s.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_s = HamsterS(0)

hamster_s.acceleration('x')

Brightness sensor value ​

The brightness sensor value

light

Parameters ​

(none)

Python ​

python
hamster_s = HamsterS(0)

hamster_s.light()

Temperature sensor value ​

The temperature sensor value

temperature

Parameters ​

(none)

Python ​

python
hamster_s = HamsterS(0)

hamster_s.temperature()

Signal strength value ​

The signal strength

signal_strength

Parameters ​

(none)

Python ​

python
hamster_s = HamsterS(0)

hamster_s.signal_strength()

Battery voltage ​

The battery voltage

battery

Parameters ​

(none)

Python ​

python
hamster_s = HamsterS(0)

hamster_s.battery()

Whether the state has changed ​

Whether the state of the robot has changed

state_change

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionKind of state0 to 7 (see the table below)-
unitMeaningPython
0Tilt forwardacceleration('x') > 5000
1Tilt backwardacceleration('x') < -5000
2Tilt leftacceleration('y') > 5000
3Tilt rightacceleration('y') < -5000
4Upside downacceleration('z') > 0
5Not upside downacceleration('z') < -3000
6Obstacle / hand detectedproximity('left') > 50 or proximity('right') > 50
7Tappedtap()

Python ​

python
hamster_s = HamsterS(0)

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

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_s = HamsterS(0)

hamster_s.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_s = HamsterS(0)

hamster_s.set_output('a', 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_s = HamsterS(0)

hamster_s.change_output('a', 10)

Open / close the gripper ​

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

gripper

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionActionopen, close-

Python ​

python
hamster_s = HamsterS(0)

# unit = "open"
hamster_s.open_gripper()
# unit = "close"
hamster_s.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_s = HamsterS(0)

hamster_s.shooter(45)

I/O port input value ​

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

input

Parameters ​

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

Python ​

python
hamster_s = HamsterS(0)

hamster_s.get_input('a')