Bodgers – Writing Our Own Functions

logo

Hi Everybody

Our WiFi set up worked much better this week with an issue with only one of our routers which decided to give up half way through the session.

We started to write our own functions today, functions are very important in programming as they allow us to run the same code multiple times without rewriting the code several times. Instead, you can put that code inside a function and call the function several times. This has the added benefit that if the function’s code has a mistake, you only have one place in the program to fix it.

If we use names that relate to our function’s operation it will make our code much easier to understand.

Functions make designing and testing bigger programs much easier as we can break the project down to manageable chunks and we can write and test these functions individually.

As we saw last week the GPIO Zero library contains robot functions which turn our robot’s wheels forwards or backwards or in opposite directions to go left or right until we call the robot.stop() function. We are going to take these functions and the sleep() function and put them in functions that will make our robot go forward or backwards  by a specified amount of Centimetres or will turn it left or right by an amount of degrees. This week we wrote a function that makes our robot go forward. See code here. Here are this weeks slides writing-functions . Next week we will write the rest of our functions.

Some Bodgers and their parents have been asking about buying Raspberry Pis but I would advise holding off until we decide on our projects as some people may end up using Arduinos or Raspberry Pi Zeros depending on their project.

However if you want to get one to experiment at home with I would recommend the following sites. https://shop.pimoroni.com/ and https://thepihut.com/ for Raspberry Pi and accessories. If you are buying a case for your Pi I would recommend Pibow Coupé from Pimoroni as the GPIO pins are numbered and easy to get at. For electronic components such as sensors etc.  http://www.bitsbox.co.uk/ are very good, they also do cheap Arduino clones. Avoid starter kits as you should be able to get your hands on stuff like keyboards if you ask friends and relations for them, do get SD cards as you can have different set ups on different cards e.g. Retropi, Kodi.

See you all next week.

Week 4 Explorers – Ghostcatcher

Hello Everyone

Great to see so many of you there on Saturday, 77 Ninjas!. Hope you had a good time. And a special welcome to our new Ninjas.

This week we created a Ghostcatcher game. We used the paint editor in Scratch for the first time. As I said on Saturday, It makes things easier if you think in shapes.

PACMAN

Using the code we have learned so far, we moved the Ghostcatcher with the mouse and the Ghosts randomly. We also added some sound.

PACMAN2

We are going to continue on next week and improve this game, adding some Variables and some levels.

Here are this weeks notes in PDF. cda-s6-week_04-ghostcatcher.pdf

Creators – Covering the Basics

PhysicsTest

We’ve been busy the last two weeks covering the basics of Unity. Among the topics we’ve touched on are:

  • Customising the Unity layout
  • Explaining what the main Unity windows (Scene, Game, Hierarchy, Project and Inspector) are each for
  • Talked about 3D space and vectors and talked about the difference between local and global axes (child objects)
  • Shown how to place objects in the scene and how to position, rotate and scale them
  • Shown how to “fly” around the scene view
  • Explained how the physics engine works (Physics clock monitoring and moving rigidbodies and tracking collisions and other interactions)
  • Built a simple physics-based scene which had a ball fall, hit a ramp and roll into a bunch of stacked block
  • Wrote a script to have the camera follow the ball as it moves

 

Additionally Mike kindly filled in and talked about the basics of object oriented programming, classes and class diagrams. There is a post from last year that covers this well for those who’d like to read it.

Additionally, the basics of the C# language that we discussed are covered in both that post which we have already linked to above and another which can be found here. The topics we touched on were:

  • Curly braces as “containers” and the requirement that they occur in pairs.
  • How semicolons (;) mark the end of statements
  • Using directives and namespaces.
  • A basic class declaration
  • Properties, both public and private
  • Methods, both public and private
  • How Unity automatically calls certain methods at certain times, and some specific examples of this:
    • Start() called when we start the game
    • Update() called every time the scene is drawn

 

The up-to-date project file can be found here. Please note it will require Unity 4.5.1 or later.

Hackers – tips for safely using a 3D printer

We were very pleased this week to be able to let the first members of the Hackers group take home 3D printers for the week to experiment with them. We will continue to do this in the coming weeks.

Here are some guidelines on safely using a 3D printer, prepared again by Kevin from Boston Scientific:

3d-printer-operating-guidlines (PDF)

Next time, we will take a closer look at building models in a 3D modelling package.

Bodgers – Getting Started With Robots

We are still having network difficulties with WiFi on our Raspberry Pi3s but I will work on finding a solution or a work around during the week.

We managed to connect to two of our robots and we wrote a simple hello world script and a script to control our robots. When we use Python and the Gpio Zero module all it takes to control a wheeled robot like ours is 9 different lines of code these are:

  1. from time import sleep – this will allow us to call the sleep function later in the code.
  2. from gpiozero import Robot – this will allow us to call all the robot functions from Gpio Zero.
  3. robot = Robot(left=(22,23),right=(24,25)) – this is the most complicated line in our code, all it does is assign which gpio pins will be used to control our robot. This will become much clearer when we start to build simpler circuits later in the year.
  4. robot.forward() – this function drives all our motors forward.
  5. robot.backward() – this function drives all our motors backward.
  6. robot.left() – this function drives the motors on the right forward and the motors on the left backward.
  7. robot.right() – this function drives the motors on the left forward and the motors on the right backward.
  8. sleep() – this function pauses the program.
  9.  robot.stop() – this function stops the motors.

If we want to drive our robot forward for five seconds we would use the following code

  1. from time import sleep
  2. from gpiozero import Robot
  3. robot = Robot(left=(22,23),right=(24,25))
  4. robot.forward()
  5. sleep(5)
  6. robot.stop()

We had a brainstorming session about what we might do for our projects and we came up with some great ideas which we talk more about on Saturday. My slides from Saturday are  here robot-intro.

Explorers – Building on our first game

Hi everyone,

Great to see you all there on Saturday. This weeks starting point was our game from last week. We wanted to add extra functionality. We added code to the Snowflake so that something happened when the Penguin touched it. Most people added some sound.

sensing

We also made our first variable. We did this so that we could keep track of our score. Using this score we also could add code to make something happen when you reached a certain score and win the game. Again here we added a sound and switched backgrounds.

variable

We learned and used a lot of new code this week and we will see over the coming weeks how we can incorporate it into many different types of games.

Why don’t you try using all the code you have learned so far to create your own game.

yourgame

See you all next week!

Here are the notes from todays session in PDF cda-s5-week_03-firstgame-part2.pdf