Minecraft coding in the classroom – 1st draft

Today’s post sways a little off the normal Raspberry Pi stuff, there is a link though!

Minecraft

One of the awesomest pieces of software the Raspberry Pi has for teaching in Minecraft Pi edition Link . If you don’t have it on your Raspberry Pi, why not?! It is great as kids can easily program modifications to the game in python allowing them to place blocks, move players and do all kinds of cool stuff. There is a problem for it though in education, not every school has a classroom of Raspberry Pis…

Fret not though, a Bukkit developer has gone and made a Bukkit plugin to emulate the API but for the normal version of minecraft.

We will start though from the start. What is minecraft?

Minecraft is a sandbox! It is a game played by millions of people across the world. It is very popular with teenagers especially. The game has a massive community behind it and is easily modifiable with the use of Java.

Modifying the game though brings with it a number of problems including modifications not playing nice with each other. To make it easier to mod the game and to help mods play nice together, a number of community projects emerged making their own APIs. The 2 most popular of these are Bukkit and Minecraft Forge. Both are not run by Mojang (Minecraft developers) and are maintained as opensource projects through donations.

Bukkit is an stable and the standard server platform for 90% of Minecraft servers out there. It has an easy to use API and a massive collection of plugins allowing you to manage players on a server and keep order. There are also a number of specialist plugins, we will be looking later at one called RaspberryJuice. Bukkit is a server only platform, it can not modify the actual client (aka add more buttons, new blocks or new menus).

Minecraft forge, the other major platform, allows direct modification to the client. This allows you to do things like add new menus, buttons, blocks. MinecraftEDU is designed for Minecraft forge. It has a very powerful API that allows you to change most of Minecraft.

 Minecraft Pi edition

Minecraft Pi edition is a special version of minecraft developed for the Raspberry Pi which is based off another branch of minecraft, Pocket edition (designed for mobile devices). It has only the basic features of minecraft but can easily run on the Raspberry Pi.The important bit though about minecraft Pi edition is it has its own simple to use API for interacting with the world! You can tp players, break or place blocks etc in languages like python, java, javascript etc.

This API is great for the classroom and at home but it has an issue. What if you don’t have a Raspberry Pi? A lot of schools dont yet have a full classroom yet of Raspberry Pis but have a fully kitted out ICT suit with much more powerful computers than the Raspberry Pi. What about this API for normal PCs? A developer has gone and created just that! An easy to use plugin called RaspberryJuice has been released that allows players to use exactly the same API but using normal Minecraft.

Each student must be running a mini server though to use this seeing as it requires bukkit, this allows teaching simple commandline based server applications too.

By using Bukkit, you also have access to 1000s of plugins that allow you to customize the entire experience. For the plugins check out their database http://plugins.bukkit.org/

Lets set up a server

First you will need a minecraft account (€19), it is likely most students will have one. MinecraftEdu offer discounts to schools and can get them as low as €10. You only need 1 set of accounts per classroom (and if they arent connecting to the same server, 1 set per school).

Next you need to set up the clients, it is a very easy process. Make sure java is installed (most machines it is), download client from Here and you are good to go.

If you are using RaspberryJuice each client also needs a mini server running in the background. The basic idea is they run their own mini preconfigured server then they just connect to localhost (aka, themselves). Using this method also allows students to connect to each others servers if they know their IP addresses.

You need to create a folder with the server stuff in it. I will be demoing this on a mac, but it will work also on windows and linux.

Make a new folder for your server and grab the latest beta build of bukkit (It is also known as craftbukkit) from dl.bukkit.org .

Bukkit has 3 standard release channels, unstable (daily releases, dont use), beta (a tested build that most things should work for, these are fine) and a recommended build (these are the most stable, there are very few of these).

Minecraft is constantly being upgraded with new features, a new update comes out on average every 1.5-2 months and will be heavily publicized before its release. Best place to hear about new versions is https://mojang.com/. They also do snapshots which are unstable test versions normally released once a week. These are minecraft versions, not bukkit. Minecraft follows a numbering system that increments .1 every major release and .0.1 for bug fixes, for example as of writing, the current version is 1.6.2. 1.6 is the main version number and there has been 2 bug fix updates. Remember, these are different from bukkit releases. Bukkit releases can take 1-2 weeks after a major update and 2-3 days after a bug fix update. When a new version comes out, you dont need to update, it is normally smarter not to until everything settles down.

When configuring the clients, it is important to go into edit profile and change the dropdown menu from latest version to the current version, this way the clients wont auto update. See the picture belowVersion

So, now you have bukkit (also known as craftbukkit), place it in your server folder you created and rename it to craftbukkit.jar. The result of this is below

We only have 1 file so far, the server!
We only have 1 file so far, the server!

The normal thing to do for most people is just double click it, sadly minecraft servers dont work like that, they need a script to launch them correctly. I have provided all the startup scripts here StartFiles

The .bat is for windows, .command is for mac.

Remember, the server .jar file must be called craftbukkit.jar

We are now ready to test out our server. Double click the start.something file and watch as a terminal or cmd opens with a load text.

The important bit here is at the bottom. It explains that it is generating the minecraft work which can take a few mins.
The important bit here is at the bottom. It explains that it is generating the minecraft work which can take a few mins.

You now have your very own minecraft server up and running.

!!!VERY IMPORTANT!!! Do not ever close the terminal or cmd with the x at the top! To correctly stop a server you must type stop into the terminal and hit enter. If you close it by mistake, easiest way to fix it is reboot your computer !!!VERY IMPORTANT!!!

You can connect to your minecraft server by launching minecraft, clicking multiplayer and connecting to localhost

If you can connect, you have done it all right!

 

Plugins?

To modify the experience for your students you can use plugins. These are modifications to the server developed for free by members of the community using the bukkit API. To add one, you simply download its .jar file and drop it into the plugins folder inside the server folder. Reboot your server and it will auto load on startup. Keep an eye on which version plugins were developed for, some older plugins may not work on more recent versions of bukkit. Most plugins work perfectly fine, RaspberryJuice for example was released 2 major releases back and it still works perfectly fine. Make sure to read the documentation that is on the plugin page if you are putting any other plugins.

Other stuff you need to know

You may want to edit some configuration text files, these are auto created when the server starts. The server.properties file is the main config file for the server. Details of it and its settings can be found at http://www.minecraftwiki.net/wiki/Server.properties

Minecraft servers have a built in permission system that is rather simple, you have 2 levels.

  • Player – can build, mine and play as a normal player
  • Op – (short for operator). The Op has full power over the server, can spawn in blocks, can change to creative mode (fly and infinite blocks) and can stop the server.

To add yourself as an op open the ops.txt file and add your name on the first line. You can also add it ingame and from server console.

Commands

The server is controlled via a series of commands, a user at the console has full permission to type any command, an Op ingame can type most commands and a play can type barely any.

To type a command ingame you prefix the command with a /

For example /stop from ingame would shut down the server. At the console you only need to type in stop and hit enter and the server will shut down. Make sure to give it a min to save the map.

A full list of commands can be found at http://www.minecraftwiki.net/wiki/Commands

You will need to download the minecraft pi version to grab the api folder which contains the python library, drop the api/python/minecraft folder into the base directory of your server. Then follow the normal minecraft pi guides but make sure to save your python scripts in your server base directory

Server is red World data files are grey Some of my python files are green API folder is yellow Text files to worry about are purple Stuff to ignore is orange
Server is red
World data files are grey
Some of my python files are green
API folder is yellow
Text files to worry about are purple
Stuff to ignore is orange

Each student will need a mini server for themselves, you can create the folder, zip it up and put it on a pendrive or shared network space and let them grab it, you dont need to include the folders in grey as the server will auto generate new worlds if no worlds exist.

Also keep in mind, if students know other students IP addresses, they can connect to each others server or write python scripts to do stuff to other peoples servers, it is up to you if you want to allow them to find out each others IP addresses 🙂

With a server running, connect to it with your client and you are good to go, create some python scripts!

Resources

http://blog.whaleygeek.co.uk/minecraft-pi-with-python/
http://www.stuffaboutcode.com/p/minecraft.html
http://arghbox.wordpress.com/2013/06/13/programming-minecraft-pi-with-python-early-draft/

 

 

Pi powered Panobot v1

I have just finshed work on version 1 of my Pi powered Panobot. It is a robot designed to take panoramas with the official raspberry pi camera board.

It is built out of lego and uses the same motors and motor controller as my Lego Pibot.

It runs a python script which allows me to program how wide a panorama I want and how many levels. Once the images are taken I copy them over to my laptop and stitch them together into one image using Hugin http://hugin.sourceforge.net/

The Pi camera is very good for its price but compared to my DSLR has a smaller dynamic range and also a smaller HFOV (Horizontal Field Of View) so to get a panorama, it requires a few more pictures. I found to allow enough overlap that 10 pictures wide was sufficient by 3 pictures tall. This totaled to 30 pictures per panorama compared to my normal 25 pictures for my DSLR. I have to stitch them on my laptop instead of the pi due to massive amount of processing power to find the control points

So, time for some pictures

The panobot on a hedge taking some pictures
The panobot on a hedge taking some pictures
A closer look inside the panobot
A closer look inside the panobot

Now for what you have been waiting for, what images does it produce?

180 Degree panorama

A full 360 degree panorama shot with the Raspberry Pi camera board
A full 360 degree panorama shot with the Raspberry Pi camera board

For the full sized panobot panorama click here as wordpress limits the upload size

A panorama taken from the same area with my DSLR (Canon 600d)
A panorama taken from the same area with my DSLR (Canon 600d)

For the full sized DSLR panorama click here as wordpress limits the upload size

280 degree panorama taken in the evening before batteries died
280 degree panorama taken in the evening before batteries died

For the full sized  panorama click here as wordpress limits the upload size

Full 360 degree panorama made up of just 30 pictures!
Full 360 degree panorama made up of just 30 pictures!

For the full sized  panorama click here as wordpress limits the upload size

For the full sized  panorama click here as wordpress limits the upload size

 

As you can see, there really isn’t much in it between the DSLR and the Raspberry Pi Panobot. There is two thing though to take into account though.

Time

The Panobot takes around 2 mins to complete a full panorama

Using the DSLR I took the example panorama in under 30 seconds

Stitching

Because of the larger HFOV on my 28mm lens on my DSLR, I only took 24 photos for the full panorama (In portrait mode to reduce lens distortion). 24 photos takes about 3-4 mins to stitch

The Pi camera board took 30 pictures to get a full panorama. It took 4 mins to stitch those though.

So there is definitely trade off with using a completely automated pi camera but I am still quite pleased with the results. It was a great learning experience and a great option for someone who can’t afford a larger camera, the whole system (excluding lego) runs in about £50-£60

A copy of the python code can be found here

A copy of the python code on github can be found here

Lego Pibot Ultrasonic wall avoider

I have been working on getting the cheap ultrasonic sensor working for the past week and have got it working with my Lego Pibot.

It sends out an ultrasonic blip every 0.1 seconds and measures the time it takes for it to get a bouce back.

I followed a very helpful guide at raspberry spy which I got a lot of the ideas from.

http://www.raspberrypi-spy.co.uk/2012/12/ultrasonic-distance-measurement-using-python-part-1/

Raspberry Pi camera board – Gstreamer

So, my Raspberry Pi camera board has arrived and I have started playing with it.

Raspberry Pi camera board

My first impressions were tiny, super cheap camera. Its low light capabilities are not great but I can live with that. The important bit is the quality, full 1080p at 25 frames per second (UK). That on its own is pritty awesome.

I was though only really interested in getting the pi to work remotely for my robot to replace the 3-4 fps standard def USB webcam I currently use. Currently though with the camera, there is no V4L driver so we have to make do with their provided applications then pipe it out to streaming applications. Their recommended method is slow and very laggy (netcat and mplayer with wifi provides 3-6 seconds of lag). So I had to find another option. I happened to be sitting on the #raspberrypi IRC on freenode and heard a user having success with gstreamer. So this is how to set up gstreamer to stream HD video with less than 0.5 seconds of lag.

First we need to add a repositary with gstreamer1.0

 

sudo nano /etc/apt/sources.list

 

and add to the end

 

deb http://vontaene.de/raspbian-updates/ . main

 

Then do an sudo apt-get update

next grab gstreamer

 

sudo apt-get install gstreamer1.0

 

 

On your recieving end you will also need gstreamer. Because I mainly use a mac, I decided to get it working on the mac so with help from arcanescu on IRC, we figured out how to get it working on mac os (10.8)

The simplest way is with brew, a package manager like apt-get, but for mac os. To install it run this in terminal on your mac simply run

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

It will grab and install brew. Now update it with

 

brew update 

 

Now we need to grab gstreamer

 

 brew install gstreamer gst-libav gst-plugins-ugly gst-plugins-base gst-plugins-bad gst-plugins-good 

 

Once that installs you should be good to go. Enter

 

 raspivid -t 999999 -h 720 -w 1080 -fps 25 -hf -b 2000000 -o - | gst-launch-1.0 -v fdsrc ! h264parse !  rtph264pay config-interval=1 pt=96 ! gdppay ! tcpserversink host=YOUR-PI-IP-ADDRESS port=5000 

 

on your raspberry pi and enter on your mac

 

 gst-launch-1.0 -v tcpclientsrc host=YOUR-PI-IP-ADDRESS port=5000  ! gdpdepay !  rtph264depay ! avdec_h264 ! videoconvert ! autovideosink sync=false 

 

The picture quality is good but I see a number of flickers which isnt a problem for me, if it is for you, maybe try adjusting the resolution

 

So thanks again to arcanescu, I take no credit for this as it was him that came up with this, if you ever see him in IRC, give him a virtual pat on the back

His blog garagedeveloper.wordpress.com

Lego Pibot revision 0.2

 

I have been working away at my Lego Pibot recently and now have something to show for it.

I rebuilt the entire thing making it more efficient in turning, it uses a towering design and is more modular. It has 4 levels with batteries, pi, breadboard and camera.

It also has support for an additional attachment on the front, so far I have used that to attach a lift-able pen on the front to draw over paper (turtle style). Finally I have added space for a breadboard and also added the extra motor for rotating the webcam.

All the electronics are the same as the first Lego Pibot with the exception of the additional motor and the breadboard for prototyping. i have also added a cheap ultrasonic sensor off eBay to it but am having issues with it right now.

What isn’t shown in the video is the wiimote support I have added. I have written an additional script for controlling the robot with Bluetooth using a wiimote.

When it is finished I will post the source code, as normal, it is in python.

Also new is the addition of scratch controlling. The robot can be really easily controlled by scratch GPIO making it really simple to write control programs.

 

As normal, if you have any questions on this, post a comment below or on the video.