Edit on GitHub

Programming

Edit

These are the methods used for editing in RoboPlus Task.

Select Multiple Lines

RoboPlus Task provides a function to select and edit (cut, copy, delete, comment,etc) multiple lines of program code. There are multiple ways to select multiple lines.

Insert New Line

RoboPlus Task provides a function to insert a line between existing lines. There are multiple ways to insert new lines.(New lines will be inserted below the highlighted line.

Delete Lines

RoboPlus Task provides a function to delete lines. One or more lines may be deleted at once. There are multiple ways to delete lines.

Enable/Disable Lines

RoboPlus Task provides a function to enable or disable lines. There are multiple ways to enable/disable lines.

Copy/Cut/Paste

RoboPlus Task provides a function to cut, copy and paste lines.

Copy

Cut

Paste

Find Name

RoboPlus Task provides a function to search for used elements.

  1. From the “‘edit” menu, select the”‘Find Name” function. The shortcut is Ctrl+F.

find name

  1. Enter a keyword and click the “Find Next” button.

search next

Commands

Start Program

“Start Program” designates the beginning of a program. Regardless of the line number, the program will always start at this point. “Start Program” is like the “main” function in the C language.

Usage

Example

Start a program with the “Start Program” command.

main

End Program

If this command is called during program execution, the program exits immediately. There are 2 ways to end a programme.

  1. When the end of “Start Program” is reached(Natural Exit). end01

  2. When “End Program” is called(Forced Exit). end02

Usage

Call the command at the point in the program where you want it to end.

Example

In this sample code, the program will end when the touch connected to Port3 is pressed.

end example

Start/End of Section

A block or a section (identified by “{“ and “}”) is a group of commands. All commands in a block have the same scope. The concept of a block is the same as in the C language.

Usage

Each block has an opening bracket ({) and a closing bracket (}). RoboPlus Task performs automatic indentation to show whether the brackets have been paired properly. If there are missing brackets, they must be added before the program can run indentation. If they were not arranged properly, you have to revise them by yourself.

section

Each block must be “owned” by a command. Blocks cannot be used independently with commands. The followings are the most commonly used commands that are followed by a block.

If a command is made by one line, it is possible to skip the block brackets.

omitted

Example

The “Start Program” and “Endless Loop” commands must be followed by blocks, as shown in the example below.

section example

Comments/Notes

This command is used to insert a comment or a note in the program code. Comments are helpful when interpreting or reviewing the code later. They are mostly used to mark easily forgotten parts or to emphasize important information. Comments and notes do not affect the program in any way. Like in C, comments can be made with two slashes(//). Comments blocks ( ‘/*’, ‘*/’ ) are not supported.

Usage

Example

This code will print “10” on the screen. The comment explains how the command line below will be executed.

comment

Calculate

“Calculate” is a command to perform an arithmetic operation on two numbers.

math

“Calculate” can perform the following operations:

Usage

You can choose an operator by double clicking a mouse or by pressing the Enter key.

select operator

Choose the appropriate 3 parameters (result, operand1, operand2) necessary for the command.

select parameter

Example

This example shows how to add 10 and 20 and to display the result on the screen.

math example

Load

Load is defined as “to place into an appropriate device”. In RoboPlus Task, Load places a value in a device.

load

Load is used for the followings:

Usage

Choose the appropriate 2 parameters (destination, source) necessary for the command.

select load

Example

To execute a device(Set the timer to 1.024 seconds).

load example01

To set a value (Insert 10 into the variable)

load example02

Label/Jump

Label and Jump are used to branch a program. Branching is used to change the order commands in a program are executed. Jump branches the program and Label designates where to branch to. It is the same function as Label and Goto in the C language.

label

Usage

Example

In this sample code, the program jumps to “JumpPoint” as soon as it starts and executes “Routine 2”.

jump example

If/Else if/Else

These commands will branch the flow of the program depending on whether the condition is true or false.

What’s a Conditional Clause?

Conditional clause is a feature to perform different actions depending on whether the condition evaluates to true (condition is met) or false (condition is not met). Conditional clause is composed of the following 3 parts: parameter 1, relational operator, and parameter 2 in order.

conditional 01

These are 6 types of relational operators.

conditional 02

Conditional clause can be combined into a complex conditional clause using conditional operators. A complex conditional clause is composed of the following 3 parts: conditional clause 1, conditional operator, conditional clause 2.

conditional 03

There are 3 types of conditional operators.

conditional 04

There is no limit to how many conditional clauses can be combined into one complex conditional clause. Each conditional clause is evaluated in order, and the final value will be either “true” or “false.”

Usage

Example

The examples below shows how to program the following conditions.

Endless Loop

This command is used to repeat the command lines in the block without end.

Usage

A block is always required(However, if the block consists of only one, the block need not be enclosed with brackets).

endless usage

Use the “Break Loop” command to exit the loop.

Example

Continuously prints “10” on the Program Output Monitor.

endless example

Loop While

This command is used to repeat the command lines in the block while the clause is true. It is the equivalent of the “while”function in C language..

What is a conditional clause?

Usage

A block is always required(However, if the block consists of only one line, the block need not be enclosed with brackets).

while usage

Use the Break Loop command to exit the loop.

Example

Continuously prints the value of on the Program Output Monitor until the variable reaches 30.

while example

Loop For

This command is used to repeat the command lines in the block for the specified number of times. Given an initial value and a terminal value, the loop will repeat while increasing the variable by 1.

img_for

The number of executions can be calculated as:

Usage

Choose the appropriate 3 parameters (variable, Start value, End value) necessary for the command.

for usage1

The initial value must be less than the terminal value. If the initial value is greater than the terminal value, the loop will not be executed.

A block is always required. (However, if the block consists of only one line, the block need not be enclosed with brackets.)

for usage2

Use the Break Loop command to exit the loop.

Example

This example will repeat the loop as many as the detected sound quantity.

for example

Break Loop

This command is used to exit the loop while it is being executed. It is the equivalent of the “break” function in C language.

img_break

Usage

The command must always be used in the block being repeated.

Example

Continuously prints the number “10” on the screen until the value of the center IR sensor becomes bigger than 400, in which case it exits the loop and prints “30” on the screen.

break example

Wait While

This command is used to pause execution when a conditional clause is true. It is the equivalent of the “while” function in C language.

What is a conditional clause?

Usage

Set the appropriate conditions without the use of blocks.

Example

The program will wait for the timer.

wait example

Exit Function

When this command is executed, it will end the operating function immediately even if not every command line was executed yet, and will return to the function called position. It is the equivalent of the “return” statement in C language.

img_exit

Usage

Can be used only within a general function or a callback function.

Example

In the following example, UserFunction is called repeatedly. Because of the Return command in UserFunction, the last 3 lines will never be executed.

exit example

Make/Call Function

If the same code need to be repeated multiple times, or if the code needs to be distinguished according to its role, you can make the code as a function, and can all the function whenever necessary. This is similar to the concept of a function in C language. The only difference is that there are no return values and input parameters. When used properly, you can easily figure out the flows of the program, and can avoid to write the same command lines again and again. Functions are executed by calling them. After a called function ends, execution will be returned to the point of the calling and started from the next command line.

img_call

Usage

call usage1

call usage2

Example

The program will continuously call the functions to move forward, backward, right and left.

call example

Callback Function

Callback function is a function that runs independently of the main program routine and is automatically executed at fixed intervals. Therefore, a callback function cannot include code that requires much time. Use of loops, variables, and function calls are limited.

Usage

Precautions

Example

This example shows how periodically receive wireless data and to save it in a variable.

callback example