PPTX - Robofest

Download Report

Transcript PPTX - Robofest

Graphical RobotC
NXT (EV3) Robot
Workshop 2015
Instructor: Dr. Fred Brauchler
Assistant: Chris Parker
2/7/2015
Lawrence Technological University
1
Workshop Overview
• 2015 RoboFest competition RoboBowl
• RoBot and Software introduction
• Using RoBot to solve the RoboBowl challenge
2/7/2015
Lawrence Technological University
2
2015 RoboFest Competition
2/7/2015
Lawrence Technological University
3
2015 RoboFest Competition
• RoboBowl animation
– https://www.youtube.com/watch?v=LJ0afkDSuZA&feature=youtu.be
• Key Tasks
–
–
–
–
–
–
Search for black rectangle or edge
Measuring height of a rectangle
Follow the edge of the table or a line
Compute and move to location of pins 3 & 4
Bowl a tennis ball*
Return to home base
*Please note that bowling the tennis balls is outside the scope of this workshop
2/7/2015
Lawrence Technological University
4
Lego NXT robot – RoBot
Right motor: B
NXT Brick
(Computer)
Left motor: C
Right Light
Sensor:port 3
Left Light
Sensor:port 2
2/7/2015
The parts shown here
may be different from
yours. You may need
to adapt a design for
your parts.
Lawrence Technological University
5
Remember the connections!
• Left Motor connects to C
• Right Motor connects to B
– If your motors are upside down, you can change the direction in the
program or select “reverse” in motor and sensors setup
• Left Light sensor connects to port no. 2
• Right Light sensor connects to port no. 3
• Unused ports: A, 1, and 4
2/7/2015
Lawrence Technological University
6
Software and Links
• How to get RobotC?
Version 4.27 download Link: www.robotc.net/robofest/
• Or search RobotC 4.28. Currently in Beta.
• PowerPoint and all example programs are available at
robofest.net select menu
– RoboBowlWorkshopGRobotC.pptx
– RoboBowlWorkshopGRobotC.zip
In order to use the custom graphical blocks, you must replace some include
files in your RobotC directory. Please see ReadmeFirst.txt in zip file.
2/7/2015
Lawrence Technological University
7
Getting Started
• Launch Graphical RobotC
• Power up and Connect NXT to Computer
•
•
•
•
Firmware Download is only needed once per NXT
brick
Menu: Robot -> Download Firmware -> Standard File
Or click on F/W Download button
Click on the
button
Click on
button after receiving “completed”
message
2/7/2015
Lawrence Technological University
8
General steps to create a new
program & run
1.
2.
3.
4.
5.
6.
7.
File -> New -> New file or
Robot -> Motors and Sensors Setup or
Write the code by dragging command blocks
Save your program Ctrl+[s] or
Compile by pressing function key F7 or
Download through USB cable key F5 or
Run on NXT robot via buttons or
2/7/2015
Lawrence Technological University
9
How to setup RobotC motors
• Launch RobotC
• New File
• Motors and
Sensors Setup
2/7/2015
Lawrence Technological University
10
Sensor set up
Change S2 for the second light sensor
Name: Light2
Sensor Type: Light-Reflected (NXT)
2/7/2015
Lawrence Technological University
11
2015 RoboFest Competition
• Recall Key Tasks for Workshop
–
–
–
–
–
–
Search for black edge
Measuring height of a rectangle
Follow a line or table edge
Compute and move to location of pins 3 & 4
Bowl a tennis ball*
Return to home base
*Please note that bowling the tennis balls is outside the scope of this workshop
2/7/2015
Lawrence Technological University
12
Task 1
Search for Black Edge
2/7/2015
Lawrence Technological University
13
SearchForBlack.rbg
• Program sequence
– Move forward
– Wait until sensor reads value < threshold (50)
– Stop
2/7/2015
Lawrence Technological University
14
How to See Sensor Values
• Run any program, for Example:
• Menu: Robot->Debugger Window->NXT Devices
• Light Sensor
Values
2/7/2015
Lawrence Technological University
15
Choose a Light Sensor Threshold
• Light sensor settings example
– On black line = 9
– Off black line = 71
– Average = (9+71)/2 = 40

use as threshold
• Get light sensor values
– On black line = ______
– On table = ______
– Average = ______  use as threshold
2/7/2015
Lawrence Technological University
16
Task 2
Measure Height of Rectangle
2/7/2015
Lawrence Technological University
17
Measure Distance
• Determine how far the robot travels when
moving forward
Compute distance traveled by
measuring the number of
rotations of the wheel
Distance
2/7/2015
Lawrence Technological University
18
Measure Distance
• Use the wheel geometry
PI = 3.14
Radius
How can use this
information?
2/7/2015
Lawrence Technological University
19
Measure Distance
• For each rotation of the wheel, the robot will
travel the distance of the Wheel Circumference
• Circumference = (Wheel Diameter) x (PI)
56mm x 3.14 = 176mm
• Distance = Circumference x (# Rotations)
176mm x (# Rotations)
2/7/2015
Lawrence Technological University
20
MeasureRectangle.rbg
• Comments
• Program sequence
–
–
–
–
Search for black
Reset motor encoder (start counting from zero)
Search for white
Calculate distance (Circumference) x (# of Rotations)
and Display distance
– Stop
2/7/2015
Lawrence Technological University
21
MeasureRectangle.rbg
Wheel circumference = 176mm
2/7/2015
Lawrence Technological University
22
Remote NXT display/control
• Run any program
• Menu: Robot->Debugger Window->NXT Remote Screen
• Can see the brick display
• Can click on buttons
2/7/2015
Lawrence Technological University
23
Task 3
Follow a Line or Table Edge
2/7/2015
Lawrence Technological University
24
Follow the Edge of a line
• Use the zig-zag
method to follow the
edge of the table
• Let’s add search for
the Bowl Zone line.
• Can we use waitUntil?
 Must use a loop
block like
Left
Edge
Right
Edge
Table
2/7/2015
Lawrence Technological University
25
EdgeFollowZZ.rbg
• Program
– Loop while light sensor > threshold
• If light2 > threshold, move left (right motor fast, left motor slow)
• Else move to the right (left motor fast, right motor slow)
2/7/2015
Lawrence Technological University
26
EdgeFollow.rbg
• Program
– Loop while light sensor > threshold
• If light2 > threshold, move left (right motor fast, left motor slow)
• Else move to the right (left motor fast, right motor slow)
“Slow” speed
“Fast” speed
Threshold value
2/7/2015
Lawrence Technological University
27
Which box is which?
?
?
?
• Look at text based program then declaration
– Menu: View -> Convert Graphical File to Text
Right-click on function -> Go to Declaration
2/7/2015
Lawrence Technological University
28
How to Improve Edge Following
• Zig-zag method can cause a bumpy response
• To improve the response, try a smooth line
follower (concept shown below)
Turn Left
Turn Left
50
30
Light
Sensor
Reading
50
30
Turn Right
2/7/2015
Light
Sensor
Reading
Turn Right
40
40
2-Level Line Follower
 Zig-Zag
Go Straight
Proportional Line Follower
 Smooth
Lawrence Technological University
29
SmoothEdgeFollow.rbg
Turn Left
Average Speed
Gain or Slope
Light Threshold
Light Sensor Port
Go Straight (30)
Slope (100)
Light
Sensor
50
Reading
30
Turn Right
Light Threshold (40)
Proportional Line Follower
2/7/2015
Important:
If Gain is set too high or
low, the robot will not
follow the Edge well.
Lawrence Technological University
30
Task 4
Compute and Move to
Location for Pins 3&4
2/7/2015
Lawrence Technological University
31
Graphical Robot C
“Custom” Functions*
Description
Displays the distance and stores value internally
Displays the internal value at any time
Function for smooth line tracking
Function for smooth line tracking
Adds number to internal value and stores
Multiplies number with internal value and stores
Subtracts number from internal value and stores
Moves distance corresponding to stored value
*Custom functions were written by the instructor and are not officially supported by RobotC.
Please see files NatLang_NXT.c NatLang_EV3.c and BuiltInVariable.txt in directory
C:\Program Files (x86)\Robomatter Inc\ROBOTC Development Environment 4.X\Includes\
2/7/2015
Lawrence Technological University
32
Calculate Distance d
• Pins 3&4 are located d from edge
• A formula is unveiled for students to enter
– Example formula: d = 300 – x/5 mm
• Black rectangle height x is measured with
robot during the round
• Calculated d with custom functions but first we
need to change to multiplication:
d = 300 – 0.2*x mm
2/7/2015
Lawrence Technological University
33
CalculateDistance_d.rbg
d = 100 – 0.2*x mm
2/7/2015
Lawrence Technological University
34
CalculateMove_d.rbg
d = 100 – 0.2*x mm
Circumference
Speed (negative backup)
2/7/2015
Lawrence Technological University
35
Task 5
Bowl a Tennis Ball
2/7/2015
Lawrence Technological University
36
Bowl A Tennis Ball
• Again, this task is outside the scope of this
workshop
• However, your robot should be in position to
deliver a tennis ball if the previous tasks were
completed successfully
2/7/2015
Lawrence Technological University
37
Task 6
Return to Home Base
2/7/2015
Lawrence Technological University
38
ReturnHome.rbg
One Possibility –
• While looking for foil tape
– Follow the edge
2/7/2015
Lawrence Technological University
39
Putting It All Together
• Recall Key Tasks for Workshop
–
–
–
–
–
2/7/2015
Search for black edge
Measuring height of a rectangle
Follow a line or table edge
Compute and move to location of pins 3 & 4
Return to home base
Lawrence Technological University
40
Little Robots, Big Missions
Questions?
[email protected]
2/7/2015
Lawrence Technological University
41