Szymon Kobalczyk's Blog

A Developer's Notebook

  Home  |   Contact  |   Syndication    |   Login
  101 Posts | 6 Stories | 291 Comments | 369 Trackbacks

News

Spotkasz mnie na CodeCamp'09 View Szymon Kobalczyk's profile on LinkedIn

Twitter












Article Categories

Archives

Post Categories

Blogs I Read

Tools I Use

Friday, February 26, 2010 #

After seeing that some of my friends get fancy customized pictures for their Facebook and Twitter profiles I thought it would be cool to get one too. But not for me – for my wife. You see, she currently works as IT Security Officer (the best I know btw.) but earlier when she started as security auditor and she worked as part of the “tiger team”, she often said she wants her picture like the movie poster from "Men in Black”. So this is what I had in mind:

Menin_Black

Given the upcoming Valentine’s Day it occurred to me this could be the perfect gift (you see it gets hard over time in marriage to came up with something unique). But instead of going to websites that offer such service, I filled the job opening on oDesk.com (freelance job exchange – highly recommended). Couple days later I got handful of candidates to choose from. In the end I choose the graphics artist from Thailand, Mr. Wanchana Intrasombat (or Vic for short). After seeing Vic’s profile and gallery (and this picture in particular) I was sure this is the style I’m looking for and that he is the perfect guy for the job.

In the end I can say that you can’t go wrong with Vic. He made truly exceptional job, and working with him was fascinating experience on its own. He was very open to my ideas and quick to accommodate them (even when I changed my mind several times in the process).

So here is the final picture:

Avatar of Asia -final version

And here is another sketch he made just for fun of it:

Asia standing

Go check out Vic’s gallery – he has tons of good stuff there. If you need a great graphics artist or just want to get your own avatar feel free to contact him: vic__unforce (at) hotmail (dot) com

And tell us what you think about the pictures!


Thursday, February 25, 2010 #

Yesterday I picked up a nice package from TinyCLR.com. Yes, it is yet another robot (third in fact), but this time it runs .NET! How freaking cool is that!

FEZ Mini Robot Kit

This robot is controlled by FEZ Mini board that runs .NET Micro Framework. What’s interesting is that this board has pin-out compatible with Basic Stamp from Parallax. You can also uses it easily on a breadboard for prototyping (just like Boarduino). TinyCLR.com also offers a larger board called FEZ Domino that has pin-out compatible with Arduino so you can use your existing shields. It is more expensive but notice that this board already includes microSD card reader and USB host connector. Both boards are based on USBizi chipset from GHI Electronics that in turns runs on 72Mhz NXP ARM processor.

FEZ MiniFEZ Domino

But the huge thing for me is that I can program this robot in Visual Studio and benefit from all the debugging goodies (breakpoints, variable inspection, stepping, etc.).

The robot kit itself comes from INEX Robotics – company that makes many interesting educational kits for robotics and electronics. Over there the robot kit is called POP-BOT and only difference is that it is controlled by Arduino compatible board. But you can also download the POP-BOT Manual that has 130 pages of many cool project ideas (line tracking, object avoiding, controlling servo motor, and serial LCD). I’m sure it will be lots of fun converting these projects to .NET Micro Framework.

FEZ Mini Robot

Two reflective sensors are included in the kit (useful for line following and edge detection projects), and you can order additional components both from TinyCLR.com and other robotics sites. Many construction parts are included in the kit so it is very easy to attach additional sensors or other parts. As you can see on the picture above, I already added a Sharp IR distance sensor in front (so I can teach the robot to not bump on walls). I also added an Xbee expansion board on the back so one day I can control the robot remotely (and my Holy Grail is to connect the robot to Microsoft Robotics Developer Studio).

Here is a video of the robot running the default program:

And here is my little robot builder crew at work:

Antoś builds a robot

Of course both FEZ Mini and FEZ Domino boards can be used not only for robotics, but also in many different applications. Go to the TinyCLR.com website and check out the Projects tab. For quick introduction to .NET MF you should also download the Beginners Guide to C# and .NET Micro Framework, free ebook from Gus Issa.

In my previous post I complained how upset I’m that there is no cheap .NET Micro Framework hardware for hobbyists. Now I can take it back. IMHO we finally have a very powerful alternative to Arduino and similar platforms, with the price that won’t break the bank (especially with FEZ Mini).


Monday, January 04, 2010 #

Just after finishing my multicolor RGB controller shield for Arduino, I came across Fritzing, a program that lets you convert your breadboard prototypes into a physical PCB. Since I got one design working at hand, I decided to give it a try. The process is very straightforward.

First you simply put all the components in the breadboard view. The parts library contains most common parts, and you use wires to connect them – exactly the same as you would do on your physical prototype:

Fritzing - Breadboard viewNext you can switch to schematic view where you can check if all the connections are correct:

Fritzing - schematic viewFinally you go to the PCB view and layout your parts on the board. Then you need to route all traces, and while Fritzing does quite a good job with auto-routing, it is worth to spend some time and review the design. In my case I was able to eliminate all the jumper wires – needed otherwise because currently Fritzing supports only single-sided PCBs.

Fritzing - PCB view In my case I designed the board to fit as an Arduino shield. As you can see it consists of a 12V voltage regulator circuit for external power source and ULN2003 converter to drive two RGB outputs.

After you are happy with you can save it in multiple output formats. For me the the etchable PDF format was especially handy because I could print it as a paper prototype and check if all the physical parts will fit properly.

Fritzing also offers a website where you can upload your projects along with any additional documentation, images, and source code. You can find my project page here: http://fritzing.org/projects/multicolor-rgb-led-controller-shield-for-arduino/

On top of that, starting with January 2010 they start a Fritzing Fab Service, and produce the real, physical PCBs. In preparation for this, they selected 24 projects and made them manufactured. I was very happy that my design was selected as one of these projects.

I got my board short after Christmas, and it looks very professional (at least for me :-)):

And here is the final product:

P1150499

As a geek I always wanted to hack the hardware like this, but at the same time I was intimidated by my little knowledge of electronics. So its truly  amazing how much can be done with such simple tools, and how much I learned in past half a year since my good friend Marcin Książek introduced me to Arduino. For me it’s just the essence of the Arduino phenomen – perfect combination of open source hardware, software and the community.

On the side note, I’m bit upset that the same didn’t happened with the .NET Micro Framework, because I think on the software side it has even greater potential (like you can write and debug your code in Visual Studio you know and love). And although I think making the platform open source is a great move, the hardware costs are the biggest barrier right now. Especially if you consider using it for few hobby projects (I don’t know what’s the pricing looks like for mass production).

I will be exploring .NET Micro Framework shortly so stay tuned.


Saturday, January 02, 2010 #

For me one of the coolest new features added in Silverlight 4 is support for capturing video and audio using webcams and microphone. As we’ve seen during Scott Guthrie’s keynote demonstration it is now possible to capture image frames from video stream and apply some interesting effects to it. On top of that we can even process the video and audio streams directly on the client (i.e. inside the browser).

Because Silverlight 4 Beta was already available at PDC I could try the webcam support right away, and so I jumped to refresh my computer vision projects. Unfortunately I never did find time to finish this but I think it’s still worth publishing the code as it is.

One things I was playing with before was the Touchless SDK. It is an open source .NET library for visual object tracking created by Mike Wasserman. In short it identifies objects with specific color characteristics and sends you their position within the image scene enabling to use these objects as input devices. It means you can control your applications without touching the screen or keyboard (and thus it’s called touchless :-)

Original project page is here: http://touchless.codeplex.com/

Touchless SL

Over a year ago I successfully used this library in WPF so now it was quite easy to convert it again to Silverlight 4. You can check it out and download the source code on the demo page. Below I summarize some notes of things I learned about Silverlight 4 API in hopes that Silverlight team can address these issues before final release.

As a starting point I used this excellent summary by Mike Taulty. The main class that handles video processing is the CameraTracker. It extends from VideoSink in order to get access to incoming video samples. Each sample frame is represented by byte array which format is specified by VideoFormat structure. In order to get current VideoFormat you have to override the OnFormatChange method (call to videoSource.VideoCaptureDevice.DesiredFormat will throw exception).

I learned that although VideoFormat specifies the PixelFormatType, currently it is an enum with only two values: Format32bppArgb and Unspecified. It’s WPF counterpart – PixelFormat structure - offers much more including masks and bytes per pixel. And instead of enum we get a static PixelFormats class with number of common formats declared as properties. I hope this will be changed in Silverlight 4 RTM.

Another thing to be aware of is that the video frame buffer is flipped vertically – so you need to read the image lines from bottom to top. I handle this in the GetPixel and SetPixel methods of RawBitmapAdapter helper class:

public RgbColor GetPixel(int x, int y)
{
    int p = _scan0 + (y * _stride) + (x * _bytesPerPixel);
    byte b = _imageData[p];
    byte g = _imageData[p+1];
    byte r = _imageData[p+2];
    return new RgbColor(r, g, b);
}
public void SetPixel(int x, int y, RgbColor color)
{
    int p = _scan0 + (y * _stride) + (x * _bytesPerPixel);
    _imageData[p] = color.Blu;
    _imageData[p+1] = color.Grn;
    _imageData[p+2] = color.Red;
}

In both cases I first calc the offset of pixel in the byte buffer using the scan0 and stride values. Stride is specified in VideoFormat but we have to guess the scan0 value (it specifies the offset of the first line):

if (_stride < 0)
    _scan0 = -_stride * (_height - 1);

Would be helpful the get it in the VideoFormat too. One last comment regarding VideoFormat is I think it’s constructor should be made public.

Before initializing the camera app displays a list of available devices. I tried to bind the collections from my ViewModel however it turns out that calls to GetAvailableVideoCaptureDevices and GetDefaultVideoCaptureDevice return different instances of CaptureDevice so you can’t do something like this:

CaptureDevices = CaptureDeviceConfiguration.GetAvailableVideoCaptureDevices(); 
SelectedCaptureDevice = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();

Also I noticed that none of the devices returned by GetAvailableVideoCaptureDevices has IsDefaultDevice flag set, so I had to use FriendlyName to match it.

Because CaptureSource is used in similar way to MediaElement I think it should expose similar API. In particular it would be helpful to get events when it state changes. We should also get some notification when camera is connected or disconnected.

In order to show the markers recognized by Touchless I paint these areas on an overlay. In current version I tried to implement this using a custom MediaStreamSource with double buffering as demonstrated by Pete Brown. It works but you can see the overlay lags significantly in respect to camera video. So I’m going to switch back to WriteableBitmap instead, but I’m not sure how it will perform either. In particular I’m concerned that WriteableBitmap doesn’t have a way to indicate that we are going to begin updating the buffer. In the WPF version you first need to issue Lock to get access to the BackBuffer. I was bit surprised that it’s not required in Silverlight version and I’m concerned how efficient it is without it. 

Altogether the camera API looks very promising and definitively opens many possibilities. However I think the most common scenario people will be trying to implement will be some sort of online IM client, and for this we would also need some generic video codecs for streaming. Right now Silverlight doesn't even have codecs for Jpeg/PNG images so I think it should be added in the first place. In the meantime you can try to use these as an alternative: http://imagetools.codeplex.com/ Updated: Please see this great post by Rene Shulte on saving webcam snapshots to JPEG using FJCore library.

Last thing, unrelated to camera API, is regarding support for commands that was also added in Silverlight 4. I found that the command CanExecute method won’t be required automatically on user input as it happens in WPF so you need to manually send CanExecuteChanged event for each command.


Friday, November 27, 2009 #

I’ve came across this interesting thread on Arduino forum about using IKEA DIODER and other RGB LED strips to build mood/ambient light. This allows you to create the same effect that you can now find on some TVs. I thought it would be a fun little project to do, and here is a short clip to show you the result:

In case you would like to build it yourself here is how I did it.

The Hardware

To get multicolor LEDs some people are hacking IKEA DIODERs but it’s quite expensive, so I followed the advice found here and ordered two RGB Multicolored 1-Meter LED strips from DealExtreme. Those are flexible plastics strips with 30 multicolor LEDs on each (you can also get it as a bar). It has 4 wires with +12V common anode and separate cathodes for RGB channels.

To control the lights I adopted the circuit shown in Markus post. I put it together on Adafruit’s Proto Shield for Arduino (which is nice because it had the IC pattern for the chip). 

P1140742

Instead of multiple transistors this circuit uses the ULN2003 chip, so that each PWM pin from Arduino is connected to one side of the chip and the RGB channels from LEDs are connected to the other side. Because LEDs require 12V voltage there is a separate power connector (Arduino is still powered from USB). Since I had only a 16V power supply I’m also using a 12V voltage regulator. Next to it I have a push switch to turn the LEDs on/off quickly. The 10K potentiometer on the other side is used to select color hue for one of the manual modes. One push button is wired to Arduino reset pin, and the other is used to switch modes.

I know it could be made prettier but I yet have to learn how to design and produce a custom PCB (please contact me if you’d like to help). If you don’t want to solder this yourself here are some other alternatives that you might consider:

For initial testing I used the Arduino sketch written by Markus. It has three modes: specific color selected by a potentiometer, pulsate the specified color, and smooth transition between random colors. You can find more details in his post.

The Software

Of course it would be hard to get ambient light working for every video source you feed to your TV, but its lot easier to do it when signal is going through a PC. This summer I build a new HTPC based on a Zotac ION-ITX board (cause its super small and quiet). Recently I ditched Windows 7 Media Center in favor of open source XBMC, mostly to get hardware accelerated VDAUP playback. Here are the steps to run it on a minimal Ubuntu install (but I admit I took me three days to figure out how to do it properly).

Apart from the video player we also need additional piece of software that will constantly sample the image visible on screen and produce average color for each LED strip. Thankfully there are existing programs that can do this for us. One of them is called Boblight and turns out to work quite well both in Windows and Linux (but again you get a little speed boost on the later).

In essence Boblight runs in backgrounds, accepts color input from clients and converts them to commands that it sends to the devices. I have to say I was pleasantly surprised to see how flexible it is, and how easy it was to configure it for my setup. You can find more details on the configuration on this page, and my config file is included in the download below.

The final piece is the code running on the Arduino that will translate these commands to corresponding light levels for each channel. Boblight uses a simple serial protocol called LTBL (Let There Be Light) that is described here. In the download you will find my sketch that handles this communication.

Currently I have Boblight setup to automatically start before XBMC loads so it will turn on the lights on startup (some advice can be found here). This setup serves me well, but as I said Boblight runs Windows too. And you can also try other software like Momolight, AtmoLightVLC Media Player, and other projects found at Ambilight4PC.


Wednesday, October 28, 2009 #

Now that .NET Framework 4.0 Beta 2 is out let’s look again what is available for building multi-touch application in WPF. In Beta 1 we got only a preview of manipulation and inertia components. With Beta 2 we finally get access to whole touch input system, and it looks very close to what was shown on PDC last year. Here is an overview from MSDN:

Elements in WPF now accept touch input. The UIElement, and UIElement3D, and ContentElement classes expose events that occur when a user touches an element on a touch-enabled screen. The following events are defined on UIElement and respond to touch input. Note that these events are also defined on UIElement3D and ContentElement.

In addition to the touch events, the UIElement supports manipulation. A manipulation is interpreted to scale, rotate, or translate the UIElement. For example, a photo viewing application might allow users to move, zoom, resize, and rotate a photo by touching the computer screen over the photo. The following events have been added to UIElement:

To enable manipulation, set the IsManipulationEnabled to true.

This is exactly what we were waiting for. I started playing with this new API and I will try to share some samples soon. But here is one problem I run into already. When I tried to use touch in ordinary WPF application, I noticed that all Buttons have a weird behavior, so that when I touched the Button it didn’t go into a pressed state immediately (I’m testing this on HP TouchSmart). Instead it only fires the Click event when I lift the finger. Testing it more I noticed that on any UIElement it won’t fire the MouseDown event until I lift the finger or slide it quite a bit.

To help me diagnose this issue I created a simple test application shown here:

multitouchtest

From left to right I have gray rectangles that react to input events from mouse, stylus and touch. Each rectangle will change color to orange when mouse or stylus is over, and to green when is pressed. In addition, on press I capture the appropriate device and during capture the border changes color to red.

This test confirms that when I use touch panel then the xxxDown events don’t arrive immediately regardless of the device used. I spent quite a while trying to figure it out and trying various settings in both the Touch and Pen Control Panel and the NextWindow’s USB Config utility.

Finally I noticed that somehow this works perfectly fine when I use manipulations. From this I quickly found that this problem goes away when you set IsManipulationEnabled property on the element. Turns out that the side effect of setting this property to true is also changing the stylus properties to disable PressAndHold and Flicks gestures on the element. This explains this problem because stylus engine has to postpone these events trying to interpret the gestures. You can see the difference by selecting the appropriate checkbox on the window.

However although now we get the xxxDown events immediately (which will be very useful for manipulations) this doesn’t fix the problem with Button pressed state. You will notice that MouseDown event is still deferred regardless of the IsManipulationEnabled settings. I believe that in this case this might be caused by input logic in Windows itself. In fact the only way I could affect this was to force the touch panel to report input as mouse events (using NextWindow’s USB Config tool).

In the end I believe the proper fix for this would require extending all WPF built-in controls so that they understand the touch events and react accordingly. At the same time some controls might get some multi-touch specific behaviors as well. For example it was already announced that ScrollViewer will be enhanced to support multi-touch panning. In case of Button it was mentioned several times, that when simultaneous touches occur the correct behavior should be to fire the Click event only after the last touch is lifted. I hope that we get some of these enhancements in the RTM timeframe.

You can download the sample code here.


Monday, July 06, 2009 #

Last Friday I’ve received new Futaba S3001 servos. Turns out they are more easier to modify to Hitec’s, and at the same seem more reliable. I’ve simply followed this Instructable, and you can also find some additional photos in my gallery. What most important the servos are also easier to calibrate, so now my SERB will actually stop in place when I want it.

Below is a short video of the completed SERB robot where it just runs in random directions:

This weekend I’ve also started looking at Microsoft Robotics Development Studio 2008. This environment promises easy entry level to robotics. However this is true only when you have a compatible robotics platform (like Lego Mindstorms NXT, fishertechnik, iRobot and few others). There are pretty good tutorials on how to control these robots both from C# and from VPL. However before I can apply them to my SERB robot, first I need to implement the hardware interface and generic services to control the robot. Not much information on this and closest what I found so for is the Robotics Tutorial 6 – Remotely Connected Robots. It would be cool to get more detailed example on writing such services, but fortunately source code of services for other robots is included. In particular I’m trying to understand the code for iRobot and this additional service for VEX Robotics. If you know of any other good examples or tutorials please let me know.


Thursday, July 02, 2009 #

Few weeks ego we went to an exhibition in one of Kraków’s malls to celebrate the 100 year anniversary of robotics. Besides some nice exhibits there was also a place where kids could try to build a robot from Lego Mindstorms NXT and Fishertechnik sets. We spent few hours there with my older son Jaś and even managed to build a walking robot.

It was fun for both of us so I started looking if we could continue playing with robots at home. Unfortunately most of the sets I found are pretty expensive (starting at $200). This is where my good pal Marcin Książek turned me to the Arduino electronic prototyping platform.

Arduino is really a simple and cheap microcontroller kit that can be easily connected to a PC and programmed. What makes it fun is that there are also many extensions that come as “shields” and adapters for the board and add capabilities such as XBee and Ethernet communication, accelerometer, DC motor control, GPS or even a touch LCD. The platform is open source so there are tons of information and fun projects on the web. Good place to start would be the Arduino Experimentation Kit (ARDX) – you can buy the kit from oomlout, but it’s also open source so you can download all guides and buy the parts in your local electronics store yourself. I also enjoy reading the book “Getting started with Arduino” by Massimo Banzi. And make sure to send the Arduino gift guide to your relatives. There are even Arduino user groups such as Howduino in Liverpool.

[In Poland you can buy Arduino from Nettigo]

All of this makes Arduino a great basis for building a simple robot. And in fact there is already a project on Instructables that shows exactly How to build a Arduino Controlled Servo Robot. Again this project is open source so you can buy a kit from oomlout or download the blueprints and find all the parts yourself. The body of the robot is done from acrylic sheets and I found a local shop with a laser cutter that could cut the parts for me. Most of the other parts can be easily found in your local DIY store.

One exception are the servo motors. Normal servos for RC models are constrained to movement in 180 degrees range, but what we need here is a “Continuous Rotation” servo. You can get one that was pre-modified such as Parallax, GWS S35 or Hitec HSR-1425CR. Another option is to modify the servo yourself, and there are also many instructions on how to do it on the web. I found that it’s really not hard to do, but you have to work a bit on the calibration.

So having all the parts I could finally begin the assembly. Below you can see is a photo gallery where we build our first SERB robot. As you can see I’m one happy geek dad, because both kids were pretty interested with this.

Right now the robot can’t do much besides running around in random directions, but I have some plans to make it smarter.

  1. Add remote control via Xbox pad or WiiMote. There is already a project showing how to use a netbook to control the robot via Skype. But being a .NET geek I would like to use Microsoft Robotics Studio for this.
  2. Add wireless connection with XBee so that robot can roam freely without cables the but still being controlled from the PC.
  3. Add some sensors so the robot gets more information from the world. I think first I would add bumpers to detect obstacles as shown in this project. Later I might also add wheel encoders (such as Nubotics WheelWatcher) for odometry.
  4. Play with some AI algorithms.

So it looks like I already have found myself a summer project :-)


Wednesday, June 17, 2009 #

Glenn Block TourNext week several .NET User Groups in Poland will host a special guest - Glenn Block, Program Manager in the .NET FX team (and previously PM for p&p “Prism”). As you probably already know, Glenn is the man behind the Managed Extensibility Framework (MEF) project and thus this will be the main topic of his talks:

Building openly extensible applications in .NET 4.0

Are you tired of building monolithic style apps? Are you tired of hacking your app to bits to meet just one more requirement. Do you want to enable third parties to provide add-on value to your apps? 

If the answer to any of these is yes, then come learn about the new Managed Extensibility Framework which ships in .NET 4.0. 

Applications built on MEF dynamically discover and compose available components at runtime. This makes MEF ideal for third-party extensibility scenarios, where the type and number of extensions are undefined. With MEF you can enable customers and third-parties to take your apps where no man has gone before.

During the tour Glenn will visit following cities:

You can register for the meeting in the city near you by clicking on the links above. More information on the official website. Also visit Glenn’s blog and leave him a comment if you like to hear about any particular topic.


Monday, April 27, 2009 #

Wczoraj zakończyła się rejestracja do konkursu o tytuł Speaker Idol 2009, a zatem znamy już nazwiska siedmiu śmiałków którzy zmierzą się ze sobą w środowy wieczór. Oto oni:

  1. Marcin Kruszyński – Innowacje w Silverlight 3
  2. Michał Brzozowski – Zasada „SOLID”
  3. Wiesław Nizio – Microsoft Excel i Windows Forms. Co wybrać Ole Automation, czy OleDb?
  4. Jakub Malinowski – CRUD UI dla danych w .Net
  5. Krystian Czepiel – Wykorzystanie Modelu MVC przy tworzeniu aplikacji ASP.NET
  6. Łukasz Podolak – Software Craftsmanship
  7. Arkadiusz Beer – Pex: Zautomatyzowane generatory testów

Już teraz możecie się zapoznać z tematami ich prezentacji opublikowanymi na stronie konkursu

Serdecznie zapraszamy na spotkanie – wieczór zapowiada się naprawdę interesująco!