Vous êtes sur la page 1sur 34

Robotics

Module 2

Data programming blocks

Math Block
In the math block, A and B values can either be manually set in the configuration panel or dynamically set with input data wires.

Variable Block
You can create logic , text and number variables
Step 1 Step 2

Variable Block
You can: read from a variable write to the variable

The value can be supplied either using the Configuration Panel or via an input data wire.

Initialize the variable


Before you can read form a variable, you must initialize it (write a value to it).

Example 1

x=0

Example 2, Counter

x = x + 1 = 0+1=1 x = x + 1 = 1+1=2 x = x + 1 = 2+1=3 .

B=1

X=0

Example 3

X =0 B=10

B=1

This is confusing !!!!!

Range Block

True

False

Example

1
A=30 B=60

42

Example

20
X=20
A=30 B=60

Example

0
A=40 B=50

30

I need a break !!

Logic block

A 0 0 1 1

B 0 1 0 1 0 0 0 1

0
0 1 1

0
1 0 1

0
1 1 1

A 0 0 1 1

B 0 1 0 1 0 1 1 0

A 0 1 1 0

Example
You want your robot to change direction if the ultrasonic value is less than 20 cm or the touch sensor is pressed.

B=20

Do you think the two pictures are the same!!

Logic Operation

Compare block

Exercise 1
Value = 2* (Intensity)2 6 * Intensity + 78 The intensity is the measured by the light sensor

Exercise 2
y= 2 x2 6 x + 3; x is a variable

Exercise # 3
Area of a circle = pi * r* r
pi is a constant r is a variable The area of the circle is displayed in the screen

Activity 1
Every time the touch sensor is bumped, the score will be incremented by ten. If the ultrasonic sensor reading is between 10 and 20 cm, the score will also be incremented by 10. The game will be over after two minutes. The final score of a pinball machine is displayed on the NXT screen.

Exercise # 4
Count and display the number of red and blue objects.

Random Block:
Random Block is used to generate a random number. It takes two inputs in the form of the min and max values of the random numbers it will be allowed to generate. It is used to create robotic games or a robot that exhibits unpredictable behavior because the blocks output will vary each time the program runs. Often a robot that is a little unpredictable can be more interesting or seem to have more personality.

Random Block:
Random Block is used to generate a random number. It takes two inputs in the form of the min and max values of the random numbers it will be allowed to generate. It is used to create robotic games or a robot that exhibits unpredictable behavior because the blocks output will vary each time the program runs. Often a robot that is a little unpredictable can be more interesting or seem to have more personality.

Challenge
A steering value has a range between -100 and 100, how can you generate a random negative value to allow steering to take place

Activity 2

Activity 3

Vous aimerez peut-être aussi