[go: up one dir, main page]

0% found this document useful (0 votes)
45 views54 pages

Spike Prime Python Game Workshop 2022

The document outlines a workshop for the 2022 Robofest competition, focusing on the OceanBots challenge where autonomous robots earn points by interacting with objects. It details various tasks for programming the LEGO Spike Prime robot, including edge detection, line following, and robot alignment, along with the necessary software and hardware configurations. The workshop is hosted by Lawrence Technological University and includes resources for participants to access additional materials online.

Uploaded by

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

Spike Prime Python Game Workshop 2022

The document outlines a workshop for the 2022 Robofest competition, focusing on the OceanBots challenge where autonomous robots earn points by interacting with objects. It details various tasks for programming the LEGO Spike Prime robot, including edge detection, line following, and robot alignment, along with the necessary software and hardware configurations. The workshop is hosted by Lawrence Technological University and includes resources for participants to access additional materials online.

Uploaded by

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

2022

OceanBots
Spike Prime/Robot Inventor
with Python Game Workshop
This file can be found under the eAcademy > Workshops page on the website

www.robofest.net robofest@ltu.edu 248-204-3568

Room J233 Taubman Complex, LTU


21000 West 10 Mile Road, Southfield, MI 48075, USA

1 1
2022 Workshops
Presented by

Lawrence Technological
University
Computer Science
Course Overview

• 2022 Robofest competition OceanBots


• Autonomous robot that get points by moving Turtles and Trash objects

• Workshop Robot introduction

• Using the Workshop Robot to solve the OceanBots challenge

3
2022 Robofest Competition

● Video overview
● Key tasks
Task 0: Finding the edge of the table
Task 1: Following the edge of the table
Task 2: Stop line following when you reach a corner
Task 3: Stop line following when you reach a given distance
Task 4: Turning the robot
Task 5: Aligning the robot to an edge
Task 6: Building Functions
Task 7: Gyro Turns

4
LEGO Spike Prime robot used
Right Motor: B
Color Sensor: E Spike Prime
Hub

Left Motor: A
Color Sensor: D

5
Remember the connections!

● Left Motor connects to A


● Right Motor connects to B
● RH Color sensor connects to E
● LH Color sensor connects to D

6
Software Versions Used

• Examples used Version 2.0.4


• Download
• https://education.lego.com/en-us/downloads/spike-prime/software

• Presentation and all example programs are available at robofest.net under


Tech Resources

7
Hub Overview Bluetooth

Ports

Scrolling Display

Keys Center (Power)


button

8
Start a New Program

● Create new program using icon or “File>new project”


● Select “Python” option

9
Connect to Hub

● Two options
○ USB Cable
○ Bluetooth
● Follow instructions in software

10
Hub Settings

11
Configure Motors And Sensors

12
Task 0

Finding the edge of the table

13
Task 0: Example Solution

https://youtu.be/goFLg-SG1lo

14
Task 1

Following the edge of the table

15
Following The Edge Of The Table
● Use the zig-zag method to follow the edge of
the table

● Edge following is also referred to as line

Right Edge

Left Edge
following

● The zig-zag method requires the use of a


sensor determine when the robot is on or off the
table

Tabl
e
16
Following The Edge Of The Table

● Get color sensor values to determine when the robot is on or off the table.
We will use the color sensor in Reflective Light Intensity mode.

● Color Sensor 1 Color Sensor 2


○ On table = ______ (99) On table = ______ (99)
○ Off table = ______ (5) Off table = ______ (5)

Color Sensor
Readings

17
Following The Edge Of The Table

● For light sensor #2 settings example


○ On table = 40
○ Off table = 0
○ Median threshold = (99+5)/2 = 52

● Two cases
○ Light sensor reading > 52. On table.
○ Light sensor reading < 52. Off table.

18
Simple Line Following Algorithm

Follow using RIGHT


side of robot

19

https://youtu.be/RGB8nKO5How
How to improve our line following algorithm

● The zig-zag method can cause a bumpy response


● To improve the response, you can use a 3-level line follower (concept shown
below)

Off On Off On
Table Table Table Table

20
How to improve our line following algorithm

21
Task 2

Line following to the corner of the table

22
Line following to the corner

● One method of line following to the corner is to follow the edge of the table
with one color sensor and detect the end of the table with a other color
sensor
○ Sensor 1 used to locate the end of the table
○ Sensor 2 used to follow the edge of the table

Color sensor
2
Color sensor
1

23
Line following to the corner
● Couple comments regarding moving around the table
○ It is possible to travel around the edge of the table with only one color sensor,
but it is more difficult and potentially less reliable than using two colors
sensors
○ Black tape is used to denote zones. We can use the black tape to line follow
to the end of a zone.

24
Line following to the corner

● Recall our line following program


○ Let’s modify the program to stop when the robot reaches the end of the table

Using this program, the robot will line follow


continuously. How can we make the robot
stop when it reaches a corner?

25
Line following to the corner

26
Task 3

Line following a given distance

27
Line following a given distance

● Approach
○ Modify LineFollowStop to stop when the robot travels a given distance

● Tools needed
○ Line following
○ Measure distance traveled

28
Measuring Distances

● How do we measure distance traveled?


● Let’s determine how far the robot travels moving forward for 2
seconds
Compute distance traveled
by measuring the number
of rotations of the wheel

Distance

29
Measuring Distances

● Use the wheel geometry

PI = 3.14

Radius

How can we use


this information?

30
Measuring Distances

● For each rotation of the wheel, the


robot travels (Wheel Diameter) x (PI)
■ Distance = (Wheel Diameter) x (PI) x
(# Rotations)
■ Distance = (5.5 cm) x (PI) x (#
Rotations)
■ Distance = (17.28 cm) x (#
degrees/360)
● Note: Right side motor (B) moves in
positive direction, Left side motor (C)
side moves in negative direction

https://youtu.be/IsRGvC7vaMI
31
Measuring Distances
● Example
○ Let’s program the robot to line follow for 30 cm
■ Distance = 30 cm
○ Number of rotations
■ Distance = (Wheel Diameter) x (PI) x (# Rotations)
■ Distance = (Wheel Diameter) x (PI) x (# degrees/360)
■ Solve for (# degrees)

Distance x 360
(# degrees) =
(Wheel Diameter) x (PI)

30 cm x 360
(# degrees) = = 626 degrees
(5.5 cm) x (PI)
32
Line following a given distance

● Line follow a desired distance

https://youtu.be/ooJ1LFSHgDk

33
Task 4

Turning the robot

34
Turning The Robot

● For our example here, we wish to turn the robot 90 degrees


● There are several methods for turning a tripod robot. We will focus on two
methods
○ “Spin” turn

○ “Swing” turn

35
90 Degree Spin

● Let’s have the robot spin 90 degrees CCW


● The robot will rotate about center of the drive wheels

Starting Position Final Position


Center of
drive
wheels
X
Robot

Robot
X
36
90 Degree Spin

● To spin 90 degrees CCW

● Set the steering to -100. This causes:


○ Right wheel to rotate forward
○ Left wheel to rotate reward
○ Equal and opposite rotations

● Now, we need to determine the correct number of rotations

37
90 Degree Spin

● You can determine the proper number of rotations mathematically;


however, the result typically needs some adjustment due to lash in the
motors

● For today’s class, we will use trial and error to find the number of rotations
that cause the robot to turn 90 degrees

38
90 Degree Spin
● We can use the following code to spin the robot

● For our sample robot, it takes 0.55 rotations to spin the robot 90
degrees

https://youtu.be/k5cqhPFShFc

39
90 Degree Swing

● Let’s have the robot swing 90 degrees CCW


● The robot will rotate about a locked wheel (denoted by red X)

Starting Position Final Position

Robot
X
Robot

40
90 Degree Swing
● To swing, we lock the left motor and power the right motor to turn the
robot

● For our sample robot, it takes 1.0 rotations to swing the robot 90 degrees
https://youtu.be/OlCKeLEf9Us

41
Task 5

Aligning the robot to an edge

42
Aligning the robot to an edge

● In some situations we desire align with robot to an edge of the table as


shown below
● Assuming the starting position below, how can we program the robot to reach
the final position that is aligned with the edge of the table?

Robot
Starting Position Final Position

43
Aligning the robot to an edge
● Travel until RIGHT color sensor reaches the edge, swing robot until it is
aligned with the edge

44
Align if either side detects edge first

https://youtu.be/998DFfMUXw0

45
Task 6

Creating Functions

46
Functions

● Solving the Robofest Game challenge will typically require a fairly large
program (around 100 lines is not unreasonable)
● Very large programs can be difficult to understand, navigate and use
● To alleviate this issue, the software has the ability to create custom code
that can replace sections of your program

47
Create Function to Find Edge of Table

48
Task 7

Gyro Turns

49
More Precise Turns with a Gyro

● Spike Prime has a built in


Gyro sensor
● Gyro sensor can be used for
turns

50
Turning with Gyro
Right Turn Left Turn

51
Putting It All Together
● In this course we learned about
– Finding the edge of the table
– Following the edge of the table
– Stop line following
– When you reach a corner
– When you reach a given distance
– Turning the robot
– Aligning the robot to an edge
– Building Functions
– Gyro turns

52
Little Robots, Big Missions

Questions?

robofest@LTU.edu
LTU Computer Science
53
2022 Workshops
Sponsored by

Lawrence Technological
University
Computer Science

You might also like