ev3 software ev3 robot workshop
DESCRIPTION
Course Overview 2015 Robofest competition RoboGolf SPbot introduction Using the SPbot to solve the RoboGolf challengeTRANSCRIPT
EV3 SoftwareEV3 RobotWorkshop
Lawrence Technological University
Instructor:Assistants:
• 2015 Robofest competition RoboGolf
• SPbot introduction
• Using the SPbot to solve the RoboGolf challenge
Course Overview
2
• Video overview• https://www.youtube.com/watch?v=bgDL4n1xs3U&feature=youtu.be
• Key tasks– Find the edge of the table– Follow the edge of the table– Find a putting green– Find the golf ball– Aim for the hole
– Mathematics to locate the center hole– Rotate the robot to putt
– Putt the golf ball
2016 Robofest competition
3
• Please note that putting the golf balls is beyond the scope of this workshop
2016 Robofest competition
4
LEGO EV3 robot used – SPbot
Color Sensor 1
EV3 Computer
Left Motor: B
Right Motor: C Touch Sensor
Sonar Sensor
Color Sensor 2
• Left Motor connects to B• Right Motor connects to C
– If your motors are upside down forward will be backwards in your program
• Color sensor 1 connects to port no. 1• Color sensor 2 connects to port no. 2• Touch sensor connects to port no. 3• Sonar sensor connects to port no. 4
Remember the connections!
6
Please note that the retail version of EV3 comes with an infrared sensor, not a sonar sensor.
• Examples use EV3 Educational Version 1.1.1 or Home Edition Version 1.1.1
• EV3 Firmware version: V1.06H
• PowerPoint and all example programs are available at robofest.net under Tech Resources
EV3 Versions Used
7
• LEGO offers a home edition of the EV3 software
• It is free to download and use– Limited sensors enabled
• You can download blocks for additional sensors
• Download at
Other EV3 Versions
8
http://www.lego.com/en-us/mindstorms/downloads/download-software/
9
Task 0
Find the edge of the table
• Using wait block
• Using loop block
Task 0: Example Solutions
10
Brick Overview
12
Task 1
Follow the edge of the table
• Use the zig-zag method to follow the edge of the table
• Edge following is also referred to as line following
• We need to determine when the robot is on or off the table
Follow The Edge Of The Table
13
Rig
ht E
dge
Left
Edge
Table
• Get color sensor values to determine when the robot is on or off the table and putting green. We will use the color sensor in Reflective Light Intensity mode.
• Color Sensor 1 Color Sensor 2– Off table = ______ (10) On green = ______
(20)– On table = ______ (60) On table = ______
(60)
Follow The Edge Of The Table
14
ColorSensor
Readings
• Light sensor settings example– Off table = 10– On table = 60– Median threshold = (10+60)/2 = 35
• Two cases– Light sensor reading > 35. On table.– Light sensor reading < 35. Off table.
Follow The Edge Of The Table
15
Simple Line Following Algorithm
16Program: LineFollowZZ.ev3 YouTube: https://youtu.be/3UIdveO7fT4
• Zig-zag method can cause a bumpy response• To improve the response, you can use a 3-level
line follower (concept shown below)
How to improve our line following algorithm
17
Off Table Off TableOn Table On Table
18
Task 2
Find a putting green
• One method of finding a putting green requires two color sensors– Sensor 1 used to follow the edge of the table– Sensor 2 used to locate the putting green
• General idea– Follow the edge of the table until the second color
sensor detects a putting green
Find A Putting Green
19
• Recall our line following program LineFollowZZ– Let’s modify the program to stop when the robot
reaches the putting green
Find A Putting Green
20
Using this program, the robot will line follow continuously. How can we make the robot stop when it reaches a putting green?
Find A Putting Green
21Program: LineFollowZZStop.ev3 YouTube: https://youtu.be/7uajAXAZjqo
22
Task 3
Find the golf ball
• General idea– Let’s assume we located the putting green and we
know where the golf ball is on the green relative to the edge of the green
– How can we begin to position our robot to putt?
Find The Golf Ball
23
• Example
Find The Golf Ball
24
Robotm
• Follow the edge of the putting green a distance “m”
• This will position the robot in line with the golf ball
m = 11 cm for the Junior Division. What about the Senior Division?
• How to find “m” given n/m– From the diagram of the putting green we have
– Let’s assume that n/m = X (X is known)– Now we can solve for m
Find The Golf Ball
25
𝑛+𝑚=22cm
𝑛𝑚=𝑋→𝑛=𝑚∗ 𝑋
𝑛+𝑚=𝑚∗𝑋+𝑚=𝑚 ( 𝑋+1 )=22cm
𝑚=22cm(𝑋+1 )
• One solution– Follow the edge of the putting green until we
reach the position of the ball• Approach
– Let’s modify LineFollowZZStop.ev3 to stop at the location of the ball
• Tools needed– Line following– Measure distance traveled
Find The Golf Ball
26
• Determine how far the robot travels moving forward for 2 seconds
Measure Distances
27
Distance
Compute distance traveled by measuring the number of rotations of the wheel
• Use the wheel geometry
Measure Distances
28
PI = 3.14
Circ
umfe
renc
e =
Dia
× PI
Radius
Diamet
er =
2 ×
Rad
iusHow can use this information?
• For each rotation of the wheel, the robot will travel (Wheel Diameter) x (PI)
• Distance = (Wheel Diameter) x (PI) x (# Rotations)• Distance = (5.5 cm) x (PI) x (# Rotations)• Distance = (17.28 cm) x (# Rotations)
Measure Distances
29Program: MeasureDistance.ev3 YouTube: https://youtu.be/g-8ocEIlxPQ
• Proposed method:– Compute the distance to travel along the edge of
the putting green– Compute the number of rotations required to
travel that distance– Find the edge of the putting green– Reset motor rotation sensor– Follow the edge of the putting green– Stop the robot when the desired number of
rotations is reached
Aligning The Robot With The Golf Ball
30
• Example– Putting green dimensions
• m = 11 cm, n = 11 cm– Number of rotations
• Distance = (Wheel Diameter) x (PI) x (# Rotations)• Solve for (# Rotations)
Aligning The Robot With The Golf Ball
31
(# Rotations) = (Wheel Diameter) x (PI)
Distance
(# Rotations) = (5.5 cm) x (PI)
11 cm= 0.64 rotations
• Line follow a desired distance
Aligning The Robot With The Golf Ball
32Program: LineFollowDistance.ev3 YouTube: https://youtu.be/BfzXMNbnC_k
33
Task 4
Aim for the hole
• We will review a few methods to aim for the hole
• Method 1: Search for the flag pole– Scan using the sonar senor
• Method 2: Compute the location of the hole– Mathematically determine the location of the hole
• Step 1– Determine the angle we must rotate to aim the robot towards the golf hole
• Step 2– Rotate the robot the determined amount
• Method 3: Determine the location using trial and error– Here we find the hole by rotating the robot different amounts in an attempt to
find the correct orientation
Aim for the hole
34
• Here we are going to have the robot spin until it “sees” the center hole flag with the sonar sensor
Method 1: Scan For Hole
35Program: SpinSearch.ev3 YouTube: https://youtu.be/GQg6tLZamsE
• Using this approach we can calculate how far to rotate the robot to face the center hole
• We complete this in two steps– Step 1
• Determine the angle we must rotate to aim the robot towards the golf hole
– Step 2• Rotate the robot the determined amount
Method 2: Mathematical Approach
36
• We can use geometry to determine the location of the hole
Determine The Rotation Angle
37
r
st
Robot
• We can use trigonometry to determine the location of the hole and aim the robot
Determine The Rotation Angle
38
tan𝜃=𝑟𝑠
si𝑛𝜃=𝑟𝑡
𝑐𝑜𝑠𝜃=𝑠𝑡
𝜃=a tan( 𝑟𝑠 )
r
stθ
Robot
• Use an advanced math block to compute the necessary rotation angle– Assume the following
• r = 40 cm• s = 30 cm
Determine The Rotation Angle
39Program: TrigMath.ev3 YouTube: https://youtu.be/DVFz0_Sf8tg
40
30 5053.13°
36.87°
• We need to rotate the robot θ degrees to aim the robot at the golf hole
Rotate The Robot To Putt
40
RobotRobot
Starting Position Rotated Position
θ
• We will use the spin feature to turn the robot θ degrees
• When the robot spins, the wheel path is a circle centered between the wheels
• The diameter is the track width of the robot
Rotate The Robot To Putt
41
Robo
t
Robo
t
Robot
• For an example, let’s spin the robot 90 deg– Robot track width = 16.2 cm– The circumference of the robot’s path
• C = PI * D = 3.14 x 16.2 cm = 50.87 cm– The circumference of the robot’s wheel
• C = PI * D = 3.14 x 5.5 cm = 17.27 cm
• 90 degrees is ¼ of the circle. The robot travels– D = ¼ x 50.87 cm = 12.72 cm
• How rotations to travel 12.72 cm?– # Rot = Distance / (Wheel Circumference)– # Rot = 12.72 cm / 17.27 cm = 0.74
Rotate The Robot To Putt
42
• Spinning robot example– Robot width = 16.2 cm– Wheel Diameter = 5.5 cm
• Circumference = 17.27cm
• Number of rotations
Rotate The Robot To Putt
43
(¿𝑅𝑒𝑣𝑜𝑙𝑢𝑡𝑖𝑜𝑛𝑠 )=12.72𝑐𝑚17.27𝑐𝑚=0.74 𝑟𝑜𝑡𝑎𝑡𝑖𝑜𝑛𝑠
(¿𝑅𝑒𝑣𝑜𝑙𝑢𝑡𝑖𝑜𝑛𝑠 )= 𝐷𝑖𝑠𝑡𝑎𝑛𝑐𝑒𝑇𝑟𝑎𝑣𝑒𝑙𝑒𝑑h𝑊 𝑒𝑒𝑙𝐶𝑖𝑟𝑐𝑢𝑚𝑓𝑒𝑟𝑒𝑛𝑐𝑒
• We can use one block to spin the robot
Rotate The Robot To Putt
44Program: Spin90.ev3 YouTube: https://youtu.be/mIBylTRqA9Y
45
Task 5
Putt the golf ball
• Again, this task is beyond the scope of this course
• However, your robot should be in position to putt the ball in the center hole
• Remember, you can only hit the golf ball once and only with the wooden block putter
Putt The Golf Ball
46
• Solving the Robofest Game challenge will typically require a fairly large EV3 program (around 100 blocks is not unreasonable)
• Very large programs can be difficult to understand, navigate and use
• To alleviate this issue, the EV3 software has a My Block Builder to create custom blocks that can replace sections of your program
My Blocks
• For example, let’s assume you have a section code that completes the following:– Move forward until the edge of the table is found with
color sensor 1, then stop– After stopping, rotate the robot 90 degrees
• The code may look like this
• My blocks will allow us to convert this to a single block
My Blocks
• Creating a My Block1. Select the section to convert2. Go to Tools -> My Block Builder3. Enter the block name, description and select icon4. Hit Finish
My Blocks
This creates a My Block called FindEdge that will be located in the My Blocks Pallet
3
4
• In this course we learned how to– Find the edge of the table– Follow the edge of the table– Find a putting green– Find the golf ball– Aim for the hole– Putt the golf ball
Putting It All Together
50