Presentation is loading. Please wait.

Presentation is loading. Please wait.

A tiny turtle robot DEI The University of Padova.

Similar presentations


Presentation on theme: "A tiny turtle robot DEI The University of Padova."— Presentation transcript:

1 A tiny turtle robot DEI The University of Padova

2 A Tiny RobotTurtle

3 Objectives A very simple moving robotic construction Straight line and rotation moving allowed The robot can execute single moving commands like a Logo turtle (forward, backward, rotate left and right)‏ For demonstration purposes Logo-like commands are implemented as NXT-G user commands and NXC functions

4 Building instructions Run the TinyRobotTurtle model using Lego Digital Designer (file TinyRobotTurtle.lxf) (also the local mode is ok)‏ You can run the animation of the building instruction selecting the Building Instruction mode (F7)‏ In the Building Instruction Player you can choose the type (sugg. Vehicles) and how many bricks to be added with each step (sugg. 1..3)‏

5 Programming with NXT-G We would define:  The 'macro-commands' forward (fd) and back (bk) with a parameter specifying a distance  The 'macro-commands' right and left with a parameter specifying an angle NXT-G supports only user block definitions without explicit parameters We substitute parameters respectively with the common variables Steps and Angle

6 NXT-G Step 1 a In a new program define the new numeric variable Steps

7 NXT-G Step 1 b Common variables must be defined with the same name and type in main program and all subprograms

8 NXT-G Step 2 a Add a Variable block to read the input parameter

9 NXT-G Step 2 b Set the block as reading the Steps variable

10 NXT-G Step 3 a Add a Move block to move forward the number of steps specified by the input parameter

11 NXT-G Step 3 b Select the two output port (A-C) The direction depends on how the motors are put on the robot The power is set on a medium value (40)‏ Brake mode allows a more precise move

12 NXT-G Step 3 b For simplicity, we decide to set the duration in motor degree units and to make this unit correspondent to the Turtle forward/backward 'unit' In the motor block you can set an arbitrary duration: the actual duration is expressed by the Steps input parameter in motor degree units

13 NXT-G Step 3 c Connect with a data wire the Variable block output with the Duration input of the Move block Its yellow colour confirms that it is a numeric data wire

14 NXT-G Step 4 a Select all the blocks and choose Make A New My Block from the Edit Menu Assign Fd as block name and write a description

15 NXT-G Step 4 b Choose an appropriate icon (you can drag more than one icon)‏ With Finish the block is recorded in your profile and listed as a My Block

16 NXT-G Step 5 a Define Bk as a new My Block from a new (sub)program similar to Fd but moving the robot backward (a different direction in the Move block)‏

17 NXT-G Step 5 b Assign an appropriate icon also to this My Block

18 NXT-G Step 6 a Define two other similar (sub)programs as new My Block named Lt and Rt for the two types of rotations For both commands the input parameter is represented by the Angle common variable which expresses the rotation of the robot turtle in degree We determine experimentally the ratio between the robot and the motor degree units: in the example such a ratio is about 2.22 and, for the sake of precision, the Angle value is multiplied by 12445 and then divided by 5600

19 NXT-G Step 6 b In a new (sub)program define the Angle numeric variable and read it

20 NXT-G Step 7 a Add a first Math block as a multiplication with the value 12445

21 NXT-G Step 7 b Connect the output of the Variable block with first operand input (A) of the Math block

22 NXT-G Step 8 a Add a second Math block as a division with the value 5600

23 NXT-G Step 8 b Connect the output of the first Math block with first operand input (A) of the second Math block

24 NXT-G Step 9 a We decide to produce the rotation of the robot controlling singularly each one of the two motors with the same power and opposite direction The synchronization is guaranteed giving the two commands in immediate sequence and waiting for completion only after the second command

25 NXT-G Step 9 a Add a Motor block for moving backwards the first motor (A) and connect the previous data output to the Duration input

26 NXT-G Step 9 b Do the same for the other motor (C) but moving forwards and waiting for completion

27 NXT-G Step 9 c Select all the elements and define the new My Block named Lt

28 NXT-G Step 10 a The Rt (sub)program is almost identical to Lt: exchange the direction in the two Motor blocks

29 NXT-G Step 10 b Define a new My Block named Rt with an appropriate icon

30 NXT-G Step 11 a The demo main program simulates the well known lists of Logo instructions to draw a square with an edge of pixels, forwards and backwards repeat 4 [fd rt 90] repeat 4 [lt 90 bk ] Some sounds are added to separate the various commands

31 NXT-G Step 11 a Start the program defining the two variables Steps and Angle

32 NXT-G Step 12 Insert a Loop block with Control type set to Count and Until set to 4 to simulate the repeat command

33 NXT-G Step 13 Add a Variable block to set the Steps value to 300 (corresponding to a movement of the robot of some centimetres)‏

34 NXT-G Step 14 a Add a Fd (user) block using the Custom palette

35 NXT-G Step 14 b Notice that no data wired is usable with user blocks: this is why we use common variables as parameters

36 NXT-G Step 15 Add a Sound block to produce a Click (!Click sound file) at the end of the previous forward command

37 NXT-G Step 16 With similar operations add a Variable block to assign the constant 90 to Angle, to rotate right the robot, and to produce a Click sound The first loop is now complete

38 NXT-G Step 17 Add a Wait block of 2 seconds to separate the two motions

39 NXT-G Step 18 With similar sub-steps complete the second loop (pay attention to its order of blocks)‏ The last sound file is Applause!

40 NXT-G Step 19 Now the example is complete Download the program and run it

41 Programming with NXC To compare the solution in NXT-G with a solution based on a textual language, we use NXC (Not eXactly C) to defined the four basic movements (fd, bk, rt, lt) and the main program

42 Programming with NXC #define RATIO 12445/5600 void fd(long steps) { RotateMotorEx(OUT_AC, -30, steps, 0, true, true); } void bk(long steps) { RotateMotorEx(OUT_AC, 30, steps, 0, true, true); }

43 Programming with NXC void rt(long angle) { angle = angle * 12445 / 5600; NumOut (0, LCD_LINE1, angle, true); RotateMotorEx(OUT_AC, -30, angle, 90, true, true); } void lt(long angle) { angle = angle * 12445 / 5600; NumOut (0, LCD_LINE1, angle, true); RotateMotorEx(OUT_AC, -30, angle, -90, true, true); }

44 Programming with NXC task main() { repeat(4) { fd(300); PlayFile("! Click.rso"); rt(90); PlayFile("! Click.rso"); } Wait(2000); repeat(4) { lt(90); PlayFile("! Click.rso"); bk(300); PlayFile("! Click.rso"); } Wait(500); PlayFile("! Applause.rso"); Wait(4000); }


Download ppt "A tiny turtle robot DEI The University of Padova."

Similar presentations


Ads by Google