Starting out programming in Blocky

First, what is Blockly?

Blockly is a simple programming language where people can learn the basics of programming without having to worry too much about syntax. It is especially ideal for kids who might not have the neccesary logical abilities or the patience to type long lines of code. If you wish to find out more about Blockly, click here. If you want to jump right into action, keep reading!

How to start?

The task of building a robot is a challenging one that involves advanced knowledge and applications ranging from STEM (Science, Technology, Engineering, Mathematics). There are various steps involved in building a robot especially if one plans to build it from scratch. One must have a pre-conceived idea about the kind of robot one wants to build. As robots are mechanical bots powered by electronic systems that are programmed for multi-tasking purposes, it is evidently important that the programming of the robot determines its capability to follow coded instructions and execute the desired task.

Programming a robot is a fairly daunting task. The programming tools like the Robot Operating System (ROS) have been designed and introduced for the purpose of simplifying the programming process. ROS mainly refers to the collection of software frameworks for robot software development. Therefore, as an expert robot programmer it is necessary to be familiar with the knowledge and use & functioning of the ROS. The basic idea behind ROS is to work around a certain set of code commands and instructions to direct the robot to perform the desired task. This accounts for the autonomous functioning of the robots.

However, with the growing popularity and application based use of robots, it is desirable that the users may have some idea of interacting and operating a robot. In the near future, robot operators may not necessarily have to have a background in software coding to operate a robot. Instead, there are efforts being made to popularize robotics by simplifying the process of robot programming.

Robot Blockly, a ROS package for programming robots, powered by Google’s Blockly library aims at doing exactly that.

Robot Blockly: A block based approach for programming Robots

In Robotics, coding is the language used as a medium of communication. Beginners can get started with blocky with a visual programming tool that allows you to create programs without the hassle of getting stuck with syntax rules. One good tool for this is Google Blocky as runs online and can generate Python code or JavaScript. This online tool is free and involves nothing more than having to drag a few jigsaw pieces over the screen.

With Blockly, you can also create cute minigames like this one.

Robot building and programming step-by-step

Step 1: To create your program, get on to the Google Blockly website and on the page, click on to the Text bar at the far left and then click on the Print Block which will appear on the screen. Click one more time and this time on the block at the top with “  ”.

Step 2: Next, drag the “ “ block to the right hand side of the text that reads ‘Print’ block and they shall join together. There will be an area with quotation marks on the “  “ block, click on that and type - Hello World! This is your first ever program created.

Step 3: There will be a white triangle on a red background icon right at the top of the screen; Click on that. The program you just created will announce ‘Hello World!’. This is the most basic of programming but one can slowly progress towards making bigger and more complex programs once they get the hang of Blocky.

Step 4: Now you can try and create another program with the ‘Item’ block instead of the “ “ block. Run this program and it will read “undefined” as the item is a variable, which means an area of memory. This is undefined.

Step 5: We can use the term ‘Set Item To’ block, under variables, to define it and then drag a “ “ block into the hole in the block. Type ‘Hello World!’ in between the quotation marks and you will find that the program works the same way as the first program we created.

Step 6: This step may appear complicated to you initially but it will get easier. The variable ‘Item’ shows up as a form of greeting to you by name. It is important to note that one can have lots of variables with each having different names by means of changing the word Item.

Step 7: We can try with arithmetic as well. There are quite a few relevant blocks under Math. Create the program using those books and it will show you how to calculate the correct answer. You can try and modify the simple programs to achieve more complicated calculations and solutions. We can move on to create several results from just the one program.

Step 8: One can generate a program containing a common programming concept known as a loop. Everything inside of the loop is carried forward for all value of the variable i from 1 to 10. You can run it to print the five times table.

Step 9: One can even create loops inside other loops. By modifying the program and making it use two variables, i and j, you will notice that it can now print out the values of all the multiplications starting from 1 x 1 to 10 x 10.

Step 10: Another very common feature of programming is the decision with regards to which instructions to execute next depending on the outcome of a comparison. For that create the program and try it out. Supply positive and negative numbers and zero when you are prompted to do so. You will need to click on the ‘*’ to add the Else if and Else parts respectively.

It is fair to say that these are the simplest of Blocky program examples that I have provided here. One can get an idea about how Blocky works from this and build on that knowledge to create bigger, better and complicated programs to achieve solutions to complex issues.