Lego Spike Prime Fishing game - Everest Alonso

From RoboWiki
Jump to: navigation, search

Introduction

In this robotics projects I aim to create a robotic game with two functions. The first function is to act as a fishing simulating game which relies on the player’s reaction time to ‘catch fish’, this will be done using the LEGO Spike Prime robot. The second function is to collect and display some data about the player’s performance in the game so that after a session of one or multiple games the player can see how they performed.

Overview of Game

The game is intended to simulate the experience of fishing, the player will watch a fishing rod and wait for a bite from a fish. Occasionally, the rod will twitch slightly as in real life, but this does not mean that there is a fish to be caught. When there is a fish, the rod will be pulled down and the player must react quickly to catch the fish. Before the rod returns to its original position the player must press a button to pull the rod up and out of the water to catch the fish. If the player reacted fast then a fish is caught and the score will increase, the rod is lowered back to the water and the game continues. If the player is too slow and pressed the button too late then the game is over. If the player presses the button when there is only a small twitch in the rod then the game is over also.

Project Goals

This project is in two main parts: the fishing game and the statistical display after the game is finished. The fishing game has the following goals:

1. There is a long robotic arm attached to a motor to simulate a fishing rod.

2. The user can start a new game with the press of a button.

3. During the game, the fishing rod is lowered, and the program will randomly decide a small number of seconds to wait until something happens.

4. When something happens, there will either be a small knock or a big bite which is randomly decided.

5. If there is a small knock the rod will twitch slightly.

6. If there is a big bite then the rod will go down and then back up, during this time there will be the opportunity for the player to score a point by pressing a button and ‘striking’ their fishing rod.

7. If the player presses the ‘strike’ button while there is a big bite, they will gain a point, a success sound will play and the game will continue.

8. If the player presses the ‘strike’ button while there is not a big bite ( for example, if they player ‘strikes’ during just a small knock or if the player ‘strikes’ for a big bite but their reaction time is too slow), the game will end.

9. Throughout the duration of the game the player’s current score is displayed by the Spike Prime pixel display.

The statistic display has the following goals:

1. While the program is running, 3 pieces of data will be collected: the total number of fish caught, the total number of fish that were missed ( when there was a big bite but the user did not strike) and the total number of failed strikes where the user struck but there was no big bite.

2. This data will be collected over an entire session not just one game so the user can see their total numbers across multiple games.

3. After each game, the current date will be shown in a bar graph in a small window.

4. Alongside the bar graph will be a small display which labels the data in the bar chart.

Implementation of Goals: Physical Robot

The physical robot for this game is very simple, it requires the main Spike Prime hub, a motor, a long Lego piece to act as the fishing rod and some small connectors to make the robot into a single connected unit.

Picture1.jpg

For decorative purposed I have added string and a small fish to the end of the line although this has no bearing on the gameplay. Below is the robot without decoration:

Picture2.jpg

The motor is held onto the hub using two tube connectors.

Picture3.jpg

The fishing rod is built as shown below:

Picture4.jpg Picture5.jpg

Implementation of Goals: Code

In the interest of this project being repeatable by younger people I have used the word blocks interface provided by the Spike Prime website.

Start of Program

When the program starts, all the variables are initialised and set to values of zero. Caught fish, missed fish and failed strikes are counting variables which will be used in the bar chart later. Bite is a Boolean variable which indicates if a big bite is currently occurring.

Picture7.jpg

Then, the motor speed is set to a slow speed and the rod moves so that it is at 45 degrees.

Picture8.jpg

Finally for the starting process, the bar chart and label displays are created and then hidden.

Picture9.jpg

Starting Game

When the user presses the left button on the hub, it indicates that they are ready to start playing the game. First, other stacks are stopped, then the score is set to zero and the message ‘fishing’ is broadcast.

Picture10.jpg

Gameplay

When the fishing message is received, the fishing game begins, bite is set to zero and the rod first slowly is moved into the lowered position. Then the movement speed is increased to a high speed for the fast motions of the knocks and the bites.

Picture11.jpg

Originally, I assumed that since bite was already set as zero I wouldn’t need to do it again but I kept encountering an issue with false positives where when the player struck their rod they would gain a point even if there was no bite. Resetting bite to zero every time the fishing message is called seemed to fix this issue. The display on the hub is set then to show the player’s current score.

Picture12.jpg

Then, a forever loop is set. Inside the loop, the program will wait any time from 1 to 7 seconds before performing one of two actions.

Picture13.jpg

After waiting, the program gives a 1 in 3 chance of enacting a big bite. Bite is momentarily set to be true, the rod then moves quickly down and back up to indicate the bite to the player and then bite is retuned to being false. After, assuming the stack has not been ended by another stack, the value of missed fish is incremented.

Picture14.jpg

This 1 in 3 chance of a big bite leaves a 2 in 3 chance of a small knock. If this is the case, then the rod moves quickly and only slightly down and back again to indicate the small knock by an interested fish.

Picture15.jpg

This ends the if statement and so once this action is completed the forever loop will repeat, waiting some time and then performing another action.

Striking

If the user at any point presses the right button on the hub, then they are striking their rod (lifting it out of the water). The code must first stop all other stacks so that if bite is true, the fishing stack is stopped before bite can stop being true and the value of bite is frozen. Next the rod moves up to a 45-degree angle.

Picture16.jpg

Next is an if statement. If bite is true then the user has caught a fish, so a short sound is played to indicate to the player that they have scored a point. After, the score is incremented, as is the variable which counts the total number of caught fish for the bar chart. The message fishing is then broadcast so that the game can continue, and the player can try to catch more fish.

Picture17.jpg

If bite is not true, then the player has not caught a fish. The variable which counts the number of failed strikes is incremented. A 7-note melody is played to let the user know that the game is over and they have failed.

Picture18.jpg

Since the game is now over, it is time to display the current data on the bar chart. Note that the session is not over and so if the player presses the left button on the hub a new game will be started, and the bar chart will again be hidden until that game is over. The values of caught fish, missed fish and failed strikes are assigned colours on the bar chart. The bar graph is then shown, along with the display which contains the labels.

Picture19.jpg

An example of the bar graph looks like this:

Picture20.jpg


Full Code

Picture21.jpg


Video


Literature Review

Title: "From Scratch to Python – Lego Robots as Motivational Tools for Coding"

Authors: Attila Körei, Szilvia Szilágyi

Summary:

In their article, "From Scratch to Python – Lego Robots as Motivational Tools for Coding," Attila Körei and Szilvia Szilágyi explore Educational Robotics and its role in cultivating coding skills among students. The focus is on LEGO robots, particularly the SPIKE Prime set, as an effective tool for hands-on learning experiences that range from primary education to higher levels such as college and even university. The authors begin by highlighting the significance of IT skills and coding abilities in today's digital world. They emphasize the need to encourage interest in coding from students early on, a sentiment echoed by Mitch Resnick, the creator of the Scratch programming language. The article addresses the current gap in programming education, especially at the secondary level, and underscores the importance of making the initial encounter with programming both motivating and inspiring. LEGO Education's long-standing commitment to STEM (Science, Technology, Engineering, and Mathematics) learning is acknowledged, with a historical overview of LEGO's robotics products, from LEGO Technic Control 0 to the recent SPIKE Prime release in 2020. The collaboration between LEGO and MIT is noted, illustrating the shared vision of combining creative play with the potential of computers. The SPIKE Prime set stands out due to its programmable hub, motors, sensors, and compatibility with Scratch-based languages and Python. The authors present a compelling argument for the versatility of SPIKE Prime, allowing for differentiated projects at various levels of education. A significant portion of the article is dedicated to the implementation of a binary conversion task, showcasing its adaptation to different difficulty levels. The authors provide programming examples using Scratch-based languages at the basic and intermediate levels and demonstrate the application of Python for a more advanced level. This example underscores the potential of using LEGO robots to teach fundamental programming concepts, even in university settings. The article concludes by emphasizing the advantages of Scratch's Hungarian language support, making it accessible to a broader audience. It also reiterates the potential of LEGO SPIKE Prime in motivating students to transition from Scratch to more advanced programming languages like Python. Overall, the authors argue that integrating robotics activities into educational curricula not only sparks early interest in technology-related careers but also serves as an effective method for teaching coding in a playful and engaging manner.

Review:

My personal take on the article is that I agree with the premise that integration of systems into education at an early age and continued use is a very powerful tool in garnering interest in the subject. At the age of around 8 years I was introduced in school to the LEGO Mindstorms in a simple maze solving exercise which was very fun. However, after this session I did not have any other interaction with programming or robotics until late into high school when I was taught python. When learning python I did not originally learn with appealing exercises but with simple yet boring exercises such as encoding a Fibonacci sequence. Throughout my education I have spend the most of my free time coding only when I am coding games, as these are the area that I enjoy to code the most due to their creativity. I believe that the lego robots such as SPIKE Prime and Mindstorm are not only fun to use because of the ability to create games but because LEGO by its nature is creative meaning that even for a less glamorous application of the robot there is still much creative freedom in how to build and use the device. This freedom and the recognisability of lego’s brand as a playful and fun thing to do means that from a young age up to and including a university level these robots can provide meaningful and engaging challenges for people of all abilities.

References

Attila, K. and Szilvia, S., 2022. From Scratch to Python-Lego Robots as Motivational Tools for Coding. Multidiszciplináris Tudományok, 12(3), pp.247-255.

Petrovič, Pavel. "Spike up prime interest in physics." In Robotics in Education: Methodologies and Technologies, pp. 146-160. Springer International Publishing, 2021.