Operators#

Add#

The Add block is used to add any two values together and reports the sum.

    ((0) + (0))

The Add block can accept decimals, integers, or numeric blocks.

The Add block fits in blocks that accept circular spaces, and can accept other circular blocks in it as well.

In this example, the Drivetrain will move forward for 400 mm.

    when started :: hat events
    drive [forward v] for ((100) + (300)) [mm v] ▶

Subtract#

The Subtract block is used to subtract one value from another and reports the difference.

    ((0) - (0))

The Subtract block can accept decimals, integers, or numeric blocks.

The Subtract block fits in blocks that accept circular spaces, and can accept other circular blocks in it as well.

In this example, the Drivetrain will move forward for 400 mm.

    when started :: hat events
    drive [forward v] for ((500) - (100)) [mm v] ▶

Multiply#

The Multiply block is used to multiply any two values together and reports the product.

    ((0) * (0))

The Multiply block can accept decimals, integers, or numeric blocks.

The Multiply block fits in blocks that accept circular spaces, and can accept other circular blocks in it as well.

In this example, the Drivetrain will move forward for 600 mm.

    when started :: hat events
    drive [forward v] for ((200) * (3)) [mm v] ▶

Divide#

The Divide block is used to divide the first value by the second value and reports the dividend.

    ((0) / (0))

The Divide block can accept decimals, integers, or numeric blocks.

The Divide block fits in blocks that accept circular spaces, and can accept other circular blocks in it as well.

In this example, the Drivetrain will move forward for 400 mm.

    when started :: hat events
    drive [forward v] for ((1200) / (3)) [mm v] ▶

Random#

The Random block is used to report a random value between the lowest and highest values in the block.

    (pick random (1) to (10))

The Random block can accept decimals, integers, or numeric blocks.

In this example, the Drivetrain will move forward for a random distance between 700 and 1000 mm.

    when started :: hat events
    drive [forward v] for (pick random (700) to (1000)) [mm v] ▶

Greater than#

The Greater than block is used to report if the first value is larger (greater) than the second value.

    <[0] > [50]>

The Greater than block can accept decimals, integers, or numeric blocks.

The Greater than block reports true when the first value is larger than the second value and false when the first value is smaller than or equal to the second value.

The Greater than Boolean block reports a true or false value and fits in blocks with hexagonal (six-sided) spaces.

In this example, the Drivetrain will move in reverse for 400 mm, because 0 > 50 returns False.

    when started :: hat events
    if <[0] > [50]> then
    drive [forward v] for (400) [mm v] ▶
    end
    drive [reverse v] for (400) [mm v] ▶

Less than#

The Less than block is used to report if the first value is less (smaller) than the second value.

    <[0] < [50]>

The Less than block can accept decimals, integers, or numeric blocks.

The Less than block reports true when the first value is smaller than the second value and reports false when the first value is greater than or equal to the second value.

The Less than Boolean block reports a true or false value and fits in blocks with hexagonal (six-sided) spaces.

In this example, the Drivetrain will move forward for 400 mm, because 0 < 50 returns True.

    when started :: hat events
    if <[0] < [50]> then
    drive [forward v] for (400) [mm v] ▶
    end
    drive [reverse v] for (400) [mm v] ▶

Equal to#

The Equal to block is used to report if the first value is the same as, or equal to, the second value.

    <[0] = [50]>

The Equal to block can accept decimals, integers, or numeric blocks.

The Equal to block reports true when the two values are exactly the same and reports false when the two values are not the same.

The Equal to Boolean block reports a true or false value and fits in blocks with hexagonal (six-sided) spaces.

In this example, the Drivetrain will move in reverse for 400 mm, because 0 = 50 returns False.

    when started :: hat events
    if <[0] = [50]> then
    drive [forward v] for (400) [mm v] ▶
    end
    drive [reverse v] for (400) [mm v] ▶

And#

The And block is used to report if two Boolean conditions are both true.

    <<> and <>>

The And block reports true when both conditions are true and reports false when one, or both, of the conditions are false.

The And Boolean block reports a true or false value and fits in blocks with hexagonal (six-sided) spaces.

In this example, if the Down Eye Sensor detects a red object and the drivetrain is moving at the same time, the Drivetrain will stop moving. Otherwise, the Drivetrain will keep moving forward.

    when started :: hat events
    if <<[DownEye v] detects [red v]?> and <drive is moving?>> then
    stop driving
    end
    drive [forward v]

Or#

The Or block is used to report if one of two Boolean conditions are true.

    <<> or <>>

The Or block reports true when one (or both) of the conditions are true and reports false when both of the conditions are false.

The Or Boolean block reports a true or false value and fits in blocks with hexagonal (six-sided) spaces.

In this example, if the Down Eye sensor detects a red or green object, the Drivetrain will stop. Otherwise, the Drivetrain will keep moving forward.

    when started :: hat events
    if <<[DownEye v] detects [red v]?> or <[DownEye v] detects [green v]?>> then
    stop driving
    end
    drive [forward v]

Not#

The Not block is used to report the opposite (inverse) of the reported Boolean value.

    <not <>>

The Not block reports true when the Boolean block inside reports false and reports false when the Boolean block inside reports true.

The Not Boolean block reports a true or false value and fits in blocks with hexagonal (six-sided) spaces.

In this example, if the Left Bumper Sensor has not been pressed, the Drivetrain will move forward. If the Left Bumper Sensor has been pressed, the Drivetrain will stop.

    when started :: hat events
    if <not <[LeftBumper v] pressed?>> then
    drive [forward v]
    end
    stop driving

Round#

The Round block is used to round the inputted value to the nearest integer.

    (round ())

The Round block can accept decimals, integers, or numeric blocks.

Decimals that are 0.5 or greater round up and decimals less than 0.5 round down.

The Round block fits in blocks that accept circular spaces, and can accept circular blocks in them as well.

In this example, the Drivetrain will move forward for the rounded number of 474 mm.

    when started :: hat events
    drive [forward v] for (round(473.64)) [mm v] ▶

Function#

The Function block is used to perform a selected math function.

    ([abs v] of (0))

The Function block can accept decimals, integers, or numeric blocks.

The available functions are:

  • abs - absolute value

  • floor - rounds down to the nearest integer

  • ceiling - rounds up to the nearest integer

  • sqrt - square root

  • sin - sine

  • cos - cosine

  • tan - tangent

  • asin - arcsine or the inverse of sine

  • acos - arccosine or the inverse of cosine

  • atan - arctan or the inverse of tangent

  • ln - the natural logarithm base e

  • log - logarithm base 10

  • e ^ - powers of e

  • 10 ^ - powers of 10

The Function block fits in blocks that accept circular spaces, and can accept circular blocks in them as well.

In this example, the Drivetrain will move forward for 760 mm.

    when started :: hat events
    drive [forward v] for ([abs v] of (-760)) [mm v] ▶

Remainder#

The Remainder block is used to divide the first value by the second value and report the remainder.

    (remainder of (0)/(0))

The Remainder block can accept decimals, integers, or numeric blocks.

Numbers that divide evenly will report a remainder of zero.

The Remainder block fits in blocks that accept circular spaces, and can accept circular blocks in them as well.

In this example, the Drivetrain will wait 2 seconds before moving forward for 200 mm.

    when started :: hat events
    wait (remainder of (17)/(5)) seconds
    drive [forward v] for (200) [mm v] ▶

ArcTan2#

The ArcTan2 block is used to perform the atan2(y, x) math function converted from radians to degrees. This function calculates the angle in degrees from the positive x-axis to a point (x, y), where ‘x’ is the horizontal coordinate and ‘y’ is the vertical coordinate.

    (atan2 of X: (1) Y:(1))

The ArcTan2 block can accept decimals, integers, or numeric blocks.

The ArcTan2 block reports a value in the range of -180 degrees to 180 degrees, representing the angle between the positive x-axis and the point (x, y).

The ArcTan2 block fits in blocks that accept circular spaces, and can accept circular blocks in them as well.

In this example, the Robot will turn to face the coordinate (500, 720).

    when started :: hat events
    turn to heading (atan2 of X: (500) Y:(720)) degrees ▶