Concept Explanation: Task [string]label { } introduction

Printer-friendly version

When you open a new RobotC program, you start with a blank slate, with no instructions. The NXT/RobotC was designed with a number of rules that force us to write or programs in a certain way. Our first rule of RobotC is:

1. NXT actions shall reside within tasks.

A task in the most simple of terms is a labeled container of instructions. By separating our instructions into tasks, we gain the ability to do multiple things at once. Tasks can be labeled anything so when you launch a program, the NXT looks for something called the "root task". This task is the only task that the NXT will automatically start. When this task ends, the NXT will close the program. The designers of this system determined that the task labeled "main" which brings us to our second rule:.

2. "task main {}" will always be the first task to be launched.

To create a task, we type the following:


The first part of any construct in RobotC is a "Command Declaration". This notifies the NXT that a particular construct is being created. In this case, we are creating a task and the NXT is now expecting certain elements to come next. The next element is the text label of the task followed by the encapsulated instructions that make up the task.

Encapsulation is when you put a symbol at the start and end of something. It acts as the boundaries of a container to relate the contents of the encapsulation with the preceding command. For tasks, we use curly braces to mark the start and end of the task. This brings us to our third rule.

3. Encapsulation will always consist of two symbols: one at the start to open, and one at the end to close.

Programming is a lot like cooking. If you have trouble conceptualizing what a task is, think of it as a recipe card. They are both a labeled set of instructions to follow. In cooking, you perform the task. In RobotC, the NXT does the work.