Playing with Mindstorms NXT - Lejos firmware and Eclipse

November 6th, 2009 by Jens Wegar

Today I decided to finally replace the default firmware on my Lego Mindstorms NXT brick with a better one. Enter Lejos, afaik the de-facto replacement firmware to use. The project has done some major improvements the last 6 months (which was when I tried this the first time) and the documentation for setting things up worked as advertised.

I had my connection to the NXT brick up and running and the firmware flashed in a very short time using the Terminal (I use OS X 10.5 on a Macbook Pro). They even have an Eclipse plugin, which I immediately set out to install next. But here I ran into some gotcha’s. For some reason, I couldn’t get Eclipse to connect even though the connection worked through the Terminal. However, when I launched Eclipse through the Terminal it worked.

Long story short, the reason was that Eclipse when launched the default way (which is by clicking the icon in the dock) doesn’t recognize the same environment variables as the Terminal (which reads the ~/.profile file at startup). So I had to figure out a way to configure environmental variables for OS X GUI apps. This involves configuring an environment.plist file for your user profile. Luckily, I found the Environment Variable Preference Pane over on Apple downloads. Using this I could setup the same variables for OS X GUI apps that the Lejos install guide said to put in ~/.profile using the Terminal. Now I can compile and run my NXT code directly onto the NXT brick from Eclipse, without having to start Eclipse using some script voodoo or through Terminal.

Hello World has been done, now looking forward to something a bit more complicated (like reading sensor data through Merapi into an AIR app for display and analysis).

Share:
  • del.icio.us
  • Digg
  • Facebook
  • Google
  • StumbleUpon
  • Technorati
  • LinkedIn

Vote for a better compiler - now!

October 28th, 2009 by Jens Wegar

If you follow the industry news in any way, you’ve probably heard that something strange happened at FOTB09 this year. One of the speakers, Joa Ebert, thought it would be nice if the ActionScript compiler would be better at optimizing what us l33t coders throw at it, and so proceeded to prove that it was possible by creating TAAS (while being sick with the flu, I might add). People who saw Joa’s presentation liked this idea (/me was one of them). So much in fact that he got a standing ovation, as far as I know the only one at FOTB09. Well, I wanted to do my part in helping to spread the word, so I’m here to tell you that there is an issue opened in the Adobe bugbase by Andre Michelle, the sole purpose of which is to get Adobe to put some money into improving the compiler. So, head over to the bugbase and vote for the issue! Do it now, please.

Share:
  • del.icio.us
  • Digg
  • Facebook
  • Google
  • StumbleUpon
  • Technorati
  • LinkedIn

Productivity tips for Flash Builder

October 24th, 2009 by Jens Wegar

Scott Evans did a good talk at MAX this year on some less know (to me at least) features when using Flash Builder in your everyday programming. Small things such as Cmd+O (for a quick outline of your current class) or Cmd+3 (think Spotlight/Quicksilver for Eclipse) that can really boost performance once you get used to them. If you’re a keyboard geek, check out his presentation online.

Share:
  • del.icio.us
  • Digg
  • Facebook
  • Google
  • StumbleUpon
  • Technorati
  • LinkedIn

Flash on the beach 2009

September 23rd, 2009 by Jens Wegar

After having airport security show me a new trick regarding carry-on luggage, forgetting my MasterCard pin code, and nearly having my luggage be hauled off by an older lady when arriving in Brighton on Sunday, I was almost ready to give up on the trip. Luckily, Brighton is a very cool city to walk around in so I quickly forgot about my mishaps. Day 0, or Sunday was all about getting to know Brighton and by the end of the day I had a pretty good feel about where things are (at least as far as the central parts go). The cool stuff could begin.

To re-iterate everything that speakers said in their sessions would become a short novel, so I’m basically just going to say if you weren’t there, TOUGH. It was great and you are a fool for not being there. Of course some speakers were better than others, but in the end I think I got at least a little something out of every single person that opened their mouth in front of a mic. The basic lesson learned? In order to become great, you need to experiment, you need to try new things and you need to question old things.

Here’s the sessions I checked out with some notes:

Keynote

Nothing that special here except multi-screen thinking will be the next big thing, according to Adobe at least. They’re holding out until MAX, which is kind of interesting. Why do all announcements at one single event?

Mike Chambers - Advanced Desktop development with Adobe AIR

To be honest, Mike seemed a bit bored with keeping this session and he was basically plugging the as3corelib and features in it that will be obsolete with AIR 2.0.

Chuck Freedman - Visualizing voice: Using the Flash microphone for advanced interaction

I loved the energy of Chuck, you could see he’s really passionate about getting better mic support into Flash (although I was expecting some very cool visuals based on the session description). If you’d like that too, go to www.getmicrophone.com and/or vote for the feature.

Rob Chiu - Fear/Love

Showed a nice short film and the process that went behind creating it. Not Flash, but very inspirational.

Dr. Whoohoo - Cybernetic art revisited

This one left me a bit cold, mostly an artsy thing and a history lesson.

Hillman Curtis - Telling stories

Again, not much in it for me, but inspirational. A film maker talking about how he uses video portraits.

Inspire session with Joel Gethin Lewis - Epiphany

Talked about his background and what inspires him. This session really lived up to the title, in that it was very inspirational.

Elevator pitch - 20 people giving 3 minute talks

Some very good ones, some bad ones, some that have read too much about how to present. A nice session overall though.

Peter Elst - The secret life of a Flash freelancer

Got some verification that I’m doing the right things and some new ideas about how to do them. Educational, but a bit lecturish.

Joa Ebert - Leaving the sandbox

The only standing ovation I saw during the entire event. Basically, Joa said F you Adobe, I’m building my own tools and making them better than your’s. Hope Adobe notices this and improves their game.

Jer Thorp - Hacking the news room

Data visualization based on the Times API and the Guardian API. Interesting patterns, but not that much new stuff for me.

Karsten Schmidt - We make our own tools, and then they shape us

The talk was perhaps a bit dry but the content was interesting. Karsten has been involved in building a music generator for an art piece that over a period of 3 months never repeated itself. Impressive, ‘nough said. I think his basic message was that complex things are built out of simple things. Some things need to be complex, others don’t.

Contrast - Unconventional web applications

A lot of food for thought in this one. Why are we following conventions, when should we break them and when not? And the bottom line, if conventions are never broken then innovation stops. If you always do what others do, then you will always be behind. To get to the front, you need to innovate.

Inspire session with Craig Swann - Choose your own adventure

Life should not be about work, it should be about doing what drives you and other things will follow. Happy to realize that I’m at least partially on the way to achieving that.

Andre Michelle - Kling Klang

This guy makes sound seem simple. He also made me want to fire up my old tracker software and start doing music again. But perhaps I’ll work with Hobnox instead.

Mario Klingemann - Connecting the dots

Send an image over a tweet. Possible? Mario seems to think so and set out to proove it. Impressive stuff.

Seb Lee-Delisle - Work/Play

Tweening engines are bad, or so thinks Seb. Also, glowsticks and 3D-glasses for everyone. Seb showed us some cool stuff that he’s been working on. And I wonder if that girl finally realized that Seb actually wants to pay her parking ticket and is not a creepy English fellow.

(update: The girl was jennifer blackwell. If you know her, let her know Seb is real. Because she might think he’s stalking her, which he’s not… or so he says… )

Jam throwdown - 6 speakers, 10 minutes each

I feel sorry for the other speakers because their sessions were probably empty. A great session giving 6 of the best guys out there 10 minutes to impress us. I can’t pick a favorite because… well I can’t.

Jared Ficklin - Seeing sound - Sound visualization in Nature and Code

When a guy who looks like a hippie takes the stage with a plastic trash can, a smoke machine, a cardboard box and a plastic tube, you know it’s going to be great. And it was. Jared took us back to basic physics and got me wanting to build musical flame throwers.

Joshua Davis - Space

Talking about using Flash to generate art works. A very funny presentation and a nice wrap-up of the entire event. Basically again boiling down to if you don’t try new things, you are doomed to be a follower.

Share:
  • del.icio.us
  • Digg
  • Facebook
  • Google
  • StumbleUpon
  • Technorati
  • LinkedIn

Getting started with Merapi 0.1.8 beta

September 15th, 2009 by Jens Wegar

My previous Merapi tutorial is by far one of the most popular posts on this blog. It is however out of date by now since a new version of Merapi has been released. The previous tutorial was based on an Alpha release, while this tutorial is based on the 0.1.8 Beta release. The API between the alpha and beta has changed quite a bit, which is why I decided to write a new tutorial instead of simply updating the old one. This tutorial is aimed at beginners, but hopefully more seasoned coders will also find something useful in it.

So, on with the show. Since you’re reading this, I assume you at least know about Merapi. In case you don’t, head over to the Merapi site and read through the basics.

The app I built here is an extension of the application in the previous tutorial. We’re still looking at round trip times, but in order to show of Merapi’s capabilities to send more complex data, I’m also adding a basic byte packet and some memory usage information. The source code is well documented and should describe what the different parts do, so I won’t go into all the details of the code in this tutorial. I’ll just guide you through the setup and highlight some general things regarding Merapi instead.

The first part of this tutorial is all about setting up SVN access to get the Merapi source and setting up the tutorial source projects. If you just want some pointers on working with Merapi, feel free to jump directly to Notes on working with Merapi.

Prerequisites

To follow this tutorial, you’ll need the following:

  • Flash Builder 4 Beta 1 plugin for Eclipse installed and running (since we’ll be using the Flex 3.4 SDK you should be fine using Flex Builder 3 also) (download free trial from Adobe website)
  • The source files for this tutorial (download here). Contains Eclipse projects for both the Java and AIR project.
  • About 30 minutes to spare, and intially some patience

I’m assuming that you know your way around the Eclipse IDE and Flash builder. I also assume you’ve done at least some Hello world level applications in both Java and Flex and know the basics of debugging (Since Merapi is still beta software, you might run into some odd problems here and there). Having said that, if you do get stuck feel free to post your questions in the comments and I’ll try to help. Also, if you notice that someone has asked a question that you know the answer to, feel free to post the answer if I haven’t had a chance yet.

My Eclipse install is running on OS X 10.5, so if you run Windows you’ll need to adjust paths etc. to suit your environment. Also, as I said earlier, I’m using Flash builder 4 beta 1. You should be able to use Flex Builder 3 also, but some of the screen shots might look a bit different.

Getting the framework

I could have added the framework to the source package of the tutorial, but since it’s a beta project I’m thinking you’ll be better off knowing how to get the latest from the SVN repository instead so that you can keep up to date. So, the first step will be to setup Eclipse to fetch the Merapi source from the Merapi Google SVN repository.

Make sure you have the package explorer view visible in Eclipse (menu: Window->Show view->Package Explorer). Control-click (Win: right click) in an empty area of the Package Explorer and choose Import. Type SVN into the filter input or browse the options to find the Checkout Projects from SVN option. Choose it and click next.

Merapi source checkout 1

In the next screen, choose Create a new repository location and press Next. Paste the URL http://merapi.googlecode.com/svn/trunk/ into the location input field and press Next again.

Merapi source checkout 2

Eclipse will work a bit before asking you to choose a folder to checkout from SVN. Choose trunk/java/merapi-core and press Next.

Merapi source checkout 3

Eclipse again works a bit and should then present you with a view where you can choose the type of checkout. Set Check out as project configured using the New Project Wizard, leave everything else as default and press Finish. The New Project Wizard will open. Choose to create a new Java project, then click Next. Give the project a name (I set it to merapicore.java), set it to create new project in workspace and press Finish. Click ok if Eclipse warns you about overwriting some sources in the future. Eclipse will start to download the java source files from SVN.

Once the Java sources have been downloaded, Eclipse will moan about a whole bunch of errors in the source files. This is because we haven’t linked in the libs that are required by the source. Control-click (Win: right-click) on the Java project in the Package Explorer, open Java Build Path and the libraries tab. Click Add JARs, open up the merapicore.java/libs folder and select all *.jar references you see, then click OK. Your Java build path should look something like this:

Merapi core Java build path

Click ok and all the compiler errors should be gone.

Next, we’ll do the same for the Flex source files. Control-click on an empty area in the Package explorer, choose import, then Checkout Projects from SVN. In the Select location view the repository location we used for the Merapi Java project should exist, so you can choose it from the list and click next. In the select folder view, instead of choosing the java folder, choose flex/merapi-core and click Next. Again choose Check out as project configured using the New Project Wizard. In the New project wizard, choose to create a Flex library project and click Next. Give the project a name (I gave mine merapicore_flex (sidenote: someone please explain to me why library project names cannot contain dots) and set the Flex SDK to be 3.4. Leave the rest at default and choose Finish.

Once the sources have downloaded Eclipse will moan that nothing was selected to be included in the library. Control-click on the Flex project in the package, choose properties->Flex library build path and in the Classes tab put a check next to the src folder, then press ok. The error should be gone.

You now have two projects in your workspace that you can always use to get the latest version of Merapi onto your computer. Simply Control-click on the projects in the package explorer and choose Team->Synchronize with repository.

Import the tutorial source files

If you haven’t done so yet, download the tutorial source files zip. Then continue reading.

Open the Java perspective in the Eclipse IDE (Window->Open perspective->Java). Control-click an empty area in the Package Explorer and choose Import. In the Import dialog, choose Existing projects into workspace and press Next. In the Import projects dialog, choose Select archive file and browse to the zip file you downloaded. Once you’ve selected the zip and pressed open, your view should look like this:

merapistats-project-import

Press Finish.

Since the projects that you imported still have some of the settings from my workspace, we’re going to have to change that before the projects can compile. First Control-click the imported AIR project in the Package Explorer and choose properties->Flex Build path and open the Library tab. Select the libs folder and click Remove. Do the same for the merapicoreflex.swc. Click Add SWC, browse to the bin folder of the merapicore_flex project and choose the swc from there. Your properties should look like this:

MerapiStats AIR project build path

MerapiStats AIR project build path

Press ok and Eclipse should not give any errors on the AIR project anymore. Next right click on the MerapiStats.java project, choose properties->Java build path and the Source tab. Remove the source folder that points to MerapiStats.java/MerapiStats-core

merapistats-java-build-path-del

then click Link Source. Browse to the src folder in the merapicore.java project we downloaded from SVN. If you want you can give the folder a more descriptive name also. It should look something like this:

merapistats-java-link-source

Press Finish then open the Libraries tab. Remove all linked in *.jar resources except the JVM, then click Add JARs. These are the same steps as we did before when working with the Merapi java source project, so choose all *.jar resources in the merapicore.java/libs folder and press ok. Your build path should look like this:

MerapiStats java project build path

MerapiStats java project build path

Click Finish to close the properties panel.

Provided all went well, you should now be able to run the projects. The order however is important. You first need to start the Java application, then start the AIR application. Otherwise the AIR application will throw a security error eventually since it cannot connect to the Java application. So first, open the src->(default package) of the  MerapiStats.java project, Control-click the MerapiStatsRunner.java file and choose Debug As->Java Application. The console should output the following messages

log4j:WARN No appenders could be found for logger (merapi.Bridge).
log4j:WARN Please initialize the log4j system properly.
IntiMessageHandler created
PingMessageHandler created
Java runner initialized

Next, Control-click the MerapiStats.air project and choose Debug As->Desktop Application. If all goes well the AIR app starts and the TextArea is populated with the text Bridge connection established. Click the Start button and you should start to see lines drawn in the graphs as in the screen shot below:

Screen shot of MerapiStats AIR application

Screen shot of MerapiStats AIR application

Notes on working with Merapi

In order to start up the Merapi bridge on the Java side, you call

  1.  
  2. Bridge.open()

MessageHandler-objects are what you use to listen for data that is passed over the bridge (this goes for both the Java and the Flex code). You should extend the MessageHandler class to provide your own implementation of the handleMessage method. This is the method that gets called when a message is received by the handler. You register a MessageHandler to handle a message of a particular type by calling addMessageType() or by passing the type into the constructor of a MessageHandler object. One MessageHandler can register interest in several different types of messages. Simply call addMessageType() for each type of message that should be handled. How many MessageHandler classses you create is of course entirely up to you, but any complex project will probably require more than one.

You can think of Messages as being similar to Events in AS3. They both should be kept simple and they both act as data transfer objects or notify a listener that something has changed. Compared to the Events of AS3, a Message has one important difference, the send() method. This is what you use in order to send a message over the Merapi bridge. So basically all it takes to send a message over the bridge is to create an instance of a Message and call the myMessage.send() method. e.g.

var myMessage:MyCustomMessage = new MyCustomMessage(”myMessageType”);
  1. myMessage.send();

Then have a MessageHandler on the other side that has been registered to handle messages of type myMessageType.

Extend the Message class in order to add any custom data you want to transfer. Messages can contain complex data also and variable types are automatically converted to their corresponding type in both ends of the bridge.

Note that you never actually create an instance of a Bridge (as you did before when working with the Alpha of Merapi). It is all handled implicitly through MessageHandlers and Messages now.

That’s it for me, hope this tutorial was useful for you. If you have any questions or feedback, feel free to post a comment.

Additional resources:

Share:
  • del.icio.us
  • Digg
  • Facebook
  • Google
  • StumbleUpon
  • Technorati
  • LinkedIn