20 Jul 2010

There’s an updated version of the Arduino MQTT client available. This fixes a bug where if the client lost its connection, you had to explicitly call disconnect before you could reconnect.

Not a major issue, but one that had caught a few people out.

8 Jul 2010

As a follow-up to my last post on creating Joggler applications under Linux, I thought I would share what I’ve been doing with it.

At some point, I plan to get all of our CD’s onto the Viglen PC that’s sat behind the TV. When plugged into the hi-fi, it’ll make an ideal media box. It does lack one thing however; a nice UI for controlling it. This is where the Joggler can come in – and I’m not the only one to have considered it. I know others have got things like XMBC and Squeezebox running, but I wanted something that integrated better with the existing Joggler apps.

The basic idea will be to use mpd on the Viglen as a simple music server for which the Joggler will act as an client that sends commands to control the music playback.

The app will let us browse the music collection on there, pick an album/track, set up a playlist – all the usual things you’d expect.

Here’s a video of the app as it current exists running in the emulator. You can see me browse through the music, add a Coldplay album to the playlist, start playing the list, then removing tracks from the playlist. You’ll note there is no sound on this video… mostly because I’ve not yet done the connection to the server part; all the album/artist data is mocked up so I can develop locally.

Joggler Music App from Nicholas O'Leary on Vimeo.

Clearly there’s lots still to do to make it properly usable – but it has definitely been a useful way to learn more about ActionScript.

31 May 2010

I recently got an O2 Joggler as a cheap touch-screen device that is easily hacked to become a generally useful device. To run Ubuntu on it is as simple as plugging in a suitably installed USB drive. I haven’t decided what I want to do with the device yet, but I wanted to see what could be done with the original software.

Under the covers, it already runs Linux with the entire interface built in Flash. This makes it a challenge to develop for – Linux certainly isn’t overrun with Flash development tools. After some trial and error, I have figured out the basics. So herewith a beginners guide to developing Joggler applications under Linux.

Note, this is not intended to be a Flash or ActionScript tutorial – I am not an expert. Everything you see here I have worked out from scratch this week.

Installing dependencies

1. Install swftools.

$ sudo apt-get install swftools

This provides a number of useful tools for working with flash swf files. The key one for our purpose is as3compile – an ActionScript 3.0 compiler.

2. Install a standalone flash player. I use Adobe’s own – you can try one of the open-source alternatives if you want.

3. Register for, and download the SDK from OpenPeak. This includes a complete version of the framework that lets you debug and run on your laptop, rather than have to copy over to the Joggler each time. The docs pdf included with the SDK explains how to do this in the ‘Testing Applications’ section.

$ cd SDK/published/
SDK/published$ flashplayer openframe.swf

Creating a new application

1. Create a new application directory under the SDK directory.

$ mkdir SDK/published/apps/DemoApp

2. Add an entry for the application to applications.xml file – this tells the framework where to find the various pieces.

<app static="1" id="test" loc="./apps/DemoApp/"
          icon="icon.swf" app="main.swf" />

3. In the application directory, create a language.xml file. This contains all of the translatable text of your application. Even if you don’t plan to translate your application, you must still create this file with an entry for the name to display beneath the icon on the main menu.

<copy>
   <mm en="Demo App" />
</copy>

Creating icon.swf

The documentation specifies what the icon movie must consist of – a 100×100 movie with a button. After some experimentation, I’ve got a template ActionScript file that does the job. Copy the following into a file called icon.as within the application directory.

package {
    import flash.text.TextField ;
    import flash.text.TextFormat ;
    import flash.display.MovieClip;
    import flash.display.SimpleButton;
    import flash.display.Shape;
    import flash.filters.ColorMatrixFilter; 

    public dynamic class DemoIcon extends MovieClip  {
        public function DemoIcon() {
            // Create a button
            var button:SimpleButton = new SimpleButton();
            // Setup the various states of the button
            button.upState = new DemoIconButton();
            button.downState = new DemoIconButton();
            button.overState = button.upState;
            button.hitTestState = button.downState;
            // Add a fade to the down state of the button
            button.downState.filters = [(
                new ColorMatrixFilter([1, 0, 0, 0, 0,
                                       0, 1, 0, 0, 0,
                                       0, 0, 1, 0, 0,
                                       0, 0, 0, 0.7, 0]))];
            // Add the button to the stage
            button.x = 10;
            button.y = 10;
            addChild(button);
        }
    }

    class DemoIconButton extends Shape {
        public function DemoIconButton() {
            // Draw the button
            graphics.beginFill(0x996633);
            graphics.lineStyle(2,0xffffff);
            graphics.drawRoundRect(0, 0, 80, 80,20,20);
            graphics.endFill();
        }
    }
}

Next, compile it to the required swf file:

SDK/published/apps/DemoApp$ as3compile icon.as

If you launch the openframe now, you should see the icon in place.

As you can see, it isn’t the most exciting icon. But it does have a nice fade effect when pressed. To change what it looks like, you can play around with the DemoIconButton() method – with a little help from the reference on flash.display.graphics.

Creating main.swf

I’m still working out how best to approach writing the main application. There are some parts in the documentation that simply don’t work for me – this may well be a result of not using the official Flash development tools.

The docs say the main app needs to include a class that extends op.framework.OpenFrameApplication. I found importing this class, even without using it, made the app fail to launch. Not a great start. However, it seems to work without using this class.

Copy the following into a file called main.as within the application directory.

package
{
    import flash.display.MovieClip;
    import flash.display.*;
    import flash.text.*;

    public class DemoMain extends MovieClip {
        function DemoMain() {
            graphics.beginFill(0x000000);
            graphics.drawRect(0, 0, 800, 410);
            graphics.endFill();

            var textField = new TextField();
            var textFormat = new TextFormat();
            textFormat.font = "Arial";
            textFormat.size = 30;
            textFormat.color = 0xffffff;
            textFormat.bold = true;
            textField.defaultTextFormat = textFormat;
            textField.text = "Hello World!";
            textField.autoSize = TextFieldAutoSize.LEFT;
            var tm = textField.getLineMetrics(0);
            textField.x = 400-tm.width/2;
            textField.y = 200-tm.height/2;
            addChild(textField);
        }
    }
}

As before, compile it to the required swf file:

SDK/published/apps/DemoApp$ as3compile main.as

Using the op.* libraries

The framework includes a number of actionscript libraries to provide integration with the platform. They are provided as uncompiled actionscript files under the SDK/op directory. To compile against them, as3compile needs to know where they are. Assuming you’re still developing in the application directory created earlier, then the following does the job:

SDK/published/apps/DemoApp$ as3compile -I../../../ main.as

I have had mixed success using these libraries – here are some of my findings that may help you.. or not.

op.framework.OpenFrameApplication
As mentioned previously, simply importing this class is enough to stop things working.
op.framework.OPLang
This class provides access to the entries in language.xml file. When included, I get the following compile error for which I have yet to find a workaround:

op/framework/OPLang.as:80:39: error: can't convert type String to XMLList

This currently rules out using this class.

op.framework.OPLink
This class provides the main link between the application and the underlying framework. When included, I get the following compile error:

op/framework/OPLink.as:13:30: error: syntax error, unexpected *=

This is easily fixed by adding a space between the * and = in two lines of the library:

private static var apploc:* = null;
private static var so:* = null;
Anything that imports fl.*
It appears that whilst as3compile can handle references to the core flash.* packages, it knows nothing of the fl.* ones. Haven’t found a solution to this yet.

Running on the Joggler

You’ll need a means to copy over your newly developed application to the Joggler. Start by installing telnet, then ssh and finally scp.

The install process is the same as I described before; creating a directory for the application, followed by adding an entry to applications.xml. This all goes under /media/appshop. Once in place, you need to restart the software to pick up the new app:

$ killall tango

Conclusion

As you can see, it isn’t the smoothest experience. But with some perseverance, the end results ought to be worth it.

22 Apr 2010

It all started, as things do, with a tweet.

As part of the Emerging Technologies group at IBM Hursley, Kevin gets to play with new technologies to see how they might be useful to IBM’s customers. One such item is the Emotiv headset (an electroencephalograph if you must), which can read signals in the brain. You can train it to recognise particular thoughts which has some very interesting applications from gaming to rehabilitative care. You can find out more about the headset in this piece from The Times. But I digress.

The BBC were interested in finding out more about the headset and what sort of thing IBM had been doing with it. Knowing they were interested to see if a car could be controlled by the headset, Kevin was looking for something to make the demo more relevant, which led to his tweet.

With only a couple days to put something together, I suggested we go down the route of wiring up an existing radio controlled car to an Arduino. Kevin already had the headset hooked up to MQTT, so it would be trivial to use my arduino MQTT library to get them all talking.

A quick trip to Asda and I was the proud owner of a £9 blue Mini Cooper car, which I attacked with my soldering iron. It didn’t take much to get it working – I’ll blog the finer details of that bit soon.

The demo went well and we discussed more about what they wanted to do for the programme itself. Some of their ideas were ambitious to say the least. Someone mentioned the idea of driving a bus through Whitehall… not sure how serious that was. But ultimately, a straight race between two taxis ‘driven’ by the two presenters was decided on.

A couple weeks later, they were back in Hursley to film with Jem and Dallas. Now, there are some things that are best not left to the last minute. Such as realising they needed two radio controlled cars for filming – when I only had one. Luckily this dawned on me the day before they came down so I returned to Asda and got a shiny red sports car that would look good alongside the mini. I then discovered one of the reasons they were so cheap is that both worked on the same frequency… one remote drove both cars. With time running out, I went back and got a gaudy yellow jeep that was a completely different make and thankfully worked on a different frequency.

The cars

A couple of weeks later, Kevin and I headed up to a barn in middle-of-nowhere-Northamptonshire where Jem had been working on the taxis. Now, a few people have said to me “yeah, but he doesn’t really do the work does he?”, to which I have to reply that he very much does; Jem really knows what he is talking about when it comes to building things and the enthusiasm he portrays on screen is just what he’s like in real life.

Jem Stansfield

Over the course of two freezing days, we got the radio units hooked up to MQTT, again via an arduino. This was probably the piece I was most worried about – it was one thing to hack a toy remote control but it was going to be quite another to do the same to an industrial radio set that cost considerably more. Not to mention the fact that they were also on loan for the project, so breaking them would have not made me any friends.

In the workshop

We filmed the first test run and the relief was palpable when the car lurched forward thanks to Jem’s brain – not to mention the reaction when he managed to brake within a few inches of an oil drum. Although none of that made it into the final programme.

Mission Control

And then we had the main event – the race itself at the Santa Pod Raceway. 8am on a freezing December morning is not the best time to be trying to wire up the last few connections and try to debug why the damn thing wasn’t working. But somehow we got there and eventually the taxis did what they were thought to do – even if one did plow into the crash barrier at some considerable speed.

Dallas & Jem

The plan had been to do two races; a straight race and an obstacle course. Technical hiccups along the way meant it wasn’t until after lunch that we got the straight race filmed, at which point we were running out of light. It was decided to put Dallas in the back of a taxi and have Jem drive him around. This was the first proper test of steering by mind-control. Let’s just say I wouldn’t enter into a slalom race any time soon.

With all the filming done we packed up and headed home. Almost 5 months later, we got to see the end result on TV. Having spent the best part of 4 days filming, I was fascinated to see how they would edit it down to the 10 minutes or so they had to fill. I have to say I’m really please with the result. They may have given Kevin the speaking part out of the two of us, but I think I got more close ups. Given the target audience, I’m also not that surprised that they didn’t dwell on the finer details of the technology.

That said, I’m a proud geek that managed to get both my Ubuntu lanyard and an Arduino onto prime-time BBC One.

Arduino on BBC1

Me

Update: you can see the bits of the programme that featured the taxis here.

15 Apr 2010

After what was a quite stressful, cold, but ultimately highly enjoyable few days at the end of last year, I’m going to be on TV.


Can You Train Your Brain?

Wednesday, 21st April, 21:00 on BBC One

A Bang Goes the Theory special to help you improve your brain. The science team gives the results of the world’s biggest ever brain training experiment and reveals how you can make yourself smarter.

Resident extreme engineer, Jem, taps into his brain to drive a car with the power of thought alone.

I’ll save the full story until after it airs so I don’t spoil anything – but it should be good viewing.

older »