8. AI Development8. AI Development\8.4 Conditions and Actions8.4 Conditions and Actions\8.4.3 Advanced Conditions

8.4.3  Advanced Conditions

In the advanced programming function, you can write simple codes for specific conditions and actions.

The Advanced programming supports the symbols for C arithmetic operations and relational operators.

Fig. 8-26: C arithmetic operations and relational operators

You can use all variables including system variables and self-defined variables in the advanced conditions and actions.


Pre-defined variables

What it means …

US_Front

The distance between obstacles and the front ultrasonic sensor. Range: 0 – 255 cm

US_Left

The distance between obstacles and the left ultrasonic sensor. Range: 0 – 255 cm

US_Right

The distance between obstacles and the right ultrasonic sensor. Range: 0 – 255 cm

CSLeft_R

The red channel value of left RGB colour sensor. Range: 0 - 255

CSLeft_G

The green channel value of left RGB colour sensor. Range: 0 - 255

CSLeft_B

The blue channel value of left RGB colour sensor. Range: 0 - 255

CSRight_R

The red channel value of right RGB colour sensor. Range: 0 - 255

CSRight_G

The green channel value of right RGB colour sensor. Range: 0 - 255

CSRight_B

The blue channel value of right RGB colour sensor. Range: 0 - 255

Compass

Compass sensor. It is 0o when facing score board. Range 0 – 360o

Time

The clock runs when game starts

WheelLeft

Left wheel speed, Range (-5) – (+5)

WheelRight

Right wheel speed, Range (-5) – (+5)

LED_1

LED status: LED_1 = 0 (off); 1 (blink); 2 (steady on)

LoadedObjects

Loaded objects counter. LoadedObject will be added by “1” when the “FindObject” key action is executed. LoadedObject will be reset to “0” when the “Deposit” key action is executed.

SuperObj_Num

When Super or Super+ objects appears, the “SuperObj_Num” will be set to 1. It will only last for about 2 sec.

SuperObj_X

When Super or Super+ objects appears, the “SuperObj_X” indicates the X coordinates of the Super Object. It will only last for about 2 sec.

SuperObj_Y

When Super or Super+ objects appears, the “SuperObj_Y” indicates the Y coordinates of the Super Object. It will only last for about 2 sec.

Teleport

If you wish to teleport to the 1st location in the WORLD_2, set Teleport = 1;

If you wish to teleport to the 2nd  location in the WORLD_2, set Teleport = 2;

If you wish to teleport to the 3rd  location in the WORLD_2, set Teleport = 3;

PositionX

X coordinate of the robot current position. It is only available in WORLD_2.

PositionY

Y coordinate of the robot current position. It is only available in WORLD_2.

Duration

 

Duration is associated with the “default” or “non-interrupt action” statement. Duration is used to specify the time that the action is executed continually. Within this period, the robot’s action will not be interrupted by other statement, except Super action statement. The “Duration” is for default action or non-interrupt action.

When Duration = 1, it means the action will continually running for 60 ms

When Duration = 2, it means the action will continually running for 120 ms

When Duration = 3, it means the action will continually running for 180 ms

…..

SuperDuration

Same as the Duration. It is for Super Action.

bGameEnd

Not in use.

CurAction

System variable

CurGame

System variable

TM_State

System variable

MyState

Not in use

 

Advanced Conditions

The advanced conditions are used for more complicated combination of conditions. Here is the procedure:

Fig. 8-27: Advanced Conditions/Actions Code Editor

More examples:           

Condition

How to program…

0 ≤ US_Front ≤ 50

and

0 ≤ CSLeft_B ≤ 60

0 ≤ US_Front ≤ 50

or

0 ≤ CSLeft_B  ≤ 60

40 ≤US_Left ≤ 80

and

CSRight_G ≥ 100

(US_Left>=40&&US_Left<=80)&&(CSRight_G>=100)

40 ≤ US_Right ≤ 80

or

CSRight_R ≥ 100

(US_Right>=40&&US_Right<=80)||(CSRight_R>=100)

0 ≤ CSLeft_R ≤ 60

and

45o ≤ Compass ≤ 90o

(CSLeft_R<=60)&&(Compass>=45&&Compass<=90)

 

You can use the graphical interface to edit the basic conditions. You can also write your own code in the code editor to create the advanced conditions. The advanced conditions can be combined with the basic conditions to fulfil more comprehensive requirement. 

The basic conditions and advanced conditions can be combined using logic-and or logic-or.

 

More examples:

Condition

How to program

60 ≤ CSLeft_G ≤ 90

and

0 ≤ CSRight_G ≤ 60

or

0 ≤ CSRight_R < 50

60 ≤ CSLeft_G ≤ 90

and

0 ≤ CSRight_G ≤ 60

and

0 ≤ CSRight_R < 50

60 ≤ CSLeft_G ≤ 90

and

0 ≤ CSRight_G ≤ 60

and

0 ≤ CSRight_R < 50

 


Top of Page