Home / Programming / NXC / Power Programming – Robotics in C

Power Programming – Robotics in C

Power Programming - Robotics in C I received my copy of John Hansen’s “Power Programming – Robotics in C”, second edition, a few weeks ago and I’ve read the whole thing. It’s a big book, a little over 540 pages, so it took me some time. 

One of the coolest thing I like about this book is that almost all of the models can be built with either the NXT 1.0 and the NXT 2.0 kit.  The only exception is the large robot arm at the end of the book.  However, a detailed list of additional parts that you need is available, including some parts that may be substituted.  I am sure that a skilled Lego builder would have no problems making a modified version of this arm.  Another nice touch is that all the currently supported platforms (Windows, Linux and OSX) are discussed and instructions on how to set up and program your robot are available for all three OSes.

Synopsis

Section I of the the book starts off gently, with a small introduction and a quickstart.  Chapters 2 and 3 discuss the hardware of the NXT such as the processor, and the way the brick can communicate with the world around it.  The motors and the standard sensors are discussed, how they work and how the brick can use them to gather information from them.  Chapter 3 briefly describes the function of the NXT’s firmware and how to interact with it through the menu.

Chapter 4 is a great help for people new to Technic Lego, also those who are migrating from the RCX platform and are not familiar with studless building techniques. There is a comprehensive list of the various Technic Lego pieces that come with the 1.0 and 2.0 kits as well as some additional ones, complete with their Peeron name!

Chapters 5 and 6 describe in great detail all the various aspects and workings of the BrixCC programming environment and the multitude of utilities that come with it.  Everything you ever wanted to know and more!  I’ve used BrixCC quite a bit in the past but I’ve also learned quite a few new handy tricks from these chapters.  Definitely don’t skim or skip over these chapters, no matter how familiar you may think you are with BrixCC.

Chapters 7 and 8 introduce you to the actual programming languages with which you can instruct your NXT.  What I thought was very cool was that not just NXC and NBC are discussed but also RICScript, a very nice language for drawing anything you like on the NXT’s screen.  RICScript programs can be embedded in your NXC programs with great ease and their contents displayed. Chapter 7 highlights the various programming concepts you’ll need to make your NXC programs.  The differences and similarities between NXC and its predecessor NQC are also outlined, another example of this book’s usefulness for those migrating from the RCX platform.  Chapter 8 is great for the hardcore programmer.  It covers advanced programming techniques using assembly (NBC).

Section II is where you will start doing some actual robot building and hone your programming skills.  In Chapter 9 you build the basic robot that you expand on in the following chapters.  Clear instructions with pictures tell you how to build it. 

Chapter 10 deals with the NXT’s basic outputs.  You add some extra bits to your robot and then it dives into some examples of programs that allow you to move the motors, make sounds and put stuff on the LCD screen using NXC and also NBC.  Chapter 11 is like 10 only this time it deals with all the basic inputs such as the sensors that come with your NXT kit.

Chapters 12 and 13 pick up where the previous chapters left off.  The inputs and outputs of the NXT are discussed in great detail.  The reading and writing of files, various 3rd party sensors and how to communicate with BlueTooth. Even how to talk to your own home made sensor via I2C is explained. 

In chapter 14 you get to make two cool games on your NXT, namely Tic-Tac-Toe and Pong.  A friend of mine made the Pong game into a small console-like setup which is one of the most popular models at Mindstorms demonstrations.

People with two NXT bricks will love the project in chapter 15; you get to build a remote control for the robot you built earlier.  It uses a feature called Direct Commands to control the robot via BlueTooth. 

The final project in chapter 16, the big robot arm, is by far the coolest and most bad-ass looking project in the book. Here you will learn about a very cool technique called Inverse Kinetics (IK) to control your robot’s movements. IK is also use in industrial robots to precisely calculate and control their movements. 

Conclusion

This is a great book and even if you’ve already been using NXC for a while, there is still a lot this book can teach you.  The projects are fun to do and look great.  If you’ve been using NXT-G for a while and are ready to take your programming skills to the next level, you’ll love the in-depth explanations of the various NXC language features.  If you’re a hard-core NXC programmer and want to optimise your robots with snippets of ASM (NBC), this book will show you how.

About Xander

Xander Soldaat is a Software Engineer and former Infrastructure Architect. He loves building and programming robots. He recently had the opportunity to turn his robotics hobby into his profession and has started working for Robomatter, the makers of ROBOTC and Robot Virtual Words.