-
Notifications
You must be signed in to change notification settings - Fork 122
Textly
The Expression block in Open Roberta Lab allows users to write complex expressions directly in text format using the TextlyJava language, enhancing the versatility of programming in Open Roberta Lab.
To access the Expression block in Open Roberta Lab, press Ctrl + 4 (or Strg + 4 for German keyboards).Once the block appears, users can write any expression and either generate the corresponding code or run a simulation using the available options in Open Roberta Lab.
The Expression block includes a combo box that allows users to select the appropriate data type for their expression. The available data types depend on the robot being used. For example, for the Microbitv2, users can choose from specific options tailored to that device. Selecting the correct data type ensures compatibility with other blocks and operations in Open Roberta Lab.
Consider the mathematical expression:
While this expression could be represented using multiple NEPO blocks, using the Expression block allows for a faster textual representation:
sqrt(a^2 + b^2 - 2*a*b * cos(gamma))
For example, given:
- a = 5
- b = 7
- gamma =
$$\frac{\pi}{3} $$
To compute the value of ( c ) using the Law of Cosines, the corresponding NEPO program representation is as follows: When utilizing the EvalExpr block for a textual expression, the representation of the equation is:
TextlyJava is a flexible expression language used for programming robots and handling a variety of tasks like arithmetic operations, logic, image manipulations, and robot-specific commands. This guide will introduce how to use various types of expressions supported by TextlyJava.
Expressions in TextlyJava represent programmable blocks of various types, such as:
- Numbers
- Strings
- Booleans
- Connections
- Colors
- Images
- Arrays of these types
Each expression can perform arithmetic, logical operations, and string manipulations, with specialized expressions for specific robots.
Block (Image) | Textly Representation | Example |
---|---|---|
expr && expr |
a && b |
|
expr || expr |
a || b |
|
expr == expr |
a == b |
|
expr != expr |
a != b |
|
expr > expr |
a > b |
|
expr < expr |
a < b |
|
expr >= expr |
a >= b |
|
expr <= expr |
a <= b |
|
expr ? expr : expr |
a == b ? x : y |
|
!expr |
!a |
|
true |
true |
|
false |
false |
|
null |
null |
Block (Image) | Textly Representation | Example |
---|---|---|
expr + expr |
a + b |
|
expr - expr |
a - b |
|
expr * expr |
a * b |
|
expr / expr |
a / b |
|
expr ^ expr |
a ^ b |
|
expr % expr |
a % b |
|
- expr |
-a |
|
sin(expr) |
sin(90) |
|
cos(expr) |
cos(90) |
|
tan(expr) |
tan(45) |
|
asin(expr) |
asin(1) |
|
acos(expr) |
acos(1) |
|
atan(expr) |
atan(1) |
|
exp(expr) |
exp(1) |
|
square(expr) |
square(2) |
|
sqrt(expr) |
sqrt(4) |
|
abs(expr) |
abs(-10) |
|
log10(expr) |
log10(100) |
|
log(expr) |
log(10) |
|
randomInt(expr, expr) |
randomInt(1, 100) |
|
randomFloat() |
randomFloat() |
|
randomItem(ListExpression) |
randomItem(ListExpression) |
|
floor(expr) |
floor(3.14) |
|
ceil(expr) |
ceil(3.14) |
|
round(expr) |
round(3.5) |
|
isEven(expr) |
isEven(2) |
|
isOdd(expr) |
isOdd(3) |
|
isPrime(expr) |
isPrime(7) |
|
isWhole(expr) |
isWhole(3) |
|
isPositive(expr) |
isPositive(10) |
|
isNegative(expr) |
isNegative(-5) |
|
isDivisibleBy(expr, expr) |
isDivisibleBy(10, 5) |
|
sum(ListExpression) |
sum(ListExpression) |
|
max(ListExpression) |
max(ListExpression) |
|
min(ListExpression) |
min(ListExpression) |
|
average(ListExpression) |
average(ListExpression) |
|
median(ListExpression) |
median(ListExpression) |
|
stddev(ListExpression) |
stddev(ListExpression) |
|
constrain(expr, expr, expr) |
constrain(50, 0, 100) |
|
castToString(expr) |
castToString(123) |
|
castToChar(expr) |
castToChar(65) |
|
phi |
phi |
|
pi |
pi |
|
e |
e |
|
sqrt2 |
sqrt2 |
|
sqrt_1_2 |
sqrt_1_2 |
|
inf |
inf |
-
ListExpression: In all examples where
ListExpression
is used, it refers to a predefined list of numbers. In TextlyJava, you can only work with predefined lists, so you need to defineListExpression
beforehand. An example of a predefined list could be:
textly ListExpression = [1, 2, 3, 4, 5]
Block (Image) | Textly Representation | Example |
---|---|---|
"String" |
"Hello World" |
|
createTextWith(expr, expr, ...) |
createTextWith("Hello", " ", "World") |
|
castToNumber(expr) |
castToNumber("123") |
|
castStringToNumber(expr) |
castStringToNumber("HelloWorld", 1) |
Block (Image) | Textly Representation | Example |
---|---|---|
[expr, expr, ...] |
[1, 2, 3, 4, 5] |
|
createListWith(expr, expr, ...) |
createListWith(1, 5) |
|
createEmptyList(Type of list) |
createEmptyList(Number) |
|
size(ListExpression) |
size(ListExpression) |
|
isEmpty(ListExpression) |
isEmpty(ListExpression) |
|
indexOfFirst(ListExpression, expr) |
indexOfFirst(ListExpression, 2) |
|
indexOfLast(ListExpression, expr) |
indexOfLast(ListExpression, 3) |
|
get(ListExpression, index) |
get(ListExpression, 0) |
|
getFromEnd(ListExpression, index) |
getFromEnd(ListExpression, 1) |
|
getFirst(ListExpression) |
getFirst(ListExpression) |
|
getLast(ListExpression) |
getLast(ListExpression) |
|
getAndRemove(ListExpression, index) |
getAndRemove(ListExpression, 1) |
|
getAndRemoveFromEnd(ListExpression, index) |
getAndRemoveFromEnd(ListExpression, 1) |
|
getAndRemoveFirst(ListExpression) |
getAndRemoveFirst(ListExpression) |
|
getAndRemoveLast(ListExpression) |
getAndRemoveLast(ListExpression) |
|
subList(ListExpression, from, to) |
subList(ListExpression, 1, 3) |
|
subListFromIndexToLast(ListExpression, index) |
subListFromIndexToLast(ListExpression, 1) |
|
subListFromIndexToEnd(ListExpression, index) |
subListFromIndexToEnd(ListExpression, 1) |
|
subListFromFirstToIndex(ListExpression, index) |
subListFromFirstToIndex(ListExpression, 1) |
|
subListFromFirstToLast(ListExpression) |
subListFromFirstToLast(ListExpression) |
|
subListFromFirstToEnd(ListExpression) |
subListFromFirstToEnd(ListExpression) |
|
subListFromEndToIndex(ListExpression, index) |
subListFromEndToIndex(ListExpression, 1) |
|
subListFromEndToEnd(ListExpression, index) |
subListFromEndToEnd(ListExpression, 1) |
|
subListFromEndToLast(ListExpression, index) |
subListFromEndToLast(ListExpression, 1) |
Block (Image) | Textly Representation | Example |
---|---|---|
functionName(expr, expr, ...) |
myFunction(0, 0) |
Block (Image) | Textly Representation | Example |
---|---|---|
image(ImageName) ImageName options: heart, heartSmall, happy, smile, sad, confused, angry, asleep, surprised, silly, fabulous, meh, yes, no, triangle, triangleLeft, chessboard, diamond, diamondSmall, squareBig, squareSmall, rabbit, cow, musicCrotchet, musicQuaver, musicQuavers, pitchfork, xmas, pacman, target, tshirt, rollerskate, duck, house, tortoise, butterfly, stickFigure, ghost, sword, giraffe, skull, umbrella, snake |
image(heart) |
|
image.define(Image defined by the user) |
image.define([ [0, 0, 0, 0, #], [0, 0, 0, 0, #], [0, 0, 0, 0, #], [0, 0, 0, 0, #], [0, 0, 0, 0, #] ]) |
|
image.shift(Direction, expr, expr) Direction options: up, down, left, right |
image.shift(left, 2, 3) |
|
image.invert(expr) |
image.invert(image) |
|
microbitv2.accelerometerSensor(Slot) Slot options: x, y, z, strength |
microbitv2.accelerometerSensor(x) |
|
microbitv2.logoTouchSensor.isPressed() |
microbitv2.logoTouchSensor.isPressed() |
|
microbitv2.compassSensor.getAngle() |
microbitv2.compassSensor.getAngle() |
|
microbitv2.gestureSensor.currentGesture(Gesture) Gesture options: up, down, faceDown, faceUp, shake, freefall |
microbitv2.gestureSensor.currentGesture(shake) |
|
microbitv2.keysSensor.isPressed(Button) Button options: Defined in robot configuration |
microbitv2.keysSensor.isPressed(A) |
|
microbitv2.lightSensor.getLevel() |
microbitv2.lightSensor.getLevel() |
|
microbitv2.pinGetValueSensor(Pin, Mode) Pin: Defined in robot configuration Mode options: analog, digital, pulseHigh, pulseLow |
microbitv2.pinGetValueSensor(P0, analog) |
|
microbitv2.pinTouchSensor.isPressed(INT) |
microbitv2.pinTouchSensor.isPressed(1) |
|
microbitv2.soundSensor.microphone.soundLevel() |
microbitv2.soundSensor.microphone.soundLevel() |
|
microbitv2.temperatureSensor() |
microbitv2.temperatureSensor() |
|
microbitv2.timerSensor() |
microbitv2.timerSensor() |
|
microbitv2.getLedBrightness(expr, expr) |
microbitv2.getLedBrightness(1, 2) |
|
microbitv2.receiveMessage(DataType) DataType options: Number, Boolean, String |
microbitv2.receiveMessage(Number) |
Block (Image) | Textly Representation | Example |
---|---|---|
#color Color options: #pink , #purple , #blue , #green , #lightgreen , #yellow , #orange , #red , #white , #rgb(XXXXXX)
|
#green , #rgb(008000)
|
|
wedo.gyroSensor.isTilted(port, direction) Port options: Defined in robot configuration Direction options: up , down , back , front , no , any
|
wedo.gyroSensor.isTilted(port1, front) |
|
wedo.infraredSensor(port) Port options: Defined in robot configuration |
wedo.infraredSensor(port2) |
|
wedo.keysSensor.isPressed(button) Button options: Defined in robot configuration |
wedo.keysSensor.isPressed(button1) |
|
timerSensor() |
timerSensor() |
Block (Image) | Textly Representation | Example |
---|---|---|
|
#rgb(hex) or #colorName Colors: #rgb(0057a6) or #blue , #rgb(585858) or #gray , #rgb(000000) or #black , #rgb(f7d117) or #yellow , #rgb(00642e) or #green , #rgb(b30006) or #red , #rgb(FFFFFF) or #white , #rgb(532115) or #brown
|
#rgb(0057a6) #rgb(f7d117)
|
ev3.connectToRobot(expr) |
ev3.connectToRobot("weDo") |
|
ev3.receiveMessage(expr) |
ev3.receiveMessage(null) |
|
ev3.waitForConnection() |
ev3.waitForConnection() |
|
ev3.getSpeedMotor(port) Port options: A , B , C , D
|
ev3.getSpeedMotor(B) |
|
ev3.getVolume() |
ev3.getVolume() |
|
ev3.touchSensor.isPressed(port) Port options: 1 , 2 , 3 , 4
|
ev3.touchSensor.isPressed(1) |
|
|
ev3.ultrasonicSensor.getDistance(port) ev3.ultrasonicSensor.getPresence(port) Port options: 1 , 2 , 3 , 4
|
ev3.ultrasonicSensor.getDistance(4) ev3.ultrasonicSensor.getPresence(4)
|
ev3.colorSensor(mode, port) Modes: colour , light , ambientlight , rgb Port options: 1 , 2 , 3 , 4
|
ev3.colorSensor(colour, 3) ev3.colorSensor(light, 3)
|
|
|
ev3.infraredSensor.getDistance(port) ev3.infraredSensor.getPresence(port) Port options: 1 , 2 , 3 , 4
|
ev3.infraredSensor.getDistance(4) ev3.infraredSensor.getPresence(4)
|
|
ev3.encoderSensor.getDegree(port) ev3.encoderSensor.getRotation(port) ev3.encoderSensor.getDistance(port) Port options: A , B , C , D
|
ev3.encoderSensor.getDegree(B) ev3.encoderSensor.getRotation(B) ev3.encoderSensor.getDistance(B)
|
ev3.keysSensor.isPressed(button) Buttons: up , down , left , right , escape , any
|
ev3.keysSensor.isPressed(up) ev3.keysSensor.isPressed(any)
|
|
|
ev3.gyroSensor.getAngle(port) ev3.gyroSensor.getRate(port) Port options: 1 , 2 , 3 , 4
|
ev3.gyroSensor.getAngle(2) ev3.gyroSensor.getRate(2)
|
ev3.timerSensor(port) Port options: 1 , 2 , 3 , 4 , 5
|
ev3.timerSensor(1) |
|
ev3.soundSensor.getSoundLevel(port) Port options: 1 , 2 , 3 , 4
|
ev3.soundSensor.getSoundLevel(4) |
|
|
ev3.hiTechCompassSensor.getAngle(port) ev3.hiTechCompassSensor.getCompass(port) Port options: 1 , 2 , 3 , 4
|
ev3.hiTechCompassSensor.getAngle(4) ev3.hiTechCompassSensor.getCompass(4)
|
|
ev3.hiTechInfraredSensor.getModulated(port) ev3.hiTechInfraredSensor.getUnmodulated(port) Port options: 1 , 2 , 3 , 4
|
ev3.hiTechInfraredSensor.getModulated(4) ev3.hiTechInfraredSensor.getUnmodulated(4)
|
ev3.hiTechColorSensor(mode, port) Modes: colour , light , ambientlight , rgb Port options: 1 , 2 , 3 , 4
|
ev3.hiTechColorSensor(colour, 3) ev3.hiTechColorSensor(rgb, 3)
|
Home | Community | Installation | Team
Installation Tutorials
- Instructions to run a openroberta lab server using DOCKER
- Instructions to run the Open Roberta Lab Server natively on ubuntu ‐ not recommended
- Raspberry Pi 2/3/4 and the Open Roberta Lab
- EV3 and leJOS
- EV3 and ev3dev
- Creating the OR leJOS image
- Arduino Create Agent
- Mbed DAL: Generation and automation
Development
-
Workflows
-
Architecture
-
Blockly
-
Software engineering issues
-
Misc
-
Notes on robots
Textual Representation
Contribution
Discussions on future development