0% found this document useful (0 votes)
88 views151 pages

Blockly Intro-Robotics 061722

Uploaded by

steven.reeder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views151 pages

Blockly Intro-Robotics 061722

Uploaded by

steven.reeder
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 151

PROGRAMMING IN DOBOTSTUDIO

WITH BLOCKLY
INTRODUCTION

THE CURRICULUM

This curriculum was designed to teach high school and college level students the basics of robotics, as used in
industry, using the Dobot Magician, DobotStudio software, and the blockly programming language.

Through these activities, you will also be able to make the robot interact with other devices including, but not
limited to:
• Arduino microcontrollers • Infrared sensors
• Color sensors • Other robots
• Conveyor belts • Other inputs like microswitches and
• Other outputs like motors and LED’s sensors
• VEX Cortex microcontroller

Defining Artificial Intelligence


A lot is being reported about artificial intelligence and robotics in industry, and it is probably one of
the most controversial issues surrounding robots… If you do not understand it. The way that we
wish to address it in this document depends on how it is defined. For our use here Jim and I will
define it as such:

Artificial Intelligence(AI): Using computers, microcontrollers, and other electronic devices to


replicate intelligent behavior to automate tasks and make manufacturing more efficient.

We would like to look at AI from a practical standpoint. How AI helps us in industrial robotics and
automation is what intrigues us the most and what we are most passionate about. In that vein, the
next question to answer then is: “How does this curriculum embody artificial intelligence?”

With the above definition of AI, isn’t a lot of automation & robotics considered artificial intelligence?
Take these instances of what students will be able to do with a dobot and this curriculum:

• Make a motor run forward or backwards depending on what time it is.


• Make a light bulb light up when you want it to. Better yet, make different color lights light
dependent upon what you want.
• Determine what color an object is and then decide where to put it.
• Change the speed of a motor dependent upon where an object is.
• Mathematically calculate where to put the next box on a pallet, or to stack objects perfectly.
• Make a robot talk to another robot and decide when to perform certain actions.
• Make a robot talk to another device to perform a myriad of automation and manufacturing
tasks.
• Make a robot 3D print a necessary part for you, or laser engrave a barcode on each passing
part of an assembly line.

All of these are possible with only a Dobot Magician, A microcontroller, this curriculum, a little
determination, and a lot of curiosity.

2
INTRODUCTION

Defining Industry 4.0


Here’s another term that is being widely used in Industry, and being touted as the next greatest
thing in manufacturing. What does it mean? Again, we have to define it for ourselves so that we
can move forward, and possible embrace it. From our limited research and knowledge of the topic
we would like to define it this way:

Industry 4.0: The 4th industrial revolution where manufacturing facilities employ computers,
machines, and technology, that have inputs and outputs that allow them to wirelessly connect to
ever larger manufacturing systems.

No more is a drill press just a drill press. It may be a CNC machine that has a vision system that
knows where a hole has to go as well as what size it is. Also this machine can be programmed
on the fly to change rapidly if a different order comes in from a different vendor. It’ll even tell
the customer when the part will be done, and in some instances, some factories will even let
customers watch their parts being produced via webcam. The list of tasks above in the definition
of AI are all within reach of high school and college students alike, and aren’t these tasks all a part
of Industry 4.0?

With a Dobot Magician, this curriculum, and a bunch of spare parts, computers, and some
ingenuity, students will definitely be headed in the right direction towards being a part of the future
of Industry; no matter what it’s called when they graduate.

3
CONTENTS

TABLE OF CONTENTS (LIST OF ACTIVITIES & PRESENTATIONS)

Curriculum Standards......................................................................................................Page 7

Presentation 1: Blockly & Dobot - Programming Commands......................................Page 9

Activity 1: Pick And Place..............................................................................................Page 23


Students learn about how to complete basic pick and place routines using the blockly coding
technique.
Essential questions answered in this activity include:
• How do I use blockly to move the robot?
• How can I create a delay?
• What method is used to turn the suction on and off?
• How do I use other end effectors?
• What are some of the basic Dobot configurations?

Activity 2: PnP with Jumps and Loops.........................................................................Page 33


Students learn about how to use jumps and loops in blockly to make the robot move and repeat
tasks.
Essential questions answered in this activity include:
• What’s a Jump, and why is it important?
• How to make the robot repeat a motion or a task?
• When would I use a While statement?
• How do I use an Until statement?
• How do I set jump height?

Activity 3: Pick and Place with Inputs..........................................................................Page 40


Students learn about what it means to be a digital input, how it works, and how to code a switch in
blockly to act as an input device.
Essential questions answered in this activity include:
• What’s the difference between an input and an output in robotics?
• What are some examples of digital inputs?
• How do I code a digital switch as an input in blockly?

Activity 4: Developing a Cube Matrix............................................................................Page 49


Students learn about the use of variables and functions when programming a robotic arm. This
activity uses mathematical concepts to de-palletize a set of blocks.
Essential questions answered in this activity include:
• Why are variables used?
• How do I use variables in blockly?
• How can I use math to palletize?
• What are some of the blockly commands needed to do this?
• Why is palletization and de-palletization important in industry?

4
CONTENTS

Activity 5: Using the Color Sensor................................................................................Page 67


Students learn about how to make the robot interact with the color sensor as an input.
Essential questions answered in this activity include:
• What’s the difference between digital and analog?
• What colors can I sense with the color sensor?
• How does the color sensor work?
• How do I wire the components together?
• How do I get a value from the color sensor?
• How do I print to a log?
• How do I sort items by color with a robotic arm?

Activity 6: Start & Stop Conveyor..................................................................................Page 85


Students learn about the basics of conveyor belts, and how to interface one with the Dobot
Magician. Students will also learn how to use the infrared sensor to stop and start the conveyor.
Essential questions answered in this activity include:
• Is the conveyor an input or an output to the robot?
• Is the Infrared sensor an input or an output?
• How do I wire the components together?
• What can I do with the infrared sensor?
• How do I code the conveyor in blockly?
• How do I code the infrared sensor in blockly?

Presentation 2: Blockly & Dobot - Hardware Connections........................................Page 98

Activity 7: Dobot to Dobot Handshaking....................................................................Page 105


Students develop an understanding of how robots can communicate with one another through the
use of inputs and Outputs. Students use two Dobot Magicians to complete a two robot operation
without timing.
Essential questions answered in this activity include:
• How do I make a robot send a signal?
• How do I get a robot to receive a signal?
• How is this done in Dobot Studio Software?
• How do I make two robots talk to one another?

Activity 8: Handshaking - Arduino to Arduino............................................................Page 116


Students develop an understanding of how important it is to be able to make machines talk to one
another. In this activity students learn how to make Arduino based microcontrollers talk to one
another.
Essential questions answered in this activity include:
• How do I make my microcontroller send and receive signals?
• What kind of software is necessary to communicate?
• How do I wire the hardware to communicate?
• How do I troubleshoot a complex system?

5
CONTENTS

Activity 9: Handshaking - VEX to VEX........................................................................Page 127


Students develop an understanding of how important it is to be able to make machines talk to one
another. In this activity students learn how to make VEX based microcontrollers talk to one another
using RobotC.
Essential questions answered in this activity include:
• How do I make my VEX Cortex send and receive signals?
• What kind of software is necessary to communicate?
• How do I wire the hardware to communicate?
• How is RobotC similar to Arduino software? How is it different?

Activity 10: Handshaking - Dobot to VEX...................................................................Page 136


Students develop an understanding of how robots can communicate with other devices, like
microcontrollers, through the use of inputs and outputs.
Essential questions answered in this activity include:
• How do I get a robot to send and receive a signal?
• How do I make my microcontroller send and receive signals?
• How is this done in Dobot Studio Software?
• How do I wire the hardware to make this happen?
• How do I troubleshoot a complex robotic system?

Activity 11: Workcell Design........................................................................................Page 142


Students develop an understanding of workcells and the interaction of different machines to
complete a manufacturing process.
Essential questions answered in this activity include:
• How do you integrate robots and other parts of a workcell to complete a given task?
• How do you safely communicate between a microcontroller and a robot?
• What are the different types and styles of inputs and outputs needed to complete your given
tasks?
• Which end of arm tooling is most appropriate for your workcell?
• Where is it appropriate to use the jump command within my workcell?
• Where would it be appropriate in your programming to use either variables or functions while
programming?
• What components of blockly did you need to complete this task?
• What other software & hardware will I need to complete this task?

Blockly Glossary...........................................................................................................Page 146

Field Diagrams..............................................................................................................Page 150

6
CURRICULUM STANDARDS

STANDARDS FOR TECHNOLOGICAL AND ENGINEERING LITERACY

The Standards for Technological and Engineering Literacy (STEL) were developed by the International
Technology and Engineering Educators Association (ITEEA) and are available as a complete download
for free here: https://www.iteea.org/189252.aspx

2W Standard: Select resources that involve tradeoffs between competing values, such as
availability, cost, desirability, and waste while solving problems.

2X Standard: Cite examples of the criteria and constraints of a product or system and how
they affect final design.

7Y Standard: Optimize a design by addressing desired qualities within criteria and


constraints.

7CC Standard: Apply a broad range of design skills to their design process.

7Z Standard: Apply principles of human-centered design.

7W Standard: Determine the best approach by evaluating the purpose of the design.

7BB Standard: Implement the best possible solution to a design.

2T Standard: Demonstrate the use of conceptual, graphical, virtual, mathematical, and


physical modeling to identify conflicting considerations before the entire system is
developed and to aid in design decision making.

7Q Standard: Apply the technology and engineering design process.

8H Standard: Research information from various sources to use and maintain technological
products or systems.

NEXT GENERATION SCIENCE STANDARDS

The Next Generation Science Standards is a multi-state effort to create new education standards
that are "rich in content and practice, arranged in a coherent manner across disciplines and grades
to provide all students an internationally benchmarked science education." More information can be
found here: http://www.nextgenscience.org/

HS.ETS1.2 Engineering Design


Design a solution to a complex real-world problem by breaking it down into smaller,
more manageable problems that can be solved through engineering.

HS.ETS1.3 Engineering Design

Evaluate a solution to a complex real-world problem based on prioritized criteria and


trade-offs that account for a range of constraints, including cost, safety, reliability, and
aesthetics, as well as possible social, cultural, and environmental impacts.

7
CURRICULUM STANDARDS

COMMON CORE STATE STANDARDS FOR MATHEMATICS

The Standards for Mathematical Practice describe varieties of expertise that mathematics educators
at all levels should seek to develop in their students. These practices rest on important “processes
and proficiencies” with longstanding importance in mathematics education. More information here:
http://www.corestandards.org/Math/Practice/

N.Q.1 Quantities
Use units as a way to understand problems and to guide the solution of multistep
problems; choose and interpret units consistently in formulas; choose and interpret the
scale and the origin in graphs and data displays.

N.Q.3 Quantities
Choose a level of accuracy appropriate to limitations on measurement when reporting
quantities.

N.Q.4 Vector and Matrix Quantities


(+) Add and subtract vectors.

A.SSE.1.A Seeing Structure in Expressions


Interpret parts of an expression, such as terms, factors, and coefficients.

A.CED.4 Creating Equations


Rearrange formulas to highlight a quantity of interest, using the same reasoning as in
solving equations. For example, rearrange Ohm’s law V = IR to highlight resistance R.

A.REI.1 Reasoning with Equations and Inequalities


Explain each step in solving a simple equation as following from the equality of numbers
asserted at the previous step, starting from the assumption that the original equation
has a solution. Construct a viable argument to justify a solution method.

A.REI.3 Reasoning with Equations and Inequalities


Solve linear equations and inequalities in one variable, including equations with
coefficients represented by letters.

G.SRT.8 Similarity, Right Triangles, and Trigonometry


Use trigonometric ratios and the Pythagorean theorem to solve right triangles in applied
problems.

G.MG.1 Modeling with Geometry


Use geometric shapes, their measures, and their properties to describe objects (e.g.,
modeling a tree trunk or a human torso as a cylinder).

G.MG.3 Modeling with Geometry


Apply geometric methods to solve design problems (e.g., designing an object or
structure to satisfy physical constraints or minimize cost; working with typographic grid
systems based on ratios).

8
Presentation 1:
BLOCKLY & DOBOT - PROGRAMMING COMMANDS

9
Presentation 1:
BLOCKLY & DOBOT - PROGRAMMING COMMANDS

10
Presentation 1:
BLOCKLY & DOBOT - PROGRAMMING COMMANDS

11
Presentation 1:
BLOCKLY & DOBOT - PROGRAMMING COMMANDS

12
Presentation 1:
BLOCKLY & DOBOT - PROGRAMMING COMMANDS

13
Presentation 1:
BLOCKLY & DOBOT - PROGRAMMING COMMANDS

14
Presentation 1:
BLOCKLY & DOBOT - PROGRAMMING COMMANDS

15
Presentation 1:
BLOCKLY & DOBOT - PROGRAMMING COMMANDS

16
Presentation 1:
BLOCKLY & DOBOT - PROGRAMMING COMMANDS

17
Presentation 1:
BLOCKLY & DOBOT - PROGRAMMING COMMANDS

18
Presentation 1:
BLOCKLY & DOBOT - PROGRAMMING COMMANDS

19
Presentation 1:
BLOCKLY & DOBOT - PROGRAMMING COMMANDS

20
Presentation 1:
BLOCKLY & DOBOT - PROGRAMMING COMMANDS

21
Presentation 1:
BLOCKLY & DOBOT - PROGRAMMING COMMANDS

22
Activity 1:
PICK AND PLACE

INTRODUCTION

Robotic arms are excellent for performing pick and place


operations such as placing small electronic components on
circuit boards, as well as large boxes on pallets. A pick and
place operation will require at least 5 points:

1. A home or safe location


2. A position above the object
3. A position at the object
4. A position above the drop off
5. A position at the drop off

In this activity you will learn how to make a basic Pick and
Place operation in blockly. Through this activity you will learn
how to program the robot to move and turn on it’s suction cup
in blockly.

Caution: NEVER wire anything to the Dobot Magician while it has power on. ALWAYS shutdown
the Dobot before making connections or damage to the robot could occur.

KEY VOCABULARY

• MoveTo • Suction Cup


• Placeholder • Blockly Programming
• Delay time • Pick and Place

Helpful Tips: All blockly commands have been put into a separate document called Blockly
Vocabulary, and can be referred to at any time throughout all of these activities.

EQUIPMENT & SUPPLIES

• Robot Magician • 1” cubes or cylinders


• DobotStudio software • Dobot Blockly - Pick and Place Field Diagram
• Suction Cup Gripper

ESSENTIAL QUESTIONS

Essential questions answered in this activity include:


• How do I use blockly to move the robot?
• How can I create a delay?
• What method is used to turn the suction on and off?
• How do I use other end effectors?
• What are some of the basic Dobot configurations?

23
Activity 1:
PICK AND PLACE

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. Print the Blockly - Pick and Place Field Diagram

2. Set up the robot with a suction cup and Air pump and place a cube in one of the red squares on
the field diagram provided.

24
Activity 1:
PICK AND PLACE

3. Open up Blockly in the software.

Helpful Tips: When DobotStudio is closed with a file open,


it will reopen with the last file used. Insure the file open is the
one you want to edit, if it is not, you may end up overwriting
another program.

Shown below is the main menu for the Blockly programming


section of DobotStudio. On the left are categories and tools
that each block of code is sorted into to. On the right are
controls for zooming around the program as you develop it
as well as a trash can for any code element(s) you wish to delete. The scroll wheel on the mouse can
also be used to zoom in and out of the program. In order to pan up and down or left and right you may
either use the scroll bars shown or click and drag on an empty space in the program.

The Crosshair Icon can be used to reset the zoom level back to default and center your code in
the middle of the field.

In this program we will be using the DobotAPIMotion sections in order to


create a simple version of a Pick and Place program.

25
Activity 1:
PICK AND PLACE

In this section there are blocks of code that allow


you to move the Dobot ranging from the arm itself to
the manipulator. For this program, we will need the
MoveTo, JumpTo, and SuctionCup[ON] blocks.

Helpful Tips: For helpful definitions of all the


important blockly commands, please see the
glossary.

The first step in the Blockly Pick and Place process will be
to define the X, Y, and Z coordinates for each step.

Expand the Operation Panel.

Use the X, Y, and Z Jog controls to locate the coordinates


for each position and record them in the chart below. You
can also use the Lock button to manually locate positions
as we did in the Teach and Playback programming.

You may also use the lock button, and then look at the
coordinates in this window to see what the XYZ values of
the points are.

Helpful Tips: Touch up the points so that all of the


corresponding positions XYZ values are aligned.

26
Activity 1:
PICK AND PLACE

X Y Z

1. Home
2. Above Pick
3. At Pick
5. Above Pick
6. Above Place
7. At Place
9. Above Place
10. Home

Now that all of the positions have been


documented, we will transfer their locations in
MoveTo blocks.

Drag over a MoveTo block from the DobotAPI/


Motion Tool Box in the programming field.

This first block is going to be the HOME or start


of the program. For this move, we want the robot
to always go to a safe or reset position before
continuing on with the program. This coordinate
or point will be called home and it does not
necessarily mean the position the robot is at when
the home button is clicked.

27
Activity 1:
PICK AND PLACE

The Home position should be a position above the


environment in which the robot is working, and safely away
from any objects.

Once the coordinates for the home position have been


recorded in the MoveTo command, right click on the
command and select Add Comment.

Please note the values in the images are placeholders,


fake values to be changed later on, and that you will
need to replace them with your own values that you get
from your positions.

Click on the Question Mark that appears. This will allow you
to name the position.

Helpful Tips: The Text Box that appears can be relocated and resized as needed. Clicking on the
Question Mark again will collapse the call out box.

Repeat the process for the remaining steps in the program.


Ignore steps 4 and 8 (Vacuum On and Off) for now.

Helpful Tips: You can also right click on a step and select
Duplicate to create a copy of the step. This may speed up
the process for steps that have similar coordinates.

28
Activity 1:
PICK AND PLACE

We will now assign the End of Arm Tooling (EoAT) as the


Suction Cup.

Drag the ChooseEndTools from the DobotAPI/Config


Tool Box over to the programming field.

Drag the ChooseEndTools over to the 1st Home position


until the links on both lines of programming turn orange
and release the block code.

The SuctionCup should already be selected. If it is not,


please select it from the drop down menu.

Link the next lines of code just before Step 4 - Turn on


Vacuum.

Drag the SuctionCup over and link it to the bottom of the


Main block grouping.

29
Activity 1:
PICK AND PLACE

Helpful Tips: When dragging around blocks of code, if you select the top block, it will allow you to
drag around that block and all of the blocks connected below it. If you selected a block of code from
the middle of a string of blocks, it will disconnect that block and all of the blocks below it. Complete
the remaining portion of the program. Remember to add one additional SuctionCup command to
turn off the Vacuum after placing the block down.

Save your work and select Start to run your


current program.

You should notice that we have the same issue in Blockly that we
had in Teach and Playback where the suction cup has not fully
engaged as the arm moves away from the ATPick location. We
need to solve this problem in the same manner by adding a pause
in the line of code to allow the vacuum to build up.

Drag and drop the Delaytime block over the programming field.

The block of code can be added in one of two different ways.

30
Activity 1:
PICK AND PLACE

Option 1: Separate the lines of code selecting the ABPick,


below the SuctionCup On command, and dragging it down.
The Delaytime can now be added and the bottom of the code
reassembled.

Option 2: Drag the Delaytime over to its desired location. Wait


for the connections to turn orange and release the code. This will
automatically insert the line of code and shift the remaining code
down.

Add an additional Delaytime after the vacuum is turned off. Again,


Test your Code. The Delay time should be adjusted appropriately.

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

31
Activity 1:
PICK AND PLACE

CONCLUSION

1. What are the five needed positions for a pick and place operation?

2. Explain in your own words why it was necessary to add delay times into the program in the
space below.

3. What is the purpose of the safe positions that are programmed above the object before it is
picked up.

GOING BEYOND

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

1. Reverse the process so that at the end the robot puts the cube/cylinder back in its
original position.

2. Try picking and placing the object on locations that are not directly in front of the
robot. What does this change? Can this be corrected in Blockly as it was in Teach
and Playback?

32
Activity 2:
PNP WITH JUMPS AND LOOPS

INTRODUCTION

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 blockly.

The two main types of loops are:


• Forever loops
• While loops
• Repeat

Caution: NEVER wire anything to the Dobot Magician


while it has power on. ALWAYS shutdown the Dobot
before making connections or damage to the robot
could occur.

KEY VOCABULARY

• Forever Loop • Jump


• While Loop • Placeholder
• Repeat • Condition
• True

Helpful Tips: All blockly commands have been put into a separate document called Blockly
Vocabulary, and can be referred to at any time throughout all of these activities.

EQUIPMENT & SUPPLIES

• Robot Magician • Suction Cup Gripper


• DobotStudio software • 1” cubes or cylinders
• Dobot Field Diagram

ESSENTIAL QUESTIONS

Essential questions answered in this activity include:


• What’s a Jump, and why is it important? • When would I use a While statement?
• How to make the robot repeat a motion or a • How do I use an Until statement?
task? • How do I set jump height?

33
Activity 2:
PNP WITH JUMPS AND LOOPS

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. Print the Blockly - Pick and Place Field Diagram.

2. Set up the robot with a suction cup and place a cube in one of the red squares on the field
diagram provided.

34
Activity 2:
PNP WITH JUMPS AND LOOPS

3. Open up Blockly in the software.

Helpful Tips: When DobotStudio is closed with a file


open, it will reopen with the last file used. Insure the file
open is the one you want to edit, if it does not, you may end
up overwriting another program.

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 create the same operation is less steps.

JUMP Movement - A JUMP movement combines three


steps into one. It combines the raise up, over, and back down
to a new point. This type of movement simplifies repetitive
movements such as a dipping operation or soldering
operation. The Z Height is defined in the JUMP parameters in
the settings menu.

A JUMP movement does not replace the initial ABPick to


ATPick as well as the finial ABPlace.

Remove the lines of code from your previous activity and


replace them with a JumpTo command. The JumpTo
command is found in the same DobotAPI/Motion Tool box.

35
Activity 2:
PNP WITH JUMPS AND LOOPS

Adjust the X, Y, and Z movements as needed.

Run your code to ensure proper operation.

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

Next we are now going to make the program loop, or restart, for
a certain number of times. To do this we will be using the repeat
block and the while loop, both can be found in the Loops
section on the left.

The repeat block is very easy to use. Drag the repeat block
into a program environment. It can be dragged into the empty
space or dragged directly onto the top connection for the
ChooseEndTools. If the Repeat loop is dragged onto the empty
space, grab the top line of the existing program and pull it into
the repeat loop. The repeat loop will automatically expand to
encompass the entire code. The program will now run for the set
number of times specified in the repeat.

36
Activity 2:
PNP WITH JUMPS AND LOOPS

Run the program again. To ensure the Repeat Loop works as designed. You will need to manually
replace the cube or cylinder at the start of each of the loops.

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

Many times in programming, we need to add a CONDITION to


our loops. A condition is the scenario that must be met to start
a loop. Many times we need something to keep repeating until
we stop the program, this type of loop is considered a forever
loop and can be made using while loops. To create a forever
loop for this program, we will add a loop that needs a condition
instead of just having it repeat a set number of times.

In order to do this, first drag the code out of the repeat block and then delete it.

Helpful Tips: If you 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.

Go to the Loops Section and drag the Repeat While loop over and drag the rest of the program into it.

Repeat While statements are different than Repeat a number of times as a Repeat while requires
a condition to be true or false to determine if they run or not, and the Repeat Times only requires a
number of times to repeat/loop; no conditions must be met.

37
Activity 2:
PNP WITH JUMPS AND LOOPS

A while loop will run until it’s condition is false so in order to


run something forever, the statement must always be true. For
example, 1 = 1, 4<5, 100>3, 1 is not 2. These statements will
always be true no matter what happens and we could use these
for our while loop but there is an easier way. We can simply have
the statement be True, as True can never be False.

In the Logic Section, you will see a True block. Drag this over to
the puzzle link next to the top of the while loop and it should snap
into place. This will cause the loop to run forever as statement
can never be false.

Once again, run the program and you should see that once the program drops off the block and
returns to it’s 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?

38
Activity 2:
PNP WITH JUMPS AND LOOPS

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 JumpTo’s?

GOING BEYOND

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

1. 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

2. Produce a repeat loop for a dipping operation. Use the JumpTo when appropriate.

39
Activity 3:
PICK AND PLACE WITH INPUTS

INTRODUCTION

Often it is necessary for a robotic arm to wait for another


machine or process to finish before moving with its
program. This can be done by adding the ability for a
robot to read input values.

In this activity you will learn how to add an input to a


basic Pick and Place operation in blockly. Through this
you will learn how to program the robot to move, turn on
it’s suction cup, and how to set up Inputs in Blockly.

Caution: NEVER wire anything to the Dobot Magician


while it has power on. ALWAYS shutdown the Dobot
before making connections or damage to the robot
could occur.

KEY VOCABULARY

• Forever Loop
• While Loop
• Placeholder
• Multiplexing
• Inputs

EQUIPMENT & SUPPLIES

• Dobot Magician • Suction Cup Gripper


• DobotStudio software • 1” cubes or cylinders
• Dobot Field Diagram • Dobot Input/Output Guide

ESSENTIAL QUESTIONS

Essential questions answered in this activity include:


• What’s the difference between an input and an output in robotics?
• What are some examples of digital inputs?
• How do I code a digital switch as an input in blockly?

40
Activity 3:
PICK AND PLACE WITH INPUTS

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. Print the Blockly - Pick and Place Field Diagram.

2. Set up the robot with a suction cup and place a cube in one of
the red squares on the field diagram provided.

3. Wire the robot such that the LIMIT SWITCH is plugged into
port GP5.

Caution: Please Refer to the Dobot Input/Output Guide for


wiring your input. The setup for wiring inputs is not the same
between the Magician V1 and the Magician V2.

41
Activity 3:
PICK AND PLACE WITH INPUTS

4. Open up Blockly in the software and Open your


Blockly - Pick and Place file from the previous
activity.

Helpful Tips: When you re-open this program


check that the name of the file on top matches
the code in the file, if it does not, you may end up
overwriting another program.

In this activity we are going to add the ability for


the program to wait for an input and then have the
program run whenever a limit switch is pressed.
To do this, you must prepare a limit switch that
can work on the Dobot, as done in Activity 5, and
plug it into GP5 (PORT3). Make sure the robot is
off before you plug or unplug anything from the
robot. After that, we are going to right click our
current while loop and click Disable Block. What
this does is that it grays out the current selected
block and any blocks inside of it, making the
program not read it but still having it there in case
you want it back later on.

42
Activity 3:
PICK AND PLACE WITH INPUTS

We are now going to setup a program to make sure


the dobot is reading the input signal from switch.
This is done by having the Dobot print the value of
the switch to the Running Log on the right of the
screen. First though, we must tell the robot that
there is an input we are expecting and we do this
by using the block SetIOMultiplexing. To see the
value we use the GetLevelInput block.

Drag a SetIOMultiplexing block over and it will


be the start of this program. Change the EIO port
to EIO05 which is equivalent to GP5 (PORT3), you
may use another port but make sure to consult the
Dobot Input/Output Guide as some ports may
damage the Dobot or other equipment. Then create
a Forever loop below it.

43
Activity 3:
PICK AND PLACE WITH INPUTS

Caution: Be sure to consult the Dobot Input/Output Guide if you want to use other inputs and
outputs, as damage to your robot or your other equipment may result.

Next we are going to have the program print the


status of the switch. To do this we are going to need
the print block, this can be found in the text section
near the bottom. Drag the print block into the Forever
loop and then drag the GetLevelInput block, that
was indicated before, and drag it into the right side of
the print block. Make sure to change it to the correct
port in order for it to work.

Now run the program. In the running log you should see it printing 0’s or 1’s while the
switch is not pressed and it should swap printing to either a 1 or a 0 while it is pressed.

N.O. - If you see 0’s that change to 1’s, your switch or the Dobot is wired N.O. -
Normally Open. The input will read Low or False until the switch is pressed.

N.C. - If you see 1’s that change to 0’s, your switch or the Dobot is wired N.C. -
Normally Closed. The input will read high or true until the switch is pressed

44
Activity 3:
PICK AND PLACE WITH INPUTS

Helpful Tips: If this is not the case, you may be plugged into the wrong port, have the wrong port
selected for the IO setup, or have the wiring for the switch incorrect. Please refer to the Dobot Input/
Output Guide for your setup and try again. Remember to turn the power off to the robot if you
switch any wires.

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

Now that we are able to see the switch, get rid of the Print block. We are now going to make a while
loop that will run as long as the switch is pressed. Drag another while loop into the Forever loop but
instead of dragging in a True block as we did previously, we are going to go to the Logic section and
drag over a [blank] = [blank] block. This block is how we check if an item is equal, greater, lesser,
or not equal to another item. In the left side of the block, drag in the GetLevelInput block that we just
used. We then are going to go to the Math Section and grab a number block, and drag that into the
right side of the block and change it into a 1.

Create the Nested Loop as seen above (steps provided below). A nested loop is a loop within another
loop. We will place the robot’s pick and place movement commands inside the second loop that is
only called to start if the robot sees a change in the input value on input EIO05. Refer to your testing to
whether the robot should start the movement on a 1 or a 0.

Attach a ReturnTrue from the Logic section. This condition will


return a true value if both inputs are equal as the condition for
the second while loop.

45
Activity 3:
PICK AND PLACE WITH INPUTS

Insert a GetLevelInput from the DobotAPI section


and add that as the first condition for the ReturnTrue
statement. Change the Input value to EIO05.

Insert an AddNumber condition as the second part of


the ReturnTrue statement.

Change the value of the AddNumber to the value that


is needed to start your loop (0 or 1).

Helpful Tips: Once a loop has started, it will continue to finish ALL of the steps in the loop even if the
condition that started the loop becomes false. The condition to start the loop is only evaluated at the
beginning of each loop

Now that the nested loop is setup, we want to re-enable our previous code for the pick and place
routine. To do this, right click on the loop again and click enable. Once it is enabled, drag the
movement code from the old loop into the new loop and then delete or disable the old loop. In the end
it should like this but with real values instead of placeholders.

46
Activity 3:
PICK AND PLACE WITH INPUTS

Once the program is written, run it and see if it works correctly. If it does not work, troubleshoot it until
it does.

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

47
Activity 3:
PICK AND PLACE WITH INPUTS

CONCLUSION

1. What would happen if the loop detecting the switch wasn’t in a forever loop? Try it and describe
what happens. (Hint: Make sure to be holding the switch when you start the program.)

2. What happens to the Pick and Place process when the switch is released (the loop condition
becomes false)?

3. In your own words, define a nested loop.

4. In your own words, define a condition.

GOING BEYOND

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

1. Break the pick and place activity into multiple sections that will wait for the limit switch
before performing each step.

48
Activity 4:
DEVELOPING A CUBE MATRIX

INTRODUCTION

Matrices come in many different sizes throughout


industry and can be used in other areas besides
robotics. Many companies will use matrices in order
to efficiently store products and materials, so it is
important for you to know how they work and how
to program one yourself. It is especially helpful for
palletizing routines when placing boxes on a pallet
efficiently.

Caution: NEVER wire anything to the Dobot


Magician while it has power on. ALWAYS shutdown
the Dobot before making connections or damage to
the robot could occur.

KEY VOCABULARY

• Forever Loop • Matrix


• Repeat Loop • Inputs
• SuctionCup • Variable
• NumberBlock • MoveTo
• ReturnSum Math Block • Function
• User-Defined Function • Delaytime

EQUIPMENT & SUPPLIES

• Robot Magician • Suction Cup Gripper


• DobotStudio software • 1” cylinders or cubes
• Dobot Field Diagram • Dobot Input/Output Guide

ESSENTIAL QUESTIONS

Essential questions answered in this activity include:


• Why are variables used?
• How do I use variables in blockly?
• How can I use math to palletize?
• What are some of the blockly commands needed to do this?
• Why is palletization and de-palletization important in industry?

49
Activity 4:
DEVELOPING A CUBE MATRIX

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. Print the Dip Tank Field Diagram

2. Set up the robot with a suction cup and place a cube on all of the empty
squares on the field diagram provided. (Cube color does not matter for
this Activity.)

3. Open up Blockly in the software and start a new


program.

Helpful Tips: When you re-open this program


check that the name of the file on top matches
the code in the file, if it does not, you may end up
overwriting another program.

Programming the robot to pick up each cube from a


matrix of cubes and drop them all off at a common
location is not necessarily hard to do, just tedious,
time consuming, and numerous lines of code that
are repetitive motions. This same process can be
done in reverse; such as when you move parts from
a feeder and place them in a matrix. This is called
palletization.

50
Activity 4:
DEVELOPING A CUBE MATRIX

From this activity we can learn how to condense


and simplify our program when we have things in
common or repeated.

In this exercise we have the following commonalities:


• Above Z locations are the same.
• At Z locations are the same.
• Place X and Y locations are the same.
• They are all EVENLY spaced in a regular matrix.

The only thing that keeps changing is the X and Y


coordinates of the cubes in the matrix field.

We can use these common factors to simplify our


operations and our code. We will do this with user
defined variables and functions.

Functions are a named section of a program that


performs a task that will be repeated over and over
again in our program. This is a procedure or a routine
that will greatly simplify our otherwise complicated
program.

Functions:

• Group of Code: Can be several lines of code that is needed to complete a single task or
operation. Allows a programmer to group thoughts or actions.

• Use Multiple Times: Functions can be called to run multiple times throughout a program.

• Simplifies Programming: Allows repeated code to be condensed it a single line of code


throughout the main program.

• Simplifies Editing: Code that repeats itself multiple times throughout a program now only needs
to be edited once.

51
Activity 4:
DEVELOPING A CUBE MATRIX

We will start our program by defining a set of


variables. Variables are a changeable quantity in
a program that can be represented by a word or
a letter. Variables can be assigned, changed, or
referenced throughout a program.

List of variables to define:

• HOME X Value
• HOME Y Value
• HOME Z Value
• PICK X Value
• PICK Y Value
• PLACE X Value
• PLACE Y Value
• COMMON Z ABOVE Value
• COMMON Z AT Value

Drag out a set item to variable from the Variables


section.

Click on the “item” portion of the variable tool and


select New variable. This will be our HomeX value.

Next, from the Math section, drag over a Number


block and attach it to the end of our variable.

52
Activity 4:
DEVELOPING A CUBE MATRIX

The next step is to start finding each of our starting values.

Expand the Operation Panel

Using either the Jog Controls, or the Lock Button find the
values for the table below.

It makes it easier to use the Lock Button to get close to the


desired position and then use the Jog Controls for smaller
movements.

Helpful Tips:
• Use Cube ‘0’, from the diagram on page 1, as the X
and Y location for the Pick Location.
• Round all values to the nearest whole number.
• Align the center of the vacuum gripper to the center of
the cube.
• Use the location of dip dank 2 for the common drop
off point.
• Ensure the CommonZAbove positions is high enough
to clear the other blocks.
• Write the values in the table below or in your notebook
for future reference.

HomeX
HomeY
HomeZ
PickX
PickY
PlaceX
PlaceY
CommonZAt
CommonZAbove

53
Activity 4:
DEVELOPING A CUBE MATRIX

Part 1: Setting Variables

Start by recording the HomeX position in the number window of


the block we created

Duplicate the HomeX block until you have 9 variables total.

Left Click on the next variable name and select New Variable.

Create New Variables for each block and fill in their values.

Helpful Tips: If you select Rename Variable, it will only


Rename that value and every where it has been used in the
program.

The order in which we set the variables does not matter in this
program.

54
Activity 4:
DEVELOPING A CUBE MATRIX

The first actual movement is for the robot to always go home


and turn off the vacuum. Please drag and add these blocks
to the program.

Helpful Tips: Remember that these tools come from the


DobotAPI/Motion section.

We will now use some of the user defined variables that we


just created.

From the Variable section, you can now see that all of the
variables that we have created are now options to use.

Select the HomeX Variable (not the set HomeX variable)


and drag it into the X position for the MoveTo step.

55
Activity 4:
DEVELOPING A CUBE MATRIX

Fill in the remaining positions for the MoveTo Home


Block as shown.

Helpful Tips: Assigning variables really helps when XYZ coordinates in a program are going to have
to change multiple times or is going to be used as a template for multiple programs. The can be altered
once at the beginning of the program and that will update everywhere they were used in the program. It
also makes reading the program easier as the user now sees words in place of number values.

We will now add all the steps needed to go get the


first block '0' from the assigned pick location and
move it to the place location.

Making duplicates of the existing MoveTo Home


position we just made will create the program faster.

Duplicate and alter other blocks as they are created to


save time.

Link both sections together.

56
Activity 4:
DEVELOPING A CUBE MATRIX

Once the program is written, run it and see if it works correctly. If it does not work, troubleshoot it until
it does.

Helpful Tips: Remember, if you hit a limit with the robot at any time, or you hear a clicking or a
grinding noise, it's always a good idea to home the robot again. Also, if the robot does not return to the
same position, just re-home it.

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

Part 2: Adjusting Variables

Now it’s time for the second cube.

The only difference in the programming for this cube


should be the X Position.

From the diagram shown, the blocks are 35mm


apart and that the block is moving toward the robot.
Moving toward the robot is shown mathematically by
subtracting 35mm from the current X position value
for block number 2 and again for block number 3.

In order to adjust the X position, set up a block


(Return the sum of two numbers) from the Math
section, and attach it to the SetVariable block.
Attach the two blocks together.

57
Activity 4:
DEVELOPING A CUBE MATRIX

In order to add 35mm to the current PickX value, and


assign that value to the old PickX value, replace the
first value with PickX and the second value with 35.

Current X value equals itself plus a constant of 35

Mathematically: PickX = PickX - 35

Helpful Tips: Grab the PickX Variable from the


Variables section or duplicate it from the main
program.

Add this block line to the bottom of your program.

58
Activity 4:
DEVELOPING A CUBE MATRIX

Now that the PickX value has been adjusted, repeat the
entire process of picking up the second and third cubes
and dropping them off at the place location.

This can be done by recreating all of Section 2 of the


program two more times. There is an easier way of
duplicating groups of code without actually grouping
them. If Section 2 is pulled away from Section 1 (Grab the
1st MoveTo X), it can be put into a loop:

If the loop is duplicated, it will duplicate everything inside


the loop.

Helpful Tips: If a loop is deleted before pulling the group of code out of the loop, it will delete the
loop and its content.

59
Activity 4:
DEVELOPING A CUBE MATRIX

Using this method the program becomes very long,


and we would have to do a lot of scrolling to move
around in our program.

Notice too that the same thing is happening three


times. Instead, just assign a loop and repeat it three
times.

Make it repeat three times as shown and try it out to


make sure it works with the blocks in spaces 0, 1,
and 2.

Since one full column of blocks is completed, just repeat this again for the next two columns.

This can be done by resetting the X value to what it was in the code before and move the Y value over
to the next column.

Repeat this block of code with those two changes two more times to complete the entire matrix.

60
Activity 4:
DEVELOPING A CUBE MATRIX

Part 3: Simplification

Break your code up into 3 separate parts:


1. Assign all of the original values needed as variables and send the robot to a safe/above home
position

2. Pick up the first object using predefined location points from the list of variables. Add or subtract
whatever value is needed to go from the center of the start object to the center of the next object
and repeat this process in a loop for however many objects are in that specific column.

3. Reassign the start value that was altered in section 2 back to the original value. Add or subtract
whatever value is needed to go from the center of the start object in column one to the center of
the next object in column 2.

61
Activity 4:
DEVELOPING A CUBE MATRIX

Rather than create a really long code that looks like:


Section 1
Section 2
Section 3
Section 2
Section 3
Section 2
Section 3
Send Robot to Home

Look to the right to see how long it actually makes


our program. This would make it really hard to work
with in the programming window as a lot of scrolling
would have to be done in order to make any edits.

Simplify it with another loop.

Be sure to add section 3 from above, and reset the


variable PickX to its original value, and then subtract
35 from PickY to move it over.

We can then duplicate and add one final SuctionCup


Off and a final MoveTo Home to end the code.

Add this to the program, then try to run it.

62
Activity 4:
DEVELOPING A CUBE MATRIX

Part 4: Adding Functions

The program is still very long even though variables were used to make it shorter and simpler.

The next step is to simplify it even further with a block of code called a function. A function is a
named section of a program that performs a task. It can also be considered a procedure or a routine
and greatly simplifies otherwise complicated programs.

When a program calls a function to run, the program pauses, runs the function, and then returns to the
program where it left off.

Drag over a Function block with no Output.

We can pull the ENTIRE matrix looping process into


the Function.

Give the Function a name that describes the process


it contains... like Matrix.

63
Activity 4:
DEVELOPING A CUBE MATRIX

The function that was created is now available to be


used in the program as many times and wherever
needed.

Drag the new Function into the Repeat Loop.

The Function just floats in the programming environment


unattached to the main program. They are essentially
separate mini programs to be called by the main
program.

Developing Functions can not only produce groups of


code to be used multiple times, but can also help a
programmer organize their program into mini programs
or separate thoughts.

64
Activity 4:
DEVELOPING A CUBE MATRIX

Once the program is written, run it and see if it works correctly. If it does not work, troubleshoot it until
it does.

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

CONCLUSION

1. In your own words, define a variable.

2. In your own words, define a Function.

3. Explain what would have to be done to palletize two layers using bullet points or a step by step list
below.

65
Activity 4:
DEVELOPING A CUBE MATRIX

GOING BEYOND

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

1. Use a switch as an input to make the robot wait until you move the block from the
Place position and hit the switch.

2. Move a row of three cubes to another row (Matrix to


Matrix).

3. Develop a program that will run the entire process in reverse. Take a block from a
common location and distribute them into a 3x3 matrix. This process is referred to as
palletizing.

4. Take the cubes from a common location and stack them in


a column vertically.

66
Activity 5:
USING THE COLOR SENSOR

INTRODUCTION

Sensors are often added to industrial robots in order for


them to perform specific tasks. These sensors can be as
simple as a color detecting sensor, or as complex as a
full vision system that will allow a robot to be aware of its
surroundings, or find a part and determine its location and
orientation.

In this activity you will learn how to use and program the
color sensor in blocky.

The dobot will pick up a part and move it above the color
sensor. The dobot will then check the part’s color and
place it in a specific location for that specific color part.
The robot will repeat the process each time a limit switch
is pressed.

Caution: NEVER wire anything to the Dobot Magician while it has power on. ALWAYS shutdown
the Dobot before making connections or damage to the robot could occur.

KEY VOCABULARY

• Color Sensor • Function / Voids


• If / Else If / Else Statement • Identify Color
• List • Sum of List
• Return True

EQUIPMENT & SUPPLIES

• Robot Magician • Dobot Input/Output Guide


• DobotStudio software • Dobot Color Sensor
• Dobot Field Diagram • 3 Small Containers
• Suction Cup Gripper • 1” cylinders or 1” cubes (RED, BLUE, GREEN)

ESSENTIAL QUESTIONS

Essential questions answered in this activity include:


• What’s the difference between digital and analog?
• What colors can I sense with the color sensor?
• How does the color sensor work?
• How do I wire the components together?
• How do I get a value from the color sensor?
• How do I print to a log?
• How do I sort items by color with a robotic arm?

67
Activity 5:
USING THE COLOR SENSOR

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 robot with a suction cup - GP1 & SW1

2. Wire the robot with the Color Sensor plugged into port GP2

3. Wire the robot with the Limit Switch plugged into port GP5 - EI05

Set up the robot, conveyor, and color sensor as shown in the diagram below:

68
Activity 5:
USING THE COLOR SENSOR

Order of Operations
• Start with the robot a safe/home position.
• Place a single cube, one at a time for the robot to pick up from a common location.
• A limit switch will be used to call for the robot to come and get the block for evaluation.
• After determining its color, drop the cube off at a specific location for that color.
• Manually remove the cube once it has been placed and send the robot to its home position.

Open up Blockly in the software.

Helpful Tips: When you re-open this program


check that the name of the file on top matches
the code in the file, if it does not, you may end up
overwriting another program.

The first step in programming this activity is to set


up the inputs.

Drag over the SetColorSensor from the DobotAPI/


Additional tool box.

Set the sensor to ON / V2 / GP2

69
Activity 5:
USING THE COLOR SENSOR

Next, set up the limit switch as we have done in past


activities.

Input 3.3V GP5 EI05

COLOR SENSOR SETUP

The next set of commands are needed to get the values from the color sensor to report the correct
values to our program.

Step 1

Bring over and link together three Set Variables to Input


blocks.

70
Activity 5:
USING THE COLOR SENSOR

Select item for each block and create a New


Variable.

We need to create a variable for each color that we


will use in our program

Create variables named:


RED
GREEN
BLUE

Step 2

The next step is to set each individual variable to a


pre-set range collected from the Color Sensor.

The IdentifyColor command is used to identify


three basic colors: Blue, Green, & Red. This block
returns a true or 1 value when the specific color is
identified and a false or 0 when it is not.

Attach an IdentifyColor block to each of your


Variables and select the corresponding color letter
for each block.

71
Activity 5:
USING THE COLOR SENSOR

Step 3

Group or consolidate all three color possibilities into one variable that can be used in the program.

Create one last variable called COLORFOUND.

Step 4

Attach each variable (RED, GREEN, and BLUE) to a


LIST. The LIST will allow us to verify that a color is
being read. From this command we will not capture
which color is being read, we will just verify that a valid
color from the list is being read.

Select the Create List With block.

72
Activity 5:
USING THE COLOR SENSOR

In order to put each variable’s value into the list, we


need to attach each variable to the list.

Attach the variable to all three empty links on the


create list with block.

Drag over the Sum of List block. This block is a


RETURN DATA TYPE command. It will allow us to
look statistically at the data from the list.

Using the blocks drop down, change SUM to MAX.


Each time a color from the list is read, they will
report a 1 to the RETURN DATA TYPE block (for
this activity, the color variables will only return a 1 or
0). This will allow it to detect if any color is read and
write either a 1 or 0 to our COLORFOUND variable.

Any Color Read, MAX value = 1

No Color Read, MAX value = 0

73
Activity 5:
USING THE COLOR SENSOR

The last step is to attach the LIST and the RETURN DATA block to
the variable COLORFOUND.

Connect all three elements together as seen below:

Final Variable - Max Value from the List - Individual Color Variables

We can now link all of our variables together in one grouping as seen below:

74
Activity 5:
USING THE COLOR SENSOR

Now that the sensor is setup, it needs to be tested to make sure everything is reading correctly. The
color sensor needs to report what color it is currently reading and is setup in Blockly to only read RED,
BLUE, and GREEN.

A loop needs to be created that will show in the Running Log the
following information:

IF the color is RED

Or IF the color is GREEN

Or IF the color is BLUE

This can be done by creating an IF/ELSE IF/ELSE Loop.

There are two new commands that will be needed to check the
cube’s color and decide which location to take the cube to.

1. If/Else If/Else Statement.

2. IdentifyColor - Uses the current value from the color sensor.

“If” statements are used when 2 or more conditions need to be evaluated. A three part “If” statement
needs to be set up.

IF the value is Identified as RED, do this.

ELSEIF the value is GREEN, do this.

ELSE do this (Else will be read as anything other than the RED or GREEN cube which will include
our BLUE cube.

Helpful Tips: The If structure used in this example will allow a NO CUBE or INVALID COLOR to be
read as BLUE since BLUE is setup as the else condition. If your program is only reading BLUE, it may
not be reading a color at all.

75
Activity 5:
USING THE COLOR SENSOR

In order to get the Logic If statement to expand to the


three conditions we need, click on the gear next to the
word if.

Drag the Else If over to the bottom pin connection


of the If in the expansion window.

Do the same for the else.

This will build the three part IF statement that we


need.

Conditions now must be made for when each level


of the IF structure runs.

Drag over the Return True block from the logic


section.

This block will allow us to compare the variable


value COLORFOUND to each individual color
variable.

When these two match (1 is equal to 1), that level of


the IF structure will be ran.

76
Activity 5:
USING THE COLOR SENSOR

Place the variable COLORFOUND and the variable


RED inside the Return True block.

We now need to fill in our If/Else If/Else


Statements.

If it is RED, stop evaluating and DO the


statements included with the IF

If it is not RED, it must be GREEN or BLUE

If it is GREEN, stop evaluating and DO the


statements included with the ELSE IF

If it is not GREEN, it must be BLUE. Stop


evaluating and DO the statements included with
the ELSE

As our programs start getting more complex, it may


help to start adding print commands to the code in
order to make it easier to troubleshoot.

Add the Print block into each statement. These


values will report to the Running Log so that you
can see what is going on in the program.

77
Activity 5:
USING THE COLOR SENSOR

We now have three separate groups of code


1. Setting Up Inputs and Outputs

2. Setting Up Variables

3. If Structure

In order to get the If statements to constantly look for


new values, both the variables and the If structure
need to be put into a Forever Loop

We will also add a small delay (from the DobotAPI/


Basic section) to slow down the looping process at
the beginning of each loop.

78
Activity 5:
USING THE COLOR SENSOR

Add together our header code and the color


checking code so that it looks like the diagram here.

Once the program is completed, run it and see if it works correctly. Every time you put a colored block
in front of the sensor, you should see the correct color reported in the running log. If it does not work,
troubleshoot it until it does.

Points for discussion:

What does the sensor reads when there is no cube placed on the sensor?

What happens if you put the yellow cube on the sensor?

What type of reading do you get as you raise the cube up and away from the sensor?

Sometimes you will get a single missed, or incorrect reading as it changes between colors. Why?

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

79
Activity 5:
USING THE COLOR SENSOR

TROUBLESHOOTING

Checking Individual Variables

Develop a code similar to the one on the


right.

The print can be replaced with each


variable to isolate which ones are ready
correctly, and which ones are not.

Each variable should read as 1 when


they are true and 0 when they are false.
The COLORFOUND will read as a 1 if it
detects RED, GREEN, or BLUE (YELLOW
reads as GREEN).

Helpful Tips: The color sensor works best if the object is held at a consistent distance from the
sensor Dobot suggested distance = (5mm to 10mm) or (1/4 to 3/8).

Helpful Tips: The different versions of the color sensors can come with different shades of colored
cubes. The V1 sensors tend to come with a lighter green and blue than the V2 sensors. This can cause
an issue with the sensors reading correctly. The V2 sensor tend to be more forgiving when it comes to
shades of colors. Remember that the color sensor is an analog sensor that reports a range of variable
values as it detects colors to the program. Since we cannot see or adjust this number, you may need to
play around with different colors and distances.

80
Activity 5:
USING THE COLOR SENSOR

Now that we have the color sensor reading


correctly, we can start developing the rest of the
program.

In order to keep our program short and organized


we will use several functions/voids.

Create the first function which will house all of our


variables for the entire activity.

Call this function setvariables.

Helpful Tips: The Z values can be shared for both the pick and place positions.

The X Value can be shared for all of the place positions.

The Lower Z Value for the Color Sensor needs to be about 10mm above the sensor face. This height
allows the sensor to catch the reflection off the block to determine its color.

The second Function will go and get the block from


a common location and JUMP to the Z ATCheck for
the color sensor.

Call this function getblock.

81
Activity 5:
USING THE COLOR SENSOR

Add all the necessary JumpTo and MoveTo


commands for each individual color.

The blocks are in a row. They should all share the


same X value.

Once the If Statements are complete, we will place it


into its own function labeled sort.

Each Statement will include:


1. A short DelayTime before the IF Statement
to ensure the cube is in place and the color
has been evaluated correctly (Remember
some of the error readings you may have
received earlier during your testing)

1. Jump to correct color sort location

2. Turn the Vacuum off

3. Delay - 1 Second

4. Move up

Finish developing the main program by creating two


loops:
1. Forever Loop

2. Conditional Input Loop

a. Get the block and move it to the sensor

b. Identify the color and move it to the correct


location

c. Move to home

82
Activity 5:
USING THE COLOR SENSOR

All of the separate sections of the program should look like this.

Helpful Tips: Be sure to consult the Dobot Input/Output Guide if you want to use other inputs and
outputs, as damage to your robot or your other equipment may result.

Once the program is completed, run it and see if it works correctly. If it does not work, troubleshoot it
until it does. Issues with the colors? See a simple color checking program below the “Going Beyond
Section.”

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

83
Activity 5:
USING THE COLOR SENSOR

CONCLUSION

1. What happens if a block isn’t there when the color sensor is told to get a color with the current
program? Give a reason why.

2. How might you keep track of how many blocks there are of each color?

GOING BEYOND

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

1. Randomly arrange cubes in a 3x3 palletized matrix for the robot to pick from. After
determining its color, drop the cube off at a specific color location. Manually remove
the cube once it has been placed.

2. Have the robot stack the cubes in columns by color.

3. Color the 9 squares on the Dobot field diagram either red, blue, or green. You will then
write a program that takes cubes from a cube matrix and puts the respective color
cubes on the colored squares.

84
Activity 6:
START & STOP CONVEYOR

INTRODUCTION

Robotic arms need to communicate with each


other as well as other peripherals such as
conveyor belts or linear rails in order to move
materials or products through stages of a work
cell.

In this activity you will learn how to program a


robot to control a conveyor belt. We will use an
Infrared Sensor to create a closed loop system.

Helpful Tips: NEVER wire anything to the Dobot Magician while it has power on. ALWAYS shutdown
the Dobot before making connections or damage to the robot could occur.

KEY VOCABULARY

• Stepper Motor • Output


• Conveyor Belt • IR - Infrared Sensor

EQUIPMENT & SUPPLIES

• Robot Magician • 1” cylinders or cubes


• DobotStudio software • Dobot Input/Output Guide
• Dobot Field Diagram • Dobot Conveyor
• Suction Cup Gripper • IR Sensor

ESSENTIAL QUESTIONS

Essential questions answered in this activity include:


• Is the conveyor an input or an output to the robot?
• Is the Infrared sensor an input or an output?
• How do I wire the components together?
• What can I do with the infrared sensor?
• How do I code the conveyor in blockly?
• How do I code the infrared sensor in blockly?

85
Activity 6:
START & STOP CONVEYOR

PROCEDURE

Order of Operations
• The Robot will pick up a cube from a known location and place it on the conveyor belt.
• The Robot will return home and then start the conveyor belt.
• The conveyor belt will run until the block arrives at the IR Sensor for inspection.
• The block will be manually removed from the belt, inspected and then returned to the belt.
• Once the block is returned to the belt, the belt will run again until the parts runs off the belt and into
storage.
• The process will loop forever.

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 robot with the suction cup gripper.

2. Plug the Conveyor Belt into STEPPER2 of Robot and plug the IR sensor into GP5 of the Robot.

86
Activity 6:
START & STOP CONVEYOR

Open up Blockly in the software.

Helpful Tips: NEVER wire anything to the


Dobot Magician while it has power on. ALWAYS
shutdown the Dobot before making connections or
damage to the robot could occur.

The first step will be to setup all of our INPUT and


OUTPUT ports.

Drag over the SetPhotoelectricSensor block from


the DobotAPI/Additional tool box.

Set the sensor to ON / V2 / GP5

Drag over the SetConveyor from the DobotAPI/


Additional tool box.

Set the conveyor to Stepper 1 / 60 mm/s

Once the header code in established, we are going


to write a quick code that will turn on the conveyor
for 5 seconds

In this example, I have used 60 mm/s for the speed


of the conveyor. Play with this value until you have a
controllable speed for this activity.

Once the program is completed, run it and see if it


works correctly. If it does not work, troubleshoot it
until it does.

87
Activity 6:
START & STOP CONVEYOR

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

We will now edit our current code to get the


conveyor belt to stop when an object is detected by
the IR Sensor.

Remove the DelayTime from the program.

Create a loop that will keep checking the IR Sensor


value until an object is detected.

Bring over a RepeatWhile loop.

Change the loop into a RepeatUntil Loop.

88
Activity 6:
START & STOP CONVEYOR

Create a condition that evaluates the IR sensors


value. We are looking for the sensors value to
change from 0 to 1.

The IR Sensor reads true/high when an object


is present. The small LED on the back of the IR
Sensor will also light up.

Drag over the ReturnTrue condition from the Logic


Toolbox.

Drag over the GetPhotoelectricSensor from the


DobotAPI/Additional Toolbox.

Drag over the Number Block from the Math


Toolbox.

Add all three blocks together to complete the


statement.

Make sure to change the GetPhotoelectricSensor


value from GP1 to GP4 and the number value to 1

Add the condition statement to the RepeatUntil


loop.

Add a small DelayTime into the RepeatUntil loop


in order to give the operation something to process.

89
Activity 6:
START & STOP CONVEYOR

Put together the code that we have so far.

Run the program. Place a cube in front of the sensor.


The conveyor should stop.

If it does not work, troubleshoot it until it does.

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

Now that we can start and stop the conveyor using


the IR Sensor we can find our positions and set our
variables for this activity.

Place the variables and positions in a function as has


been done in previous activities.

90
Activity 6:
START & STOP CONVEYOR

Add the variables Function to the beginning of your


program.

Create a Function for the Pick and Place operation.


• Pick up the cube
• Place it on the belt
• Return home

Pull the main program apart between the first two


SetConveyor blocks.

Drag over and create a Forever Loop.

91
Activity 6:
START & STOP CONVEYOR

Start developing the loop.

Consider the order of operations:


• Start with the robot at a Home position.
• Pick and Place - Get the block and put it in the
belt and return to home.
• Start the belt and run it until the cube reaches
the sensor.
• Stop the belt.

As the program starts getting more complex, it may


help to start adding print commands to the code to
be able to troubleshoot the code

Add them anywhere in the program where an


operation may be changing or a value may be read.

Assemble the code that we have so far.

92
Activity 6:
START & STOP CONVEYOR

Once the program is completed, run it and see if it works correctly. If it does not work, troubleshoot it
until it does.

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

Reminder:

This activity requires the following operations:


• The Robot will pick up a cube from a known location and place it on the conveyor belt.
• The Robot will return home and then start the conveyor belt.
• The conveyor belt will run until the block arrives at the IR Sensor for inspection.
• The block will be manually removed from the belt, inspected and then returned to the belt.
• Once the block is returned to the belt, the belt will run again until the parts runs off the belt and
into storage.
• The process will loop forever.

The next step is to create a loop that will allow the block to be removed and then wait for it to be
returned. The issue is that we have no idea when the block has been removed, how long it will take for
the inspection, or when it will be returned.

We need to create a closed loop system that will look for the following conditions without respect to
time.

The Block has been REMOVED


The Block has been RETURNED

93
Activity 6:
START & STOP CONVEYOR

These two conditions can be developed using two


separate RepeatUntil Loops just as we did for
stopping the conveyor.

One that will wait for a ‘0’ and one that will wait for
a ‘1’

Place a small DelayTime in between the two loops


to keep them separate and then add them into our
main loop

Some of this program can be condensed into


separate functions in order to simplify the
main program.

94
Activity 6:
START & STOP CONVEYOR

Our final task is to start the conveyor again and run


the part off the end and into a container. Use the
same code you started with to accomplish this task.
The time needed to run the part off the conveyor will
be different for each project, depending on where
the sensor is mounted.

Place a small DelayTime in front of the code to


allow time for the user to get their hand away from
the belt before it starts running.

Add this last group inside the end of your


Forever Loop.

95
Activity 6:
START & STOP CONVEYOR

Once the program is written, try it and make sure that it works as expected. If it does not work
correctly, troubleshoot until it does.

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

96
Activity 6:
START & STOP CONVEYOR

CONCLUSION

1. Why is it better to have the infrared sensor stopping the conveyor belt rather than just running it for
time?

2. How would the program be different if the conveyor belt could not be run as a linear rail?

3. What’s one way to determine where the robot is at any given time in the program?

GOING BEYOND

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

1. Use functions to make your program as short as possible.

2. Use the color sensor and make the robot report what color block is being sent down
the conveyor.

97
Presentation 2:
BLOCKLY & DOBOT - HARDWARE CONNECTIONS

98
Presentation 2:
BLOCKLY & DOBOT - HARDWARE CONNECTIONS

99
Presentation 2:
BLOCKLY & DOBOT - HARDWARE CONNECTIONS

100
Presentation 2:
BLOCKLY & DOBOT - HARDWARE CONNECTIONS

101
Presentation 2:
BLOCKLY & DOBOT - HARDWARE CONNECTIONS

102
Presentation 2:
BLOCKLY & DOBOT - HARDWARE CONNECTIONS

103
Presentation 2:
BLOCKLY & DOBOT - HARDWARE CONNECTIONS

104
Activity 7:
DOBOT TO DOBOT HANDSHAKING

INTRODUCTION

Robotic arms need to communicate with other robots in


a work cell, or factory. This is called HANDSHAKING and
can be done between different machines, devices and
robots. It is a very simple form of communication and is
done with simple ones and zeros; or “ons” and “offs”.

In this activity you will learn how to make a robot


handshake with another robot.

Robot 1 will pass a part into another robot’s work


envelope, go to a safe position and then send a signal
to other robot. The signal received by the other robot
will initiate a sequence to get the part, and place it
somewhere else.

Caution: NEVER wire anything to the Dobot Magician while it has power on. ALWAYS shutdown
the Dobot before making connections or damage to the robot could occur.

KEY VOCABULARY

• Input • Function / Voids


• Output • Handshaking

EQUIPMENT & SUPPLIES

• 2 Robot Magicians • Dobot Input/Output Guide


• DobotStudio software • Suction Cup Gripper
• 1” cylinders or cubes • Handshake Modules

ESSENTIAL QUESTIONS

Essential questions answered in this activity include:


• How do I make a robot send a signal?
• How do I get a robot to receive a signal?
• How is this done in Dobot Studio Software?
• How do I make two robots talk to one another?

105
Activity 7:
DOBOT TO DOBOT HANDSHAKING

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 both Robots with a suction cups - GP1 & SW1 and place

2. Dobot field diagrams, taped to the work surface, between the two robots.

3. Wire Robot1 with an OUTPUT signal GP2 - EIO13.

4. Wire Robot2 with an INPUT signal GP5 - EIO5.

5. Wire both Robots to the Handshaking module as shown in the following


pages. Be sure that wires are not going to be pulled out by the motion of
the robots.

Open Loop System Block Diagram: Robot #1 acts as the input for robot #2. Robot #2 does not
communicate back to robot #1 so there is no feedback. The Handshake Module acts as the device
that helps make the handshake happen safely.

Order Of Operations
ROBOT 1 - OUTPUT SIGNAL ROBOT 2 - INPUT SIGNAL
• Move - Home • Move - Home
• Move - ABPick • Move - ABPick
• Move - ATPick • Move - ATPick
• Jump - ATPlace • Jump - ATPlace
• Move - ABPlace • Move - ABPlace
• Move - Home • Move - Home
• Send Output Signal • Wait for INPUT Signal

106
Activity 7:
DOBOT TO DOBOT HANDSHAKING

Open up Blockly in the software.

Helpful Tips: When you re-open this program


check that the name of the file on top matches
the code in the file, if it does not, you may end up
overwriting another program.

107
Activity 7:
DOBOT TO DOBOT HANDSHAKING

How to SEND an OUTPUT signal.

The first part of this activity will focus on how to


send a signal.

In order to make sure our setup, wiring, and program


are all correct, we will only use ONE ROBOT.

Nothing should be connected to the Output side of


the handshake module.

Drag over the SetIOMultiplexing block from the


DobotAPI/ I/O Toolbox.

Change the settings to OUTPUT 5V and EIO13.


In order to test the OUTPUT signal, we will create a
simple program that loops the process of turning on
and off the output.

108
Activity 7:
DOBOT TO DOBOT HANDSHAKING

Drag over the RepeatTimes Loop.

10 times should be enough to ensure our setup is


working correctly so make it repeat this many times.

Drag over the Set5VOutput block from the


DobotAPI/ I/O Toolbox.

Add the block to our loop.

Set the port to EIO13

Set Enabled to ON

Insert a TimeDelay under the Set5VOutput block.


Set it to send the signal for two seconds.

Duplicate both steps.

Set Enabled to OFF

109
Activity 7:
DOBOT TO DOBOT HANDSHAKING

Once this portion of the program is completed, run it and see if it works correctly. The LED on the
handshake module should light up whenever EIO13 is enabled ON. If it does not work, troubleshoot it
until it does.

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

TROUBLESHOOTING THE OPTICAL ISOLATOR

Helpful Tips: The LED helps us determine if the signal is actually being sent by the first robot. We
can write a simple Blockly program to see if the second robot is getting the signal. The issue is if the
second robot is not getting the signal….. WHY is it not getting the signal? It could be a damaged
optical isolator.

An easy way to check is to use a voltage meter set to check RESISTANCE. When no signal is present,
the voltmeter should read “O.L” or “---”. When a signal is present it should read near the resistance
value of the resistor used.

110
Activity 7:
DOBOT TO DOBOT HANDSHAKING

Programming for ROBOT 1

Throughout the remainder of this activity, we will use many of the skills that you have developed in
previous activities. If you need clarification at any point, you can go back to the other activities for
more information.

As we have done in the past,


• Create Functions
• Create Variables
• Find Positions

Create a new Function - SendSignal.

Put the program together.

111
Activity 7:
DOBOT TO DOBOT HANDSHAKING

Programming for ROBOT 2

Throughout the remainder of this activity, we will make assumptions that you have already learned
several concepts in previous activities.

As we have done in the past,


• Create Functions
• Create Variables
• Find Positions

Create a RepeatUntil Loop to wait for the signal.

Helpful Tips: Reminder!! Your repeat until will


need to wait for a Zero/Low signal for the Magician
V2 and a One/High signal for the Magician V1

Put the different parts of the program together.

112
Activity 7:
DOBOT TO DOBOT HANDSHAKING

USE A LIMIT SWITCH HARDWIRED TO THE ARM


FOR TESTING THIS PROGRAM

Once this portion of the program is completed, run


it and see if it works correctly. If it does not work,
troubleshoot it until it does.

When you press the switch, what happens?

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

Consider adding Print to Running Log commands to


both programs so that you can see what the robot is
doing at any given time.

Now that both programs are created AND tested, it is time to put it all together.

Finish the Handshake Module and replace the manual limit switch on ROBOT 2 with the breadboard
connection.

113
Activity 7:
DOBOT TO DOBOT HANDSHAKING

Dobot Magician V1 (All White IO Ports) Dobot Magician V2 (Colored IO Ports)

Caution: Be sure to consult the Dobot Input/Output Guide if you want to use other inputs and
outputs, as damage to your robot or your other equipment may result.

Once the program is completed, run it and see if it works correctly. If it does not work, troubleshoot it
until it does.

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

114
Activity 7:
DOBOT TO DOBOT HANDSHAKING

CONCLUSION

1. What would you have to do to make this program run five times without any human intervention?
Explain fully below.

2. What other inputs could you use on your robot to start this process? Use the Dobot Input/Output
Guide to answer this question, and do not attempt to try it without your instructor’s permission.

3. What other outputs could you use on your robot to start this process? Use the Dobot Input/Output
Guide to answer this question, and do not attempt to try it without your instructor’s permission.

GOING BEYOND

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

1. Change the LEDs to Motors. Be sure to get your instructor’s permission, and be sure
to use the correct outputs for the motor chosen.

Caution: Be sure to consult the Dobot Input/Output Guide if you want to use other inputs and
outputs, as damage to your robot or your other equipment may result.

115
Activity 8:
HANDSHAKING - ARDUINO TO ARDUINO

INTRODUCTION

Often the process of handshaking goes


beyond a robot’s need to communicate with
another robot. In industry the process of
have Programmable Logic Controllers (PLCs)
communicate with each other, or robotic arms
can be just as simple as having two robots
communicate. It is a very simple form of
communication and is done with simple ones
and zeros; or “ons” and “offs”.

In this activity we will reuse the theory


of communicating with simple ones and
zeros; or “ons” and “offs” from the previous
activity. We will replace the robots with two
microcontrollers. For this activity, we will focus
on the wiring and syntax programming for two
Arduino microcontrollers.

The limit switch attached to each microcontroller will control the on and off function of the other
controller’s motor.

Helpful Tips: This activity was written for arduino uno microcontrollers, but the principles taught in this
activity could be applied to any other microcontroller as well. The principles of communication between
devices are the same, but the hardware and software setup may be different. Even when using different
“brands” of arduinos, the programming may be a bit different. If you try something as presented here,
and it does not work with your microcontroller, you may have to do some troubleshooting to get it to
work. It is also advisable to check the documentation for microcontrollers, as well as any user forums
on line as well.

KEY VOCABULARY

• Limit Switch
• If/Else Statement
• Loop
• Void/Function
• Handshaking

116
Activity 8:
HANDSHAKING - ARDUINO TO ARDUINO

EQUIPMENT & SUPPLIES

• 2 Arduino Uno Microcontrollers • 2 USB Cables


• Handshake Modules • 4 100 Ohm Resistors
• 2 Limit Switches • Jumper Wires
• 4 LEDs • 2 4.7K Ohm Resistors

ESSENTIAL QUESTIONS

Essential questions answered in this activity include:


• How do I make my microcontroller send and receive signals?
• What kind of software is necessary to communicate?
• How do I wire the hardware to communicate?
• How do I troubleshoot a complex system?

PROCEDURE

Each Arduino will be able to control the ON/OFF of the LED on the other Arduino.
1. The digital output of each Arduino will be attached to a digital input of the other Arduino

2. A SPST Normally Open (N.O.) limit switch will be connected to each Arduino

3. An LED will be used as a controllable output on each LED

4. Build and wire 2 handshake modules. One as seen below and one mirrored.

The wiring diagram to send a signal one way is shown below:

117
Activity 8:
HANDSHAKING - ARDUINO TO ARDUINO

118
Activity 8:
HANDSHAKING - ARDUINO TO ARDUINO

Wire a limit switch to each Arduino on dgtl2.

Repeat the process for the other Arduino.

Wire an LED to dgtl12.

Repeat the process for the other Arduino.

119
Activity 8:
HANDSHAKING - ARDUINO TO ARDUINO

Once all of the wiring is complete start developing


the syntax programming for this activity. Start by
defining the individual steps that will control each
individual microcontroller (the program for one
controller should be identical to the other)

Now take care of the other conditions. …

What has to be done when we are not sending or receiving signals?

Start by grouping individual steps into like groups.

120
Activity 8:
HANDSHAKING - ARDUINO TO ARDUINO

We should notice that there are only two possible


situations for each grouping. It is, or is not. We can
simplify our code to: “If a specific condition is met,
do operation 1 else, do operation 2”.

OR

We will use a digitalRead() command to evaluate if an


input signal is high or low.

Helpful Tips: Reminder

1 (=) sets a value

2 (==) evaluates a value

Because we are using dgtl2 as a pullup input, all of


its values will read backwards. On is Off and Off is
on… HIGH is OFF and LOW is ON.

Now simplify the code down to only the essentials.

121
Activity 8:
HANDSHAKING - ARDUINO TO ARDUINO

Instead of having to read the condition in our IF


statement as digitalRead(2), we can set the port
value to a variable. This will make reading and
troubleshooting our programs easier.

An example is shown to the right.

We can now use limitSwitch in place if


digitalRead(2).

In order to get the program to constantly evaluate


either or both situations (multiple If statements can
be true at one time) put the program inside the
function LOOP.

Use the digitalWrite command each time we need to


turn on and off the digital output.

The entire program is shown in the example here:

122
Activity 8:
HANDSHAKING - ARDUINO TO ARDUINO

123
Activity 8:
HANDSHAKING - ARDUINO TO ARDUINO

Once this portion of the program is completed, run it and see if it works correctly. If it does not work,
troubleshoot it until it does.

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

TROUBLESHOOTING THE OPTICAL ISOLATOR

Helpful Tips: When the digital Output is turned on / high, the LED on the handshake module
should turn on.

If the Debugger window reads correctly, the LED turns on, but no signal is being seen by the other
Arduino, check your wiring. As a last resort, the Optical Isolator could be damaged. Ask your instructor
to help you evaluate the signal side of the Isolator using a voltmeter and the images below. Voltmeter
should be set to OHMS. The meter should read zero when no signal is present and approximately the
value of the resistor used on the signal side when a signal is present.

124
Activity 8:
HANDSHAKING - ARDUINO TO ARDUINO

CONCLUSION

1. What are some similarities of microcontroller programming and blockly? List at least two and
explain how they are similar.

2. What are some differences between microcontroller programming and blockly? List at least two
and explain how they are different.

3. Why is it important to use the optical isolator when communicating? Explain in your own words.

125
Activity 8:
HANDSHAKING - ARDUINO TO ARDUINO

GOING BEYOND

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

1. Use a motor instead of an LED. Be sure to consider what type of motor you are using,
and be sure to check with your teacher before attempting this; especially if you switch
outputs on the microcontroller.

126
Activity 9:
HANDSHAKING - VEX TO VEX

INTRODUCTION

Often the process of handshaking goes


beyond a robot’s need to communicate with
another robot. In industry the process of
have Programmable Logic Controllers (PLCs)
communicate with each other, or Robotic arms
can be just as simple as having two robots
communicate. It is a very simple form of
communication and is done with simple ones
and zeros; or “ons” and “offs.”

In this activity we will reuse the theory


of communicating with simple ones and
zeros; or “ons” and “offs” from the previous
activity. We will replace the robots with two
microcontrollers. For this activity, we will focus
on the wiring and syntax programming for two
VEX microcontrollers.

The limit switch attached to each


microcontroller will control the on and off
function of the other controllers motor.

KEY VOCABULARY

• Limit Switch
• If/Else Statement
• While True Loop (Forever Loop)
• Handshaking

EQUIPMENT & SUPPLIES

• 2 VEX Cortex • 2 VEX Cables


• Handshake Modules • 2 VEX Batteries
• 2 Limit Switches • Servo Extension Cables
• 2 Motors

127
Activity 9:
HANDSHAKING - VEX TO VEX

ESSENTIAL QUESTIONS

Essential questions answered in this activity include:


• How do I make my VEX Cortex send and receive signals?
• What kind of software is necessary to communicate?
• How do I wire the hardware to communicate?
• How is RobotC similar to Arduino software? How is it different?

PROCEDURE

1. The digital output of each Cortex (dgtl1) will be attached to a touch input (dgtl2) of the other
Cortex.

2. Build and wire 2 handshake modules. One as seen below and one mirrored.

128
Activity 9:
HANDSHAKING - VEX TO VEX

Wire a limit switch to each cortex as a


Touch on dgtl3.

Repeat the process for the other Cortex.

Wire a motor to either motor port 1 or port 2.

Repeat the process for the other Cortex.

129
Activity 9:
HANDSHAKING - VEX TO VEX

Once all of the wiring is complete develop the syntax


programming for this activity. Start by defining the
actions that will control each individual microcontroller
(the program for one controller should be identical to
the other).

Define the other conditions. … What to do when no


signal is sent or received.

Now start grouping our individual actions into like


groups.

130
Activity 9:
HANDSHAKING - VEX TO VEX

We should notice that there are only two possible


situations for each grouping. It is, or is not. We can
simplify our code to If a specific condition is met, do
operation 1 else, do operation 2.

Now simplify the code down to only the essentials

In order to get the program to constantly evaluate


either or both situations (multiple If statements can
be true at one time) we will put our program in a
While True Loop

We will use the SensorValue command each time we


need to evaluate or a sensor value or turn on and off
the digital output.

131
Activity 9:
HANDSHAKING - VEX TO VEX

Helpful Tips: Reminder

1 (=) sets a value

2 (==) evaluates a value

An example of the entire program in RobotC is seen below.

Program Only Program with Comments

132
Activity 9:
HANDSHAKING - VEX TO VEX

Once this portion of the program is completed, run it and see if it works correctly. If it does not work,
troubleshoot it until it does.

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

133
Activity 9:
HANDSHAKING - VEX TO VEX

TROUBLESHOOTING THE OPTICAL ISOLATOR

Helpful Tips: Use the Debugger window to troubleshoot your program. When the Limit Switch is
pressed, both the dgtl1 (Send Signal) and dgtl3 (Limit Switch) should read true.

When the digital Output is turned on / high, the LED on the handshake module should turn on.

Helpful Tips: If the Debugger window reads correctly, the LED turns on, but no signal is being seen
by the other cortex, check your wiring. As a last resort, the Optical Isolator could be damaged. Ask
your instructor to help you evaluate the signal side of the Isolator using a voltmeter and the images
below. Voltmeter should be set to OHMS. The meter should read zero when no signal is present and
approximately the value of the resistor used on the signal side when a signal is present.

134
Activity 9:
HANDSHAKING - VEX TO VEX

CONCLUSION

1. What would you have to do to make this program run five times without any human intervention?
Explain fully below.

2. What other inputs could you use on your VEX Cortex to start this process? Use the Dobot Input/
Output Guide to answer this question, and do not attempt to try it without your instructor’s
permission.

3. What other outputs could you use on your VEX Cortex? Be sure to check with your instructor first!

GOING BEYOND

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

1. Change the Motors to servos. Be sure to get your instructor’s permission, and be sure
to use the correct inputs and outputs in RobotC.

135
Activity 10:
HANDSHAKING - DOBOT TO VEX

INTRODUCTION

Often robotic arms need to communicate with


other devices or controllers in a work cell, or
factory. This is called HANDSHAKING and can
be done between different machines, devices and
robots. It is a very simple form of communication
and is done with simple ones and zeros; or “ons”
and “offs.”

In this activity you will use all of the knowledge


learned in previous activities including activity
seven and eight to make a Dobot Magician Robot
communicate with a VEX cortex.

Caution: NEVER wire anything to the Dobot Magician while it has power on. ALWAYS shutdown
the Dobot before making connections or damage to the robot could occur.

KEY VOCABULARY

• Inputs and Outputs • Function / Voids


• Variables • Handshaking

EQUIPMENT & SUPPLIES

• Dobot Magician • Suction Cup Gripper


• VEX Cortex • Handshake Modules
• 1” cylinders or cubes • Various VEX parts for grinding station
• Simple VEX Grinding Station

ESSENTIAL QUESTIONS

Essential questions answered in this activity include:


• How do I get a robot to send and receive a signal?
• How do I make my microcontroller send and receive signals?
• How is this done in Dobot Studio Software?
• How do I wire the hardware to make this happen?
• How do I troubleshoot a complex robotic system?

136
Activity 10:
HANDSHAKING - DOBOT TO VEX

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 Robot with a suction cup - GP1 & SW1.

2. Wire Robot with an OUTPUT signal GP2 - EIO13.

3. Wire Robot with an INPUT signal GP5 - EIO5.

4. Wire the Microcontroller Digital Output (sendSig) to dgtl1 and the Touch (receiveSig) to dgtl2.

5. Wire both the Robot and the Microcontroller to the handshake modules as shown on the next
pages.

Order of Operations
ROBOT VEX - Microcontroller
• Move - Home • Wait for INPUT Signal
• Move - ABPick • Turn on Grinding Station
• Move - ATPick • Run the station for 3 seconds
• Pick Up Cube • Send OUTPUT signal to Dobot
• Jump - ATMachine
• Send OUTPUT signal to VEX
• Wait for INPUT Signal
• Jump- ATPick
• Release Cube
• Move - ABPick
• Move - Home

Open up Blockly in the software.

Helpful Tips: When you re-open this program


check that the name of the file on top matches
the code in the file, if it does not, you may end
up overwriting another program.

137
Activity 10:
HANDSHAKING - DOBOT TO VEX

DOBOT SETUP

SEND Output RECEIVE Input

138
Activity 10:
HANDSHAKING - DOBOT TO VEX

VEX MICROCONTROLLER SETUP

SEND Output RECEIVE Input

139
Activity 10:
HANDSHAKING - DOBOT TO VEX

Caution: Be sure to consult the Input/Output Guide if you want to use other inputs and outputs,
as damage to your robot or your other equipment may result.

Create a simple Grinding Station using VEX material.


Use the rubber intake wheel as the grinding wheel.

…Where’s the rest of the activity? If you need additional assistance, please refer to the previous
activities. All concepts were taught, and this one was left open ended so that you may apply what
you’ve learned.

Once the program is completed, run it and see if it works correctly. If it does not work, troubleshoot it
until it does.

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

140
Activity 10:
HANDSHAKING - DOBOT TO VEX

GOING BEYOND

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

1. Have the robot take blocks from a matrix, machine them, and drop them off at a
finished location (example: dropped into a bin).

2. Make another machine out of VEX parts and make the robot perform two operations.

3. Have the robot pick them up when a switch is hit, and then palletize them after
grinding.

141
Activity 11:
WORKCELL DESIGN

INTRODUCTION

A robotic workcell is defined as the complete


environment around a robot. This environment
may include tools, machines and/or other
robots.

In this activity you will use a robot and a


microcontroller system to recreate a workcell.
Your workcell will incorporate all of the devices
that you have learned about in previous
activities including:
• Inputs & outputs
• Sensors
• Conveyor belt
• Machines An example of a workcell using robots, prototyped
• Robots parts and VEX components

KEY VOCABULARY

• Handshaking • Optical Isolator


• Workcell • Sensor
• Output • Input
• Nesting • Palletize

EQUIPMENT & SUPPLIES

• Robot Magician(s) • Dobot Input/Output Guide


• DobotStudio software • Input & Output devices
• Microcontroller System & Components • Breadboard/wire/4N25 Optical Isolator and
• RobotC or other VEX control software 100 ohm & 4.7K ohm resistors
• 1” cylinders or cubes • VEX, PIC, Arduino may all be used in this
• Pneumatic Gripper or Suction Cup Gripper activity, but wiring may vary.
• Servo extension cables • Conveyor System
• Handshake device

142
Activity 11:
WORKCELL DESIGN

ESSENTIAL QUESTIONS

Essential questions answered in this activity include:


• How do you integrate robots and other parts of a workcell to complete a given task?
• How do you safely communicate between a microcontroller and a robot?
• What are the different types and styles of inputs and outputs needed to complete your given
tasks?
• Which end of arm tooling is most appropriate for your workcell?
• Where is it appropriate to use the jump command within my workcell?
• Where would it be appropriate in your programming to use either variables or functions while
programming?
• What components of blockly did you need to complete this task?
• What other software & hardware will I need to complete this task?

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. You and your team will design, organize, create, program and test a full work cell. Your instructor
will have you pick from the list below the items that must be included in your work cell.

Dobot Magician - # of __________ Dobot Color Sensor

Microcontroller - # of _________ Student Designed Storage System

Dobot Conveyor System Handshakes - # of __________

Student Designed Feeder System _____________________________

Dobot IR Sensor _____________________________

Student Designed Machine - # of ________ _____________________________

Machine Examples
• Pneumatic Stamping Press • Painting Station
• Rotary or Reciprocating Saw • Drying Station
• Welder • Drilling Station
• Quality Control Station • ???

143
Activity 11:
WORKCELL DESIGN

2. Be sure to note any additional parameters that are given to you by your instructor (due date, size
or storage requirements, and additional items from home. Take notes in the space below.

3. In the time allotted for this project design a workcell that includes the following:

a. Accurate Robot pick and place routines.

b. Jumps where appropriate.

c. Proper usage of Functions and Variables.

d. A simulation of a manufacturing process.

e. A palletize or stacking routine.

4. Create a video of your workcell.

Caution: Be sure to consult the Dobot Input/Output Guide if you want to use other inputs and
outputs, as damage to your robot or your other equipment may result.

144
Activity 11:
WORKCELL DESIGN

CONCLUSION

1. Make a flowchart/Process flowchart of your workcell as indicated by your instructor in the space
below.

2. What’s the pseudocode that you used for your microcontroller program? Copy and paste it here.

3. What are the inputs you used in your workcell?

4. What are the outputs you used in your workcell?

GOING BEYOND

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

1. Make your workcell communicate with someone else’s workcell in your class. When
your process ends, theirs begins.

2. Same as number one, but use the same part in both cells. In other words, perform 2
operations in two separate cells, on the same part.

145
BLOCKLY GLOSSARY

TYPE OF
VOCABULARY COMMAND DEFINITION
(if applicable)
Blockly A programming language used to program a Dobot
Magician. Lines of complex code are represented as
simple “blocks” that fit together to form programs. A
graphical programming method rather than text based.

ChooseEndTools Config A blockly config command that allows you to set the end
effector to be used in the program.

Comment Can be used in blockly to name a position, or add a


comment in English, that the program will not read.
These are commonly used as notes for the programmer
and the operator.

Condition This is what needs to be true in order for a set of


instructions or a program to continue. It is also very
useful in looping programs.

Delaytime Basic A blockly basic command that allows you to delay,


or pause in a program for a given amount of time in
seconds.

Forever loop A programming method used to make an instruction or a


set of instructions continue forever.

Function A named section of a program that performs a task. It


can also be considered a procedure or a routine and
greatly simplifies otherwise complicated programs.

GetADInput I/O A blockly I/O command that returns the value of a


specified analog input. This can only work with analog
inputs 1, 5, 7, 9, 12, and 15.

GetCurrentCoordinate Motion A blockly motion command that returns the XYZ values
of the robot’s current position.

GetJointAngle Motion A blockly motion command that returns the value of a


specified robot joint.

GetLevelInput I/O A blockly I/O command that returns the value of a


specified input.

GetPhotoelectricSensor Additional A blockly additional command that returns the value of the
sensor plugged into a given port.

146
BLOCKLY GLOSSARY

Function A named section of a program that performs a task. It


can also be considered a procedure or a routine and
greatly simplifies otherwise complicated programs. Also
called a Void.

Gripper Motion A blockly basic command.

Home Basic The same as an axis movement; Movement of a robot's


end effector in a straight line on the X, Y or Z axis.

IdentifyColor Additional A blockly additional command that allows you to choose


what color to identify with the color sensor: red, green, or
blue.

If/Else If/Else Logic A blockly logic command that allows a branch in a


program. It compares two or more sets of data and if it is
true it does one thing, if false it will do another.

JumpTo Motion A blockly motion command that will move from one point
to another, while increasing the Z height, causing the
robot to “jump” to the next position. The default is set to
20 mm.

Laser Additional A blockly additional command that turns the laser on and
off and allows you to set the power.

Matrix A rectangular array of parts made of a finite number of


rows and columns. A good example is an array of boxes
on a pallet.

MoveDistance Motion A blockly motion command that allows you to move


the robot’s end effector relative to where it’s position is
presently in its work envelope.

MoveLinearRailTo Additional A blockly additional command that allows you to move


the Linear slide rail to any given point.

MoveTo Motion A blockly motion command that allows you to move the
robot’s end effector to a given XYZ coordinate within the
robot’s work envelope.

NumberBlock Math A blockly math command that allows you to set a


variable to a number.

Placeholder A value used to fill in a blank in a program to be changed


to a different value, once that value is determined. For
example, the values of XYZ in a program do not need to
be known before you write the program.

147
BLOCKLY GLOSSARY

Repeat Loop A blockly loop command that allows you to make a set of
instructions repeat a given number of times.

ReturnSum Math A blockly math command that can be used to easily


change a variable.

SetColorSensor Additional A blockly additional command that allows to turn the


color sensor on and off, what version it is, and what port
it is plugged in to.

SetConveyor Additional A blockly additional command that allows you tell the
program where it is plugged in, and what speed you want
it to move at n mm per second.

SetCoordinateSpeed Config A blockly config command.

SetEndEffectorParams Config A blockly config command that allows you to offset the
XYZ position of an end effector.

SetJointAngle Motion A blockly motion command that allows you to move an


individual joint on the robot.

SetJointSpeed Config A blockly config command.

SetJumpHeight Config A blockly config command that allows you to set the
jump height in a program.

SetLinearRailSpeed Config A blockly config command that allows you to set the
velocity and acceleration of the attached linear rail.

SetLinearSlideRail Additional A blockly additional command that allows you to tell the
program what version of the slide rail you are using, and
whether you want it on or off.

SetIOMultiplexing I/O A blockly I/O command.

SetLostStepParams Config A blockly config command.

SetMotionRatio Config A blockly config command that allows you to set a


default velocity and acceleration of a robot’s moves
between positions.

SetPhotoelectricSensor Additional A blockly additional command that allows you to turn the
photoelectric sensor on or off, tell it what version it is that
is plugged in, and what port it is plugged into.

SetItem Variable A blockly command that allows you to set a new variable
or change a variable within a program.

148
BLOCKLY GLOSSARY

SetR Motion A blockly motion command.

SuctionCup{ON/OFF] Motion A blockly motion command that turns the suction cup on
or off.

True Logic A blockly logic command that can be used to create a


forever loop.

Variable A changeable quantity in a program that can be


represented by a word or a letter. Variables can be
assigned, changed, or referenced throughout a program.

While loop Loop A programming method to make an instruction or set of


instructions continue or repeat if a condition is true.

149
FIELD DIAGRAMS

150
FIELD DIAGRAMS

151

You might also like