ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments...

62
ROBOTC Software EV3 Robot Workshop Lawrence Technological University Computer Science Instructor: Assistants:

Transcript of ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments...

Page 1: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

ROBOTC SoftwareEV3 RobotWorkshop

Lawrence Technological UniversityComputer Science

InstructorAssistants

bull 2017 Robofest competition RoboHit

bull SPbot introduction

bull Using the SPbot to solve the RoboHitchallenge

Course Overview

2

bull Video overview

bull Key tasksndash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball stand

ndash Mathematics to locate the ball standndash Find objectsndash Bat the ballndash Return home

2017 Robofest Competition

3

bull Please note that the actual batting of the ball is beyond the scope of this workshop

2017 Robofest Competition

4

LEGO EV3 robot used ndash SPbot

Color Sensor 1

EV3 Computer

Left Motor B

Right Motor C

Touch Sensor

Sonar Sensor

Color Sensor 2

bull Left Motor connects to Bbull Right Motor connects to C

ndash If your motors are upside down forward will be backwards in your program

bull Color sensor 1 connects to port no 1bull Color sensor 2 connects to port no 2bull Touch sensor connects to port no 3bull Ultrasonic sensor connects to port no 4

Remember the connections

6

Brick Overview

bull ROBOTC Version 455 bull Build Date Aug 25 2016

bull PowerPoint and all example programs are available at robofestnet under Tech Resources

ROBOTC Versions Used

8

bull Opening the source codes files for the workshop will assist in setting up the ROBOTC environment

bull Once the source files are loaded the EV3 motors and sensors should be assigned

Setting Up The ROBOTC Environment

bull The first time you use an EV3 robot with ROBOTC you need to download the ROBOTC kernelndash Robot -gt Download EV3 Linux Kernel -gt Standard

Kernel

Setting Up The ROBOTC Environment

Setting Up The ROBOTC EnvironmentUnder Robot Menu

Compiler Targetbull Physical Robot

Platform Typebull LEGO Mindstroms EV3bull Uncheck Natural Language

Motors and Sensor Setupbull Reviewed on the next slide

Firmware Download

11

bull Select Custom Configuration

Motors and Sensors Setup

12

bull Set left and right motors

Motors and Sensors Setup

13

bull Set up sensors

Motors and Sensors Setup

14

bull Once the motors and sensors at set up ROBOTC will generate code to configure them

bull We will use this code in all programs we write in this course

Code generation

15

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 2: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull 2017 Robofest competition RoboHit

bull SPbot introduction

bull Using the SPbot to solve the RoboHitchallenge

Course Overview

2

bull Video overview

bull Key tasksndash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball stand

ndash Mathematics to locate the ball standndash Find objectsndash Bat the ballndash Return home

2017 Robofest Competition

3

bull Please note that the actual batting of the ball is beyond the scope of this workshop

2017 Robofest Competition

4

LEGO EV3 robot used ndash SPbot

Color Sensor 1

EV3 Computer

Left Motor B

Right Motor C

Touch Sensor

Sonar Sensor

Color Sensor 2

bull Left Motor connects to Bbull Right Motor connects to C

ndash If your motors are upside down forward will be backwards in your program

bull Color sensor 1 connects to port no 1bull Color sensor 2 connects to port no 2bull Touch sensor connects to port no 3bull Ultrasonic sensor connects to port no 4

Remember the connections

6

Brick Overview

bull ROBOTC Version 455 bull Build Date Aug 25 2016

bull PowerPoint and all example programs are available at robofestnet under Tech Resources

ROBOTC Versions Used

8

bull Opening the source codes files for the workshop will assist in setting up the ROBOTC environment

bull Once the source files are loaded the EV3 motors and sensors should be assigned

Setting Up The ROBOTC Environment

bull The first time you use an EV3 robot with ROBOTC you need to download the ROBOTC kernelndash Robot -gt Download EV3 Linux Kernel -gt Standard

Kernel

Setting Up The ROBOTC Environment

Setting Up The ROBOTC EnvironmentUnder Robot Menu

Compiler Targetbull Physical Robot

Platform Typebull LEGO Mindstroms EV3bull Uncheck Natural Language

Motors and Sensor Setupbull Reviewed on the next slide

Firmware Download

11

bull Select Custom Configuration

Motors and Sensors Setup

12

bull Set left and right motors

Motors and Sensors Setup

13

bull Set up sensors

Motors and Sensors Setup

14

bull Once the motors and sensors at set up ROBOTC will generate code to configure them

bull We will use this code in all programs we write in this course

Code generation

15

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 3: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Video overview

bull Key tasksndash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball stand

ndash Mathematics to locate the ball standndash Find objectsndash Bat the ballndash Return home

2017 Robofest Competition

3

bull Please note that the actual batting of the ball is beyond the scope of this workshop

2017 Robofest Competition

4

LEGO EV3 robot used ndash SPbot

Color Sensor 1

EV3 Computer

Left Motor B

Right Motor C

Touch Sensor

Sonar Sensor

Color Sensor 2

bull Left Motor connects to Bbull Right Motor connects to C

ndash If your motors are upside down forward will be backwards in your program

bull Color sensor 1 connects to port no 1bull Color sensor 2 connects to port no 2bull Touch sensor connects to port no 3bull Ultrasonic sensor connects to port no 4

Remember the connections

6

Brick Overview

bull ROBOTC Version 455 bull Build Date Aug 25 2016

bull PowerPoint and all example programs are available at robofestnet under Tech Resources

ROBOTC Versions Used

8

bull Opening the source codes files for the workshop will assist in setting up the ROBOTC environment

bull Once the source files are loaded the EV3 motors and sensors should be assigned

Setting Up The ROBOTC Environment

bull The first time you use an EV3 robot with ROBOTC you need to download the ROBOTC kernelndash Robot -gt Download EV3 Linux Kernel -gt Standard

Kernel

Setting Up The ROBOTC Environment

Setting Up The ROBOTC EnvironmentUnder Robot Menu

Compiler Targetbull Physical Robot

Platform Typebull LEGO Mindstroms EV3bull Uncheck Natural Language

Motors and Sensor Setupbull Reviewed on the next slide

Firmware Download

11

bull Select Custom Configuration

Motors and Sensors Setup

12

bull Set left and right motors

Motors and Sensors Setup

13

bull Set up sensors

Motors and Sensors Setup

14

bull Once the motors and sensors at set up ROBOTC will generate code to configure them

bull We will use this code in all programs we write in this course

Code generation

15

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 4: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Please note that the actual batting of the ball is beyond the scope of this workshop

2017 Robofest Competition

4

LEGO EV3 robot used ndash SPbot

Color Sensor 1

EV3 Computer

Left Motor B

Right Motor C

Touch Sensor

Sonar Sensor

Color Sensor 2

bull Left Motor connects to Bbull Right Motor connects to C

ndash If your motors are upside down forward will be backwards in your program

bull Color sensor 1 connects to port no 1bull Color sensor 2 connects to port no 2bull Touch sensor connects to port no 3bull Ultrasonic sensor connects to port no 4

Remember the connections

6

Brick Overview

bull ROBOTC Version 455 bull Build Date Aug 25 2016

bull PowerPoint and all example programs are available at robofestnet under Tech Resources

ROBOTC Versions Used

8

bull Opening the source codes files for the workshop will assist in setting up the ROBOTC environment

bull Once the source files are loaded the EV3 motors and sensors should be assigned

Setting Up The ROBOTC Environment

bull The first time you use an EV3 robot with ROBOTC you need to download the ROBOTC kernelndash Robot -gt Download EV3 Linux Kernel -gt Standard

Kernel

Setting Up The ROBOTC Environment

Setting Up The ROBOTC EnvironmentUnder Robot Menu

Compiler Targetbull Physical Robot

Platform Typebull LEGO Mindstroms EV3bull Uncheck Natural Language

Motors and Sensor Setupbull Reviewed on the next slide

Firmware Download

11

bull Select Custom Configuration

Motors and Sensors Setup

12

bull Set left and right motors

Motors and Sensors Setup

13

bull Set up sensors

Motors and Sensors Setup

14

bull Once the motors and sensors at set up ROBOTC will generate code to configure them

bull We will use this code in all programs we write in this course

Code generation

15

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 5: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

LEGO EV3 robot used ndash SPbot

Color Sensor 1

EV3 Computer

Left Motor B

Right Motor C

Touch Sensor

Sonar Sensor

Color Sensor 2

bull Left Motor connects to Bbull Right Motor connects to C

ndash If your motors are upside down forward will be backwards in your program

bull Color sensor 1 connects to port no 1bull Color sensor 2 connects to port no 2bull Touch sensor connects to port no 3bull Ultrasonic sensor connects to port no 4

Remember the connections

6

Brick Overview

bull ROBOTC Version 455 bull Build Date Aug 25 2016

bull PowerPoint and all example programs are available at robofestnet under Tech Resources

ROBOTC Versions Used

8

bull Opening the source codes files for the workshop will assist in setting up the ROBOTC environment

bull Once the source files are loaded the EV3 motors and sensors should be assigned

Setting Up The ROBOTC Environment

bull The first time you use an EV3 robot with ROBOTC you need to download the ROBOTC kernelndash Robot -gt Download EV3 Linux Kernel -gt Standard

Kernel

Setting Up The ROBOTC Environment

Setting Up The ROBOTC EnvironmentUnder Robot Menu

Compiler Targetbull Physical Robot

Platform Typebull LEGO Mindstroms EV3bull Uncheck Natural Language

Motors and Sensor Setupbull Reviewed on the next slide

Firmware Download

11

bull Select Custom Configuration

Motors and Sensors Setup

12

bull Set left and right motors

Motors and Sensors Setup

13

bull Set up sensors

Motors and Sensors Setup

14

bull Once the motors and sensors at set up ROBOTC will generate code to configure them

bull We will use this code in all programs we write in this course

Code generation

15

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 6: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Left Motor connects to Bbull Right Motor connects to C

ndash If your motors are upside down forward will be backwards in your program

bull Color sensor 1 connects to port no 1bull Color sensor 2 connects to port no 2bull Touch sensor connects to port no 3bull Ultrasonic sensor connects to port no 4

Remember the connections

6

Brick Overview

bull ROBOTC Version 455 bull Build Date Aug 25 2016

bull PowerPoint and all example programs are available at robofestnet under Tech Resources

ROBOTC Versions Used

8

bull Opening the source codes files for the workshop will assist in setting up the ROBOTC environment

bull Once the source files are loaded the EV3 motors and sensors should be assigned

Setting Up The ROBOTC Environment

bull The first time you use an EV3 robot with ROBOTC you need to download the ROBOTC kernelndash Robot -gt Download EV3 Linux Kernel -gt Standard

Kernel

Setting Up The ROBOTC Environment

Setting Up The ROBOTC EnvironmentUnder Robot Menu

Compiler Targetbull Physical Robot

Platform Typebull LEGO Mindstroms EV3bull Uncheck Natural Language

Motors and Sensor Setupbull Reviewed on the next slide

Firmware Download

11

bull Select Custom Configuration

Motors and Sensors Setup

12

bull Set left and right motors

Motors and Sensors Setup

13

bull Set up sensors

Motors and Sensors Setup

14

bull Once the motors and sensors at set up ROBOTC will generate code to configure them

bull We will use this code in all programs we write in this course

Code generation

15

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 7: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

Brick Overview

bull ROBOTC Version 455 bull Build Date Aug 25 2016

bull PowerPoint and all example programs are available at robofestnet under Tech Resources

ROBOTC Versions Used

8

bull Opening the source codes files for the workshop will assist in setting up the ROBOTC environment

bull Once the source files are loaded the EV3 motors and sensors should be assigned

Setting Up The ROBOTC Environment

bull The first time you use an EV3 robot with ROBOTC you need to download the ROBOTC kernelndash Robot -gt Download EV3 Linux Kernel -gt Standard

Kernel

Setting Up The ROBOTC Environment

Setting Up The ROBOTC EnvironmentUnder Robot Menu

Compiler Targetbull Physical Robot

Platform Typebull LEGO Mindstroms EV3bull Uncheck Natural Language

Motors and Sensor Setupbull Reviewed on the next slide

Firmware Download

11

bull Select Custom Configuration

Motors and Sensors Setup

12

bull Set left and right motors

Motors and Sensors Setup

13

bull Set up sensors

Motors and Sensors Setup

14

bull Once the motors and sensors at set up ROBOTC will generate code to configure them

bull We will use this code in all programs we write in this course

Code generation

15

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 8: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull ROBOTC Version 455 bull Build Date Aug 25 2016

bull PowerPoint and all example programs are available at robofestnet under Tech Resources

ROBOTC Versions Used

8

bull Opening the source codes files for the workshop will assist in setting up the ROBOTC environment

bull Once the source files are loaded the EV3 motors and sensors should be assigned

Setting Up The ROBOTC Environment

bull The first time you use an EV3 robot with ROBOTC you need to download the ROBOTC kernelndash Robot -gt Download EV3 Linux Kernel -gt Standard

Kernel

Setting Up The ROBOTC Environment

Setting Up The ROBOTC EnvironmentUnder Robot Menu

Compiler Targetbull Physical Robot

Platform Typebull LEGO Mindstroms EV3bull Uncheck Natural Language

Motors and Sensor Setupbull Reviewed on the next slide

Firmware Download

11

bull Select Custom Configuration

Motors and Sensors Setup

12

bull Set left and right motors

Motors and Sensors Setup

13

bull Set up sensors

Motors and Sensors Setup

14

bull Once the motors and sensors at set up ROBOTC will generate code to configure them

bull We will use this code in all programs we write in this course

Code generation

15

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 9: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Opening the source codes files for the workshop will assist in setting up the ROBOTC environment

bull Once the source files are loaded the EV3 motors and sensors should be assigned

Setting Up The ROBOTC Environment

bull The first time you use an EV3 robot with ROBOTC you need to download the ROBOTC kernelndash Robot -gt Download EV3 Linux Kernel -gt Standard

Kernel

Setting Up The ROBOTC Environment

Setting Up The ROBOTC EnvironmentUnder Robot Menu

Compiler Targetbull Physical Robot

Platform Typebull LEGO Mindstroms EV3bull Uncheck Natural Language

Motors and Sensor Setupbull Reviewed on the next slide

Firmware Download

11

bull Select Custom Configuration

Motors and Sensors Setup

12

bull Set left and right motors

Motors and Sensors Setup

13

bull Set up sensors

Motors and Sensors Setup

14

bull Once the motors and sensors at set up ROBOTC will generate code to configure them

bull We will use this code in all programs we write in this course

Code generation

15

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 10: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull The first time you use an EV3 robot with ROBOTC you need to download the ROBOTC kernelndash Robot -gt Download EV3 Linux Kernel -gt Standard

Kernel

Setting Up The ROBOTC Environment

Setting Up The ROBOTC EnvironmentUnder Robot Menu

Compiler Targetbull Physical Robot

Platform Typebull LEGO Mindstroms EV3bull Uncheck Natural Language

Motors and Sensor Setupbull Reviewed on the next slide

Firmware Download

11

bull Select Custom Configuration

Motors and Sensors Setup

12

bull Set left and right motors

Motors and Sensors Setup

13

bull Set up sensors

Motors and Sensors Setup

14

bull Once the motors and sensors at set up ROBOTC will generate code to configure them

bull We will use this code in all programs we write in this course

Code generation

15

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 11: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

Setting Up The ROBOTC EnvironmentUnder Robot Menu

Compiler Targetbull Physical Robot

Platform Typebull LEGO Mindstroms EV3bull Uncheck Natural Language

Motors and Sensor Setupbull Reviewed on the next slide

Firmware Download

11

bull Select Custom Configuration

Motors and Sensors Setup

12

bull Set left and right motors

Motors and Sensors Setup

13

bull Set up sensors

Motors and Sensors Setup

14

bull Once the motors and sensors at set up ROBOTC will generate code to configure them

bull We will use this code in all programs we write in this course

Code generation

15

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 12: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Select Custom Configuration

Motors and Sensors Setup

12

bull Set left and right motors

Motors and Sensors Setup

13

bull Set up sensors

Motors and Sensors Setup

14

bull Once the motors and sensors at set up ROBOTC will generate code to configure them

bull We will use this code in all programs we write in this course

Code generation

15

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 13: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Set left and right motors

Motors and Sensors Setup

13

bull Set up sensors

Motors and Sensors Setup

14

bull Once the motors and sensors at set up ROBOTC will generate code to configure them

bull We will use this code in all programs we write in this course

Code generation

15

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 14: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Set up sensors

Motors and Sensors Setup

14

bull Once the motors and sensors at set up ROBOTC will generate code to configure them

bull We will use this code in all programs we write in this course

Code generation

15

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 15: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Once the motors and sensors at set up ROBOTC will generate code to configure them

bull We will use this code in all programs we write in this course

Code generation

15

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 16: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

Task 0

Find the playing field

16

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 17: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull The robot is required to start a distance (D2)from the playing field

Task 0 Find The Playing Field

(West starting position)

North

17

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 18: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

Task 0 Example Solution

Program findFieldc YouTube httpsyoutubeu4ApKEUcRuI

Turn on motors forward

Wait until the edge of the field is detected

Stop the robot

18

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 19: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull One method of monitor the sensor values is to use the ROBOTC debugger windowndash Download program to your robot

bull This opens the Debugger and Debugger windows

Reading sensors values

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 20: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull ROBOTC offers many debugging options

Debugger Windows

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 21: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull We can write a program to display the sensor values on the EV3 LCD screen as well

Reading sensors values

Program sensorValuesc21

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 22: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

Task 1

Follow the playing field edge

22

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 23: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Use the zig-zag method to follow the edge of the playing field

bull Edge following is also referred to as line following

bull We need to determine when the robot is on or off the playing field

Follow The Playing Field Edge

23

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 24: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Get color sensor values to determine when the robot is on or off the playing field We will use the color sensor in Reflective Light Intensity mode

bull Color Sensor 1 Color Sensor 2ndash On field = ______ (70) On field = ______ (70)ndash Off field = ______ (10) Off field = ______ (10)

Follow The Edge Of The Field or Mat

ColorSensor

Readings

24

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 25: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Light sensor settings examplendash Off field = 10ndash On field = 70ndash Median threshold = (10+70)2 = 40

bull Two casesndash Light sensor reading gt 40 On the playing fieldndash Light sensor reading lt 40 Off the playing field

Follow The Edge Of The Field or Mat

25

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 26: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

Simple Line Following Algorithm

Program LineFollowZZc YouTube httpsyoutubewpSw-wC0oKA

Set the threshold value

Loop forever ndash the robot will not stop

Based on color senor reading determine which direction to travel to line follow

26

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 27: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Zig-zag method can cause a bumpy responsebull To improve the response you can use a 3-level

line follower (concept shown below)

How to improve our line following algorithm

Off Table Off TableOn Table On Table

27

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 28: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

Task 2

Run the bases

28

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 29: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull One method to move from one base to another is the use two color sensorsndash Sensor 1 used to follow the edge of the playing fieldndash Sensor 2 used to locate the end of the playing field

Run The Bases

Color sensor 1

Color sensor 2

29

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 30: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Couple comments regarding moving around the field

ndash It is possible to achieve this using only one color sensor but it more difficult and potentially less reliable

ndash Remember that only two of the bases have foil tape please keep this under consideration

bull When your robot finds the foil tape which base are you atbull Need to ldquocountrdquo bases without a foil tape indicator

Run The Bases

30

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 31: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Letrsquos modify the program to stop when the robot reaches the end of the base line

Run The Bases

Currently the program will line follow until we stop the robot

Letrsquos change the outer loop to stop when the green is reached

31

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 32: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

Run The Bases

Program lineFollowZZStopc YouTube httpsyoutube_HL-SXSpV9I

Here we modify the while loop conditional statement to use the second color sensor to detect when the edge of the field is reached

Once edge is reached we exit while loop and stop the robot

32

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 33: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

Task 3

Find the ball stand

33

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 34: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull General ideandash Now that we can travel from one base to another

we can align our robot with the ball stand by traveling half way to a base

bull The rules specify that the bottle will be located in the middle of the playing field

ndash The dimensions of the playing field are L and Wndash The distance traveled should be H2 or W2ndash Once the appropriate distance is traveled turn 90

degrees and travel towards the ball stand

Find The Ball Stand

34

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 35: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Approachndash Modify LineFollowZZStopev3 to stop at the

location of the ball standndash Spin 90 degreesndash Travel to the ball stand

bull Tools neededndash Line following ndash Measure distance traveledndash Precise turning

Find The Ball Stand

35

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 36: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Determine how far the robot travels moving forward for 2 seconds

Measure Distances

Distance

Compute distance traveled by measuring the number of rotations of the wheel

36

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 37: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Use the wheel geometry

Measure Distances

PI = 314

Radius

How can use this information

37

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 38: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

Measure Distances

Program measureDistancec YouTube httpsyoutube6IoyBSrdTmY

Here we reset the a motor encoder

The encoder outputs the rotation of the motor in degrees so we convert the output to rotations

Code added to wait until the touch sensor is pressed to keep the information visible on the robot screen

38

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 39: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Proposed methodndash Compute the distance to travel along the edge of

the playing field (H2 or W2)ndash Compute the number of rotations required to

travel that distancendash Follow the edge of the playing fieldndash Stop the robot when the desired number of

rotations is reachedndash Spin 90 degreesndash Travel to the bottle

Find The Ball Stand

39

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 40: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Examplendash Assume H = 80 cm

bull H2 = 40 cm

ndash Number of rotationsbull Distance = (Wheel Diameter) x (PI) x ( Rotations)bull Solve for ( Rotations)

Find The Ball StandCompute Distance To Travel

( Rotations) = (Wheel Diameter) x (PI)

Distance

( Rotations) = (55 cm) x (PI)

40 cm= 232 rotations

40

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 41: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

Here we define some variables

Loop until the desired distance is traveled

Compute the distance traveled

Program lineFollowDistancecYouTube httpsyoutubeJ4wm8yNQISo

Find The Ball StandLine Follow The Proper Distance

41

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 42: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Letrsquos have the robot spin 90 degrees CCW

Find The Ball StandSpin 90 Degrees

Robot

Starting Position

Robo

t

Final Position

(East)

42

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 43: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull We will use the spin feature to turn the robot bull When the robot spins the wheel path is a

circle centered between the wheelsbull The diameter is the track width of the robot

Find The Ball StandSpin 90 Degrees

Robo

t

43

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 44: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull To spin the robot 90 degndash Robot track width = 162 cmndash The circumference of the robotrsquos circular path

bull C = PI D = 314 x 162 cm = 5087 cmndash The circumference of the robotrsquos wheel

bull C = PI D = 314 x 55 cm = 1727 cm

bull 90 degrees is frac14 of the circle The robot travelsndash Distance = frac14 x 5087 cm = 1272 cm

bull How rotations to travel 1272 cmndash Rot = Distance (Wheel Circumference)ndash Rot = 1272 cm 1727 cm = 074 rotations

Find The Ball StandSpin 90 Degrees

44

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 45: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Spinning robot examplendash Robot width = 162 cmndash Wheel Diameter = 55 cm

bull Circumference = 1727cm

bull Number of rotations

Find The Ball StandSpin 90 Degrees

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =1272 1198881198881198881198881727 119888119888119888119888

= 074 119903119903119877119877119877119877119903119903119877119877119877119877119877119877119877119877119877119877

119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877119877 =119863119863119877119877119877119877119877119877119903119903119877119877119888119888119877119877 119879119879119903119903119903119903119877119877119877119877119877119877119877119877119879119879

119882119882119882119877119877119877119877119877119877 119862119862119877119877119903119903119888119888119877119877119888119888119862119862119877119877119903119903119877119877119877119877119888119888119877119877

45

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 46: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Spin the robot

Find The Ball StandSpin 90 Degrees

Program spin90c YouTube httpsyoutubejDmOSHctRO4

Loop until the desired distance is traveled

46

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 47: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Assuming that we need to travel 40 cm to get to the center of the field we modify lineFollowDistancec to travel the same distance in the a straight line

Find The Ball StandTravel To The Ball Stand

Program travelDistancec

Found on Slide 40

47

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 48: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

Task 4

Find objects

48

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 49: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Recall that the trash objects of unknown typendash Examples color cup soft drink can etc

bull The object position is also random but a given distance from the ball stand

ndash Distance from ball stand is D3

bull Here we use the ultrasonic sensor to find objects on the playing fieldbull But the ultrasonic sensor will not be able to differentiate trash objects

from the ball stand

Find objects

Ultrasonic sensor field of vision

Robot

Ball stand

Trash object

Trash object

49

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 50: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull If we travel around the playing field we know that the trash objects will be closer to the robot than the ball stand from at least one side of the field

Find objects

Ballstand

TrashObject 1

TrashObject 2 Ro

bot

Robot

Robot50

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 51: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Travel from one base to another and stop if we find a trash object

Find objects

Program objectSearchc YouTube httpsyoutuben1ePWZU0Z08

This loop with allow the robot line follow until an object is detected by the ultrasonic sensor

51

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 52: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

Task 5

Bat the ball

52

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 53: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull This task is beyond the scope of this coursebull However

ndash You should be able to position your robot in a proper hitting position using the techniques outlined in this course

ndash To increase your bat speed to hit the farther you may use gears with the EV3 motors

ndash Consider using a large EV3 motor rather then a medium EV3 motor for increased bat speed

Bat the ball

53

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 54: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Gearing to increasing bat speed

Bat the ball

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 119863119863119903119903119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119877119877119877119877119877119877119882

119863119863119903119903119877119877119877119877119877119877119877119877 119866119866119877119877119903119903119903119903 119879119879119882119877119877119877119877119877119877 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

119874119874119877119877119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 =36 11987711987711987711987711987711987711987711987711988212 119877119877119877119877119877119877119877119877119882 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879 = 3 times 119868119868119877119877119874119874119877119877119877119877 119878119878119874119874119877119877119877119877119879119879

Drive Gear(connected to motor)

Driven Gear(connected to drive gear)

Driven gear spins 3 times faster than the drive gear

54

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 55: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

Task 6

Return home

55

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 56: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull To successfully complete the RoboHit mission the robot must return to home and stop

bull One way of accomplishing this is to modify the line following program to follow the baseline until home plate (reflective foil tape) is foundndash Please recall that there are two bases with foilndash The white vinyl playing surface can be very

reflective Make sure to position our robotrsquos color sensor high enough from the playing surface (~15 mm) to ensure that your robot and differentiate between the playing field and home base

Return Home

56

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 57: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

Return Home

Program lineFollowZZHomec YouTube httpsyoutubeoF184R9pkk4

Here we modify the while loop conditional statement to use the color sensor to detect home base

We increase the turn amount to make the robot zig-zag more

Once home is reached we exit while loop and stop the robot

57

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 58: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Solving the Robofest Game challenge will typically require a fairly large EV3 program

bull Very large programs can be difficult to understand navigate and use

bull To alleviate this issue ROBOTC allows the use of functions group and reuse sections of your program

Functions

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 59: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull For example letrsquos assume you have a section code that completes the followingndash Move forward until the

edge of the table is found with color sensor 1 then stop

ndash After stopping rotate the robot 90 degrees

bull Here is an examplehellip

Functions

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 60: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull Letrsquos create a function called findEdgeAndTurn

Functions

Now can call the function from our main task program

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 61: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

bull In this course we learned how tondash Find the playing fieldndash Follow the playing field edgendash Run the basesndash Find the ball standndash Find objectsndash Bat the ballndash Return homendash Functions

Putting It All Together

61

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions
Page 62: ROBOTC Software EV3 Robot Workshop - Robofest - Home · PDF file• Couple comments regarding moving around the field – It is possible to achieve this using only one color sensor,

robofestLTUeduLTU Computer Science

Little Robots Big Missions

Questions

62

  • Slide Number 1
  • Course Overview
  • 2017 Robofest Competition
  • 2017 Robofest Competition
  • LEGO EV3 robot used ndash SPbot
  • Remember the connections
  • Brick Overview
  • ROBOTC Versions Used
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Setting Up The ROBOTC Environment
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Motors and Sensors Setup
  • Code generation
  • Slide Number 16
  • Task 0 Find The Playing Field
  • Task 0 Example Solution
  • Reading sensors values
  • Debugger Windows
  • Reading sensors values
  • Slide Number 22
  • Follow The Playing Field Edge
  • Follow The Edge Of The Field or Mat
  • Follow The Edge Of The Field or Mat
  • Simple Line Following Algorithm
  • How to improve our line following algorithm
  • Slide Number 28
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Run The Bases
  • Slide Number 33
  • Find The Ball Stand
  • Find The Ball Stand
  • Measure Distances
  • Measure Distances
  • Measure Distances
  • Find The Ball Stand
  • Find The Ball StandCompute Distance To Travel
  • Find The Ball StandLine Follow The Proper Distance
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandSpin 90 Degrees
  • Find The Ball StandTravel To The Ball Stand
  • Slide Number 48
  • Find objects
  • Find objects
  • Find objects
  • Slide Number 52
  • Bat the ball
  • Bat the ball
  • Slide Number 55
  • Return Home
  • Return Home
  • Functions
  • Functions
  • Functions
  • Putting It All Together
  • Little Robots Big Missions