Showing posts with label star wars. Show all posts
Showing posts with label star wars. Show all posts

Sunday 3 January 2016

Raspberry Pi gesture controlled Minecraft X-Wing

figure 1
This post builds on an earlier project to get a simple X-Wing into Minecraft on a Raspberry Pi.  The goal was get Python to build and move the X-Wing. Details of this project can be found here.

In this post the additional of Pirmoroni's Skywriter HAT included to allow movements of a hand to enable the X-Wing to take-off, land, move forward or backward.

It builds on ideas from the book Adventures in Minecraft on using Python and Minecraft using a Raspberry Pi.


figure 2
The Skywriter is a Raspberry Pi HAT (see figure 2) that allows positional information of the hand just above the board. In this project it is detecting flicks of the hand up, down, or across the board to determine the direction of motion.

Before you start, to use the Skywriter, in the terminal you need to add curl -sSL get.pimoroni.com/skywriter | bash

To start with we just placed the X-Wing above the player by placing blocks in the shape (roughly) of the X-Wing based around the method MinecraftShape (see Chapter 8 of Adventures in Minecraft ).



figure 3
  • Find the position of the player;
  • To avoid building on top the player the starting position of the X-Wing is set by:
    • add 5 to the x position of the player;
    • add 10 to the y position of the player(The bit I have to keep reminding myself is the y-axis is vertical.);
    • add 5 to the z position of the player;
  • Using these values build using, Wool blocks, the X-Wing - 0 for white, and 14 for red blocks;
  • If a flick starts at the top of the board (or "north") this moves the X-Wing down towards the ground;
  • If a flick starts at the bottom of the board (or "south") this moves the X-Wing vertically up;
  • If a flick starts on the right of the board (or "east") the X-Wing moves backwards horizontally;
  • if a flick starts on the left of the board (or "west") the X-Wing moves forward.
    from mcpi.minecraft import Minecraft
    from mcpi import block
    import mcpi.minecraftstuff as minecraftstuff
    import time
    import skywriter
    import signal

    mc=Minecraft.create()
    xPos=mc.player.getTilePos()
    xPos.x=xPos.x+5
    xPos.y=xPos.y+5
    xPos.z=xPos.z+5

    xWingBlocks=[
    minecraftstuff.ShapeBlock(0,0,0,block.WOOL.id,0),
    minecraftstuff.ShapeBlock(-1,0,0,block.WOOL.id,0),
    minecraftstuff.ShapeBlock(-2,0,0,block.WOOL.id,14),
    minecraftstuff.ShapeBlock(-3,0,0,block.WOOL.id,0),
    minecraftstuff.ShapeBlock(1,0,0,block.WOOL.id,0),
    minecraftstuff.ShapeBlock(0,1,0,block.WOOL.id,0),
    minecraftstuff.ShapeBlock(1,1,0,block.WOOL.id,0),
    minecraftstuff.ShapeBlock(2,0,0,block.WOOL.id,0),
    minecraftstuff.ShapeBlock(2,1,0,block.WOOL.id,0),
    minecraftstuff.ShapeBlock(1,2,-1,block.WOOL.id,14),
    minecraftstuff.ShapeBlock(1,2,1,block.WOOL.id,14),
    minecraftstuff.ShapeBlock(1,-1,-1,block.WOOL.id,14),
    minecraftstuff.ShapeBlock(1,-1,1,block.WOOL.id,14),
    minecraftstuff.ShapeBlock(1,3,-2,block.WOOL.id,0),
    minecraftstuff.ShapeBlock(1,3,2,block.WOOL.id,0),
    minecraftstuff.ShapeBlock(1,-2,-2,block.WOOL.id,0),
    minecraftstuff.ShapeBlock(1,-2,2,block.WOOL.id,0)]

    xWingShape=minecraftstuff.MinecraftShape(mc,xPos,xWingBlocks)

    @skywriter.flick()
    def flick(start,finish):
      if start=="south":
        for count in range(1,10):
          time.sleep(0.1)
          xWingShape.moveBy(0,1,0)
      if start=="west":
        for count in range(1,10):
          time.sleep(0.1)
          xWingShape.moveBy(-1,0,0)
      if start=="east":
        for count in range(1,10):
          time.sleep(0.1)
          xWingShape.moveBy(1,0,0)
      if start=="north":
        for count in range(1,10):
          time.sleep(0.1)
          xWingShape.moveBy(0,-1,0)
    signal.pause()




    For more details on Minecraft and Python I would suggest going to http://www.stuffaboutcode.com/2013/11/coding-shapes-in-minecraft.html especially on how to download the software to implement MinecraftShape. 
    If you do use or modify please leave a comment, I would love to see what others do with it.






    All views are those of the author and should not be seen as the views of any organisation the author is associated with.


    Saturday 26 December 2015

    BB-8, Droid I was looking for... - Tynkering

    In a recent post controlling the Sphero BB-8 with the Tickle App was discussed.

    This is not the only alternative software, the Tynker App can also control it.


    This is also a graphical drag and drop programming tool, that you can connect certain 'toys' to. Though the App itself is about developing programming skills.










    The Sphero BB-8 Droid can be connected to Tynker (or how I did it anyway) by:

        • Clicking on the Create button on the opening screen;
        • Clicking on Blank Template;
        • Deleting the 'Actor' that has there and clicking on the + button in the top right hand corner of the screen;
        • Clicking on connected toys and selecting the grey ball;
        • On the main screen it should say spherobot with a code button at the side, click on the button;
        • You should get a screen with some code for changing the colour shown and then moving in a square- you can change this for your own code.
    Not all the commands, listed down the side, will work with the BB-8 - I restricted myself to the ones under common (star in the list).

    The Tynker app is a nice tool anyway with lots of games related activities to try. Having the ability to connect and program certain devices is a benefit.


    If you have comments or experiences with Tynker, Sphero BB-8 or Tickle app please add them.





    All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with.

    Friday 25 December 2015

    BB-8, this is the Droid I was looking for...




    Previously I have shown the Sphero BB-8 rolling around the room under its own control

    One of the features of the Sphero BB-8 Droid  is it programmable either by its own downloadable software but also by one of my favourite apps - TickleApp which has been discussed in previous posts. This app allows control of a quite an impressive range of devices using the same interface. Examples, some of which have been discussed previously (e.g Parrot Minidrone or Dash and Dot), are shown below. 






















































    The App uses an graphical programming interface similar to Scratch or Blockly to produce code. The example here it a very simple one of:

    • Spin twice for one second;
    • Move roughly in a square;
    • If the BB-8 collides (or is bumped) it is set to spin twice for a second.  

    Ok, not the most sophisticated bit of coding; but it does demonstrates the simplicity of controlling this robot with the app. 

    Sphero BB-8 Droid is great fun, and with the head appearing to float over the body and face in the direction of movement it is hard resist. The video below shows it action.





     All opinions in this blog are the Author's and should not in any way be seen as reflecting the views of any organisation the Author has any association with.

    Thursday 10 September 2015

    Sphero Droid BB-8 on patrol




    Sorry not programming this time, but this is a great little toy. An App-control robot from Sphero based on the Star Wars new Sphero BB-8 Droid . The video shows it in patrol mode, which in the case of my one is either rolling under the chair or rolling around the room.



    One of the other parts of the app include an augmented reality option where on the tablet it appears to be projecting messages and videos (included ones you create).



    It is difficult to resist playing with this one.



    Top posts on this blog in March 2024

    The Top 10 viewed post on this blog in March 2024. Covering areas such as small robots, augmented reality, Scratch programming, robots. Micr...