2. Train

from intelino.trainlib import Train
class trainlib.Train

Synchronous (blocking) version of the intelino train class.

disconnect()

Disconnects from the train and cleans up all resources.

Reconnection of the same blocking train instance is not possible. Create a new instance.

property id: str

Connection ID / address.

property name: str

Advertised name.

property alias: str

User-defined nickname (train alias).

property is_connected: bool
property distance_cm: int
property direction: intelino.trainlib_async.enums.enums.MovementDirection
property speed_cmps: float
property next_split_decision: intelino.trainlib_async.enums.enums.SteeringDecision
drive_at_speed(speed_cmps: Union[int, float], direction: intelino.trainlib_async.enums.enums.MovementDirection = MovementDirection.FORWARD, play_feedback: bool = True) None

Drive with speed control at the given speed in cm/s.

Parameters
  • speed_cmps – Desired speed in cm/s. Possible (drivable) values are 15-75 cm/s. Note: The increment step is 0.9425 cm, so the final desired speed might get adjusted by the train.

  • direction – Movement direction forward, backward, stop etc.

  • play_feedback – Sound and lights.

drive_at_speed_level(speed_level: intelino.trainlib_async.enums.enums.SpeedLevel, direction: intelino.trainlib_async.enums.enums.MovementDirection = MovementDirection.FORWARD, play_feedback: bool = True) None

Start driving at a speed level defined by the train (and green snaps).

Parameters
  • speed_level – 1, 2, 3.

  • direction – Movement direction forward, backward, stop etc.

  • play_feedback – Sound and lights.

stop_driving(play_feedback_type: intelino.trainlib_async.enums.enums.StopDrivingFeedbackType = StopDrivingFeedbackType.MOVEMENT_STOP)

Stop the train.

Parameters

play_feedback_type – Sound and lights.

set_next_split_steering_decision(next_decision: intelino.trainlib_async.enums.enums.SteeringDecision) None

This steering decision is valid for the next split (detected by it’s snaps).

It overrides the snap value (if set) or the random choice.

Parameters

next – The next decision.

set_top_led_color(r: int, g: int, b: int) None

Set the top RGB LED color.

Parameters
  • r (int) – 8bit RGB value for red.

  • g (int) – 8bit RGB value for green.

  • b (int) – 8bit RGB value for blue.

set_headlight_color(front: Optional[Iterable[int]] = None, back: Optional[Iterable[int]] = None)
Set front and back headlight color (for driving). They switch based

on movement direction. To reset colors call without parameters.

Parameters
  • front – Front 8bit RGB value array [red, green, blue].

  • back – Back 8bit RGB value array [red, green, blue].

set_snap_command_feedback(sound: bool, lights: bool)

Set snap command behavior feedback.

Parameters
  • sound (bool) – Sounds on/off.

  • lights (bool) – Blink top LED on/off.

set_snap_command_execution(on: bool)

Enable or disable snap command execution on the train (from BLE API v1.2).

Parameters

on (bool) – Snap command execution on/off.

clear_custom_snap_commands()

Clear user defined custom snap commands stored in the train to avoid collisions in behavior in case we would listen and react to these events.

decouple_wagon(play_feedback: bool = True)

Decouple wagon.

Parameters

play_feedback – Sound and lights.

add_movement_direction_change_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventMovementDirectionChanged], None])
remove_movement_direction_change_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventMovementDirectionChanged], None])
add_low_battery_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventLowBattery], None])
remove_low_battery_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventLowBattery], None])
add_button_press_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventButtonPressDetected], None])
remove_button_press_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventButtonPressDetected], None])
add_snap_command_detection_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventSnapCommandDetected], None])
remove_snap_command_detection_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventSnapCommandDetected], None])
add_snap_command_execution_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventSnapCommandExecuted], None])
remove_snap_command_execution_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventSnapCommandExecuted], None])
add_front_color_change_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventFrontColorChanged], None])
remove_front_color_change_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventFrontColorChanged], None])
add_back_color_change_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventBackColorChanged], None])
remove_back_color_change_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventBackColorChanged], None])
add_split_decision_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventSplitDecision], None])
remove_split_decision_listener(listener: Callable[[trainlib.train.Train, intelino.trainlib_async.messages.TrainMsgEventSplitDecision], None])