a1tQ200000921faIAA

Course: AI LAB- Level 1
5. PnP with Jumps and Loops - Block

  • 6-12 grade
  • Beginner

Lesson Description:

When programming a robotic arm, it often becomes necessary to repeat operations a set number of times or indefinitely. This can be accomplished by adding different styles of loops to our program. It is also a good programming habit to optimize or reduce your lines of code when appropriate.

In this activity you will learn one way to simplify your code as well as add different styles of loops to a basic Pick and Place operation in DobotLab.

The two main types of loops are:

  • Forever loops
  • While loops
  • Repeat


KEY VOCABULARY

  • Forever Loop
  • While Loop
  • Repeat
  • True
  • Jump
  • Placeholder
  • Condition

All blockly commands and robotics terms have been put into a separate glossary that can be founded in the Resources chapter of this curriculum.


EQUIPMENT & SUPPLIES

  • Robot Magician Lite
  • Dobot Dip Tank Field Diagram
  • Magician Lite Work Mat
  • DobotLab software
  • Suction Cup Gripper
  • Small Cubes & Pallets

image description

Lesson Modules


Teaching Tips:

PROCEDURE

Caution: NEVER wire anything to the Dobot Magician while it has power on. ALWAYS turn it off before making connections or damage to the robot could occur. Be sure to ask your instructor if you have any questions.

1. Set up the Dobot in the same configuration from activity “1.3 Pick and Place.”

Setup from 1.3

2. In this activity, use the JUMP command to simplify the original PNP activity from 1.3.

JUMP Concept

3. Open up the DobotBlock lab in the DobotLab software.

Open DobotLab Open DobotLab

4. Open your Pick and Place Blockly Activity.

In this activity, we will add a JUMP movement as well as a LOOP. The JUMP command in blockly works the same as it does in Teach and Playback. This will allow us to remove a few lines of code, creating the same operation in fewer steps.

JUMP Movement – A JUMP movement combines three steps into one. It combines the retract, move over, and back down movements into one step. This type of movement simplifies repetitive movements such as dipping operations or soldering operations. The Z Height for the JUMP movement is defined with a SETTING block.

A JUMP movement does not replace the initial ABPick to ATPick as well as the final ABDrop.

Jump movement explanation
Blockly window

First identify what portions of the last program, if any, can be replaced with a JumpTo command.

After the suction cup is turned on, there is a group of code that is an UP-OVER-DOWN. We will combine these three steps into one JUMP.

JumpTo block example

5. Isolate the section of code to be replaced and pull it off to the side (we still need the ATDROP coordinates).

Does the Jump command make writing a program any easier?


Isolate code block

6. From the MOTION category, drag over a JUMP TO XYZR. Fill in the coordinates with the values for ATDROP (the final point we would like to JUMP to) and add a comment to the block. Reassemble the code with the new JUMP line.

That definitely makes your program shorter and more efficient.

JumpTo block JumpTo block

7. Run your code to ensure proper operation.

Run program

8. Next, we want to add a command that will allow us to control the JUMP Z Height. Drag over a SET JUMP HEIGHT from the SETTING category.

The JUMP height is a relative coordinate, not an absolute coordinate. We want the jump height to be the distance we want the JUMP to travel up for its current location.

Example:
ABPICK Z = 2.0 ABSOLUTE
ATPICK Z = -33 ABSOLUTE
JUMP HEIGHT = (33 + 2) = 35

Set Jump Height

Since this is a setting command line, we will add it to the top of our program where we assigned the EoAT. This step can be added anywhere in the program, as long as it is placed before the jump command is used.

Set Jump Height Set Jump Height Set Jump Height

If your set up did not work correctly the first time, what did you have to do to make it work?



9. Next, we are now going to make the program loop, or repeat, a certain number of times.

To do this we will be using the REPEAT block from the CONTROL category and the while loop – both can be found in the Loops section on the left.

Repeat loop icon

The white arrow at the bottom of a C Block (referred to as a “C” block because of its shape) indicates that the original condition will be re-checked to see if it is still true at the end of each loop. If it is, the loop will run again. In this example, our condition is the number of times to REPEAT. The REPEAT will loop until the condition is no longer true.

Drag only the operations we wish to repeat into this “C” block. We will leave the rest of the program outside of the loop.

Edit the REPEAT block to make this section run 3 times.

Repeat loop Repeat loop explanation

10. Run your code to ensure proper operation.

Run with repeat

Often, we need a section of code to run FOREVER instead of a set number of times. To do this, we will use a FOREVER block. Drag over a FOREVER block from the CONTROL category. Replace the REPEAT block with the FOREVER block and test your program.

Run your code to ensure proper operation.

Forever block example Forever block in use
Repeat Loop Icon

If we select the Repeat Loop to be deleted before the program section is pulled out of the loop, it will delete the loop and everything it contains.

Notice that once the program drops off the block and returns to its safe position, it goes back to the start of the program to try to pick up another block and that this will continue repeating indefinitely until you hit the stop button, or the robot is turned off.

If your set up did not work correctly the first time, what did you have to do to make it work?


Teaching Tips:

CONCLUSION

  1. What is the difference between a forever loop and a repeat loop?
  2. Can a loop be placed inside another loop? Give an example of how you might use this when programming in Blockly.
  3. Describe in your own words how a JumpTo command works. Why is it good programming practice to use JumpTos?

GOING BEYOND

Finished early? Try some of the actions below. When finished, show your instructor and have them initial on the line.

  • Nesting Loops – Produce 2 different pick and place routines. Routine 1 will repeat three times then routine 2 will repeat twice. This process will loop routine 1 and then 2 forever.
  • Produce a repeat loop for a dipping operation. Use the JumpTo when appropriate.