Documentation > nControl > API Reference
Introduction
The train control tile communicates with the 4DBrix WiFi train controller.
It does not support custom scripts but you can control the train by calling train control tile functions from the event scripts of other tiles, for example: as sensor tile can make a train stop when it detects it.
Event Scripts
Train control tiles support the following event scripts:
API Functions
Tile Specific Functions
nTrainControlTile.clickTile(zone)
Simulates a mouse click on the tile; this executes the mouse click event script.
The argument zone specifies the mouse click zone where the virtual click appeared:
nTrainControlTile.getDirection()
Returns direction in which the train is going:
nTrainControlTile.getLastPower()
Returns the motor power before it was changed the last time; expressed in percentage [0-100].
This function can, for example, be used to get what the motor power was before you stopped the train.
nTrainControlTile.getLightState()
Returns the status of the lights:
nTrainControlTile.getMessageData()
Returns the contents of the MQTT message.
nTrainControlTile.getMessageTopic()
Returns the topic of the MQTT message.
nTrainControlTile.getPower()
Returns the current motor power, expressed in percentage [0-100].
nTrainControlTile.goBackward(power)
Makes the train go backward using the specified motor power. The power is expressed in percentage: [0-100].
nTrainControlTile.goForward(power)
Makes the train go forward using the specified motor power. The power is expressed in percentage: [0-100].
nTrainControlTile.goRandom(power, forward=1, backward=1)
Makes the train go in a random direction using the specified motor power.
nTrainControlTile.sendCommand(portId, command)
Sends a serial command to an auxiliary device.
nTrainControlTile.setPort(portId, mode, baud=38400)
Configures the auxiliary devices ports.
nTrainControlTile.setPower(power)
Sets the current motor power, expressed in percentage [0-100].
nTrainControlTile.setPowerRandom(lower=0, upper=100, step=1)
Sets the current motor power to a random value:
nTrainControlTile.soundHorn()
Plays the tile's horn sound.
nTrainControlTile.stop(reversePower = 0, duration = 0)
Makes the train stop.
Inherited from nTile
nTrainControlTile.clearScreen() Clear all the text in the console window. nTrainControlTile.getTile(label) Returns the tile object specified by label. If there is no tile with the specified label, the function returns a None value. nTrainControlTile.print(text) Prints text in the console window. If the console window it not yet visible, printing text will make it visible. nTrainControlTile.showConsole(mode) Shows (mode = True) or hides (mode = False) the console window. nTrainControlTile.sleep(duration) Stops the execution of the script for the the given number of seconds. Note that duration can be a floating point number, e.g. to suspend the script for half a seconds use self.sleep(0.5). nTrainControlTile.timestamp() Returns the number of seconds that passed since nControl™ was launched. It returns a floating point value with the highest possible time resolution supported by your system. The difference between two time stamps provides the number of seconds elapsed between those two events. nTrainControlTile.localVars Base property to which you can add local variables that retain their value after the event script finishes. For example self.localVars.myVar = 5 adds a new property myVar to self.localVars and gives it the value 5. The localVars property is local to the current tile meaning that each tile has its own independent localVars property. nTrainControlTile.globalVars Base property to which you can add global variables that retain their value after the event script finishes. For example self.globalVars.myVar = 5 adds a new property myVar to self.globalVars and gives it the value 5. The globalVars property is global to nControl meaning that all tiles use the same globalVars property. As such globalVars can be used to exchange information between the tiles. |