in

WPF Design and Development

IdentityMine Team Blogs

David Kelley

A day in the life of a humble software architect... doing C#, WPF, Silverlight, Legos, Fuzzy Logic AI and/or whatever is the latest and greatest or more importantly the coolest techo mumbo jumbo...

August 2006 - Posts

  • Cool SQL 2005 Features...

    The T-SQL Language implemented in SQL Server 2005 has been enhanced to provide more power and flexibility. For example you have new key words like PIVOT and UNPIVOT. With these you can now do cross tab queries or ‘Pivot Tables’ right in SQL. One of the things can was difficult todo at the database level was doing pivot tables and users have been doing them in other applications from extracts. Now you don’t need todo that any more.

    Here is a sample of using SQL Pivot tables:

    First we will use the Adventure works db with the following:

    USE AdventureWorks
    GO
    
    CREATE TABLE MonthlyPurchaseOrders
    (VendorID int NOT NULL,
    OrderMonth int NOT NULL,
    SubTotal money NOT NULL)
    GO

    and then insert some data with:
    INSERT MonthlyPurchaseOrders
    SELECT 
       VendorID, 
       DATEPART(m, OrderDate), 
       SubTotal
    From Purchasing.PurchaseOrderHeader
    WHERE VendorID IN (3,4,5,6,7,8,9)
    GO
    

    Now to actually do something open a new query window and run this code:
    SELECT * From MonthlyPurchaseOrders
    PIVOT (SUM(SubTotal) FOR OrderMonth In (
    [1],[2],[3],[4],[5],[6],
    [7],[8],[9],[10],[11],[12])) As X
    

    Its fairly simple SQL but for those family with reporting and data warehouses and the like this kind of functionality allows us to keep data processing as close to the data as possible which as we ALL know is the most effective way to process data.

    PIVOT and UNPIVOT allow us to really get more effective information out of our data really enhancing Business Intelligence with two key words.

    Ok, so PIVOT and UNPIVOT are cool and IT departments will get excited over that, but lets throw a bone to our developers. For YEARS, developers have asked for one single set of key words in SQL. EVERY OTHER LANGUAGE on the market supports them but until now T-SQL has been um… ‘lacking’.

    So with SQL Server 2005 we now have 'TRY... CATCHS...'

    You might say, 'What is the big deal?'

    Well, the big deal is the reason all the software running on your PC just doesn’t blow up every time you blow on it

    AND the same reason a server can be made to be reasonably stable.

    The 'TRY.. CATCH...' construct allow a developer to have a bit of code try to execute that they are not sure is going to work

    And if it doesn’t work the computer just doesn't freeze and lock up, but is able to recover and do something else. Without 'TRY...CATCH...' one little mishap and the whole thing goes to $#!&*.

    Seriously let's try some sample code. In this example the try block attempts to delete a record from the Sales.SalesPerson table in the ‘AdventureWorks’ sample database.

    USE AdventureWorks
    GO
    BEGIN TRY
        -- Generate a constraint violation error.
       DELETE Sales.SalesPerson WHERE SalesPersonID=275
    END TRY
    BEGIN CATCH
        SELECT 
       ERROR_NUMBER() AS ErrNum,
          ERROR_SEVERITY() AS ErrSev,
          ERROR_STATE() as ErrSt,
          ERROR_MESSAGE() as ErrMsg;
    END CATCH
    GO
    

    When the code executes SQL Server will find a reference constraint and the delete fails. The catch block will execute and we get a select showing us the error information regarding the error that occurred.

    Simple but this really makes Developers jobs easier when writing T-SQL.

    Additions like the TRY/CATCH and PIVOT and UNPIVOT provide more flexibility and control to help DBAs and Developers in building better database code.

  • Robotics Design Patterns

    For now I'm going to use the following layout for design patterns with the MS robotics environment. Now don't get to excited. I haven't worked out really any details, this is just a start...

    Title: Component/Part/Object
    Problem Space: BaseLine
    Abstract: All Windows/Legos Based robotic systems are derived from this pattern. Given the current state of the world you can't get around it.
    Context: Microsoft Windows.NET, Microsoft Robotics API's, Lego NXT, Bluetooth
    Known Uses: all
    Related Patterns: all

    Title: The Navigable System
    Problem Space: Navigation
    Abstract: Derived from Component/Part/Object this patterns address the abiltiy for a robot to move around in 2 or 3d space.
    Context: Microsoft Windows.NET, Microsoft Robotics API's, Lego NXT, Bluetooth
    Known Uses: Manuvering in a given area some kind of robot
    Related Patterns: Component/Part/Object

    Title: The Stationary Device
    Abstract: Derived from Component/Part/Object this patterns address the abiltiy for a robot preform a given action.
    Problem Space: The Machine
    Context: Microsoft Windows.NET, Microsoft Robotics API's, Lego NXT, Bluetooth
    Known Uses: Preforming actions, such as building or a repetitive action.
    Related Patterns: Component/Part/Object

    So regarding problem spaces I feel that there are others but for now I'll deal with these. So I have built robots as seen in earlier entries for the first 2 patterns and now I am focusing on the last one. The robot I built was a automated gun emplacement. In the processing of building this one I also learned more about the lego IDE including how to keep the robot from timing out and how to use variables and other complex 'lego' programming components. For the most part you can do anything you want but things to keep in mind are how variables are used and how they have to be wired up separately and you need different blocks for read, write and comparison operations. And all variables are global and have defined globally and with a 'brick'.

    Back to my automated machine. So the idea is that the gun will rotate over a set of degrees and when it detects anything in its way it will fire as many rounds as it can it 1 or 2 second bursts. The processing of building this I also got the hang of gearing operations with the NXT servos which I'm sure will help with building other robots. I will include a picture of this with this entry. You'll note that in this we end of with gearing on 3 planes and we can achieve step down or up solutions with this design.

  • SQL 2005 CLR debugging in the 64-bit Environment

    Ok. So setting up CLR routines in SQL 2005 can be a bit of a pain but once you get past that there is a lot of cool stuff you can do. Allot of developers I know get a bit bent out of shape around CLR routines as they are not the fastest way of doing most things but there are actually sounds reasons for doing CLR routines even though they might be slower then T-SQL for core database tasks. One of the primary reasons in my mind for adding the CLR technology is that you get the ability to turn SQL into an application server. So my favorite case for CLR routines in the db is pushing Credit Card and Financial processing in to the database layer. Anyway for now I wanted to just note one little issue around CLR routine debugging.

    So I use this ubber 64-bit monster as my desktop machine. Its got ALL the bells and whistles but once I managed to get my CLR routine in the db for importing a huge block of XML and I figure a CLR routine written in C# is going to take months less to write then trying in vain for weeks todo do the process using SQL. So the ideal is I have this CLR routine that uses XML Serialization to import my XML blob and then it processes this into data into my data base. It seems like it works and I write my unit test script and try to run it and it steps into the t-SQL in the debugger and I get to my break points and then it trys to step into my C# code and the entire thing blows up. And I don't mean my routine blows up, Visual Studio blows up, something about 32-bit code and going from 64-bit to 32-bit. In any case there is an easy fix. Just spin up the 32-bit 'Visual Studio Remote Debugging Monitor' and it all works like a finely oiled machine. Start - All Programs - Microsoft Visual Studio 2005 - Microsoft Visual Studio tools - Visual Studio Remote Debugging Monitor' you can tell you have the right one as you want the one that doesn't say (64-bit) by it.

  • Lego Version of this using Blue tooth and Indigo...

    Hmmm... this link is for fun but maybe when I get a bunch more sets I might try to build something like this.

    http://www.technovelgy.com/ct/Science-Fiction-News.asp?NewsNum=703
  • Robotics, Windows and Legos

    A number of years ago I worked at a different company during the height of the dotcom era in the companies R and D department. One of the other guys brought in this new mindstorms lego set that was just the coolest thing at the time. You would build robots that run and around and do all kinds of things. From robots that run around and chase people to color recognition and even messing with the cleaning staff. All in good fun right? From automatic transmissions to Gatling guns we had a lot of fun. My interest in robotics really started with these Legos. Its now a number of years later and my work has stayed on the bleeding edge and we hear that Microsoft has put out a new Robotics design studio along with the latest Mindstorms from Lego. With built in blue tooth and an indigo programming model we were excited to get the latest and greatest in house for our work in advanced prototype development for Microsoft.

    So Mark (the CEO) got a number of sets and I think everyone was afraid to touch it for a couple weeks and finally Lori (office diva) opened the box and my son came in as a punishment to sort the parts into this nice tackle box. hmm, my wife didn't seem that think this was much of a 'punishment' but that is a different story. Anyway I digress. So finally I started playing with these Legos with the goal of from a technical stand point understanding the mechanical physics of building a robot, learn to program to the device API's in the window environment and most importantly build a combat droid to harass incoming customers how come into the office. The robot would run long the top of this half wall turn a corner and go to the end where it had a perfect view of the lobby to take aim at. It was almost like the wall was meant for just this purpose.

    So the first couple of days I found a couple of issues with devices and such and differences from the older versions of mindstorms. So on my first few days of playing with the new NXT bits here is what I found:

    1. The ultrasonic sensor should not be too close to the edge you are looking a change on as it will not detect a change as much especially when there is vibration from the device giving a false reading. A good few inch's seems to do much better.
    2. There is not differential part with the new mindstorms... but much to my dismay it is just better not to have both wheels powered any way and much less complicated.
    3. Rail guides are problematic. So we have this half wall that I was attempting to make the robot move on and I used some guid's to make it work. much to my discontent this proved problematic to solve. Basically on square corners avoid a guide...
    4. The gears for doing angles is better in this version then the old gears that were provided.
    5. Lego parts are not as exacting as one might hope when building fully autonomous robots...
    6. Using the castor design that the initial directions come with seems to be the best design thus far.
    7. limited memory still on the 'brick'...
    8. Lego IDE is limited. Granted that comes from some one that is used to the ubber version of Visual Studio and programs in 14 odd languages... but there is the new MS Robotics Design Studio... But basically I guess I find that real fall down is the in ability to do OOP (Object Oriented Programming), for the most part the 'lego' ide forces you into this sort of linear programming flash back de' ja' vue thing, granted you are programming with objects but still.
  • Lego Mindstorms NXT

    Ok so maybe I was a little harsh on the lego IDE as it is cool, and you aren't writing code so it kind of realizes the whole Visio IDE and you can define new 'bricks' or objects but I really feel more at home in the VS environment... we will give it a few weeks. :) In any case one cool feature I found is that you can use the arrow keys to scroll the design surface. Maybe for the next version they can add 'scroll bars'... another draw back that has been bugging me is the time out on the brick. I made this cool attack droid and had it stocking the front of the office and after so many minutes it shuts off when waiting and it is in a loop. I'm going to try to make the loop do something with a motor and see if it does the same thing.

    So among my playing with different designs I have found that there are a couple of design patterns that are starting to emerge for me. That's a bit of the architect coming out but so lets start with the problem space. The first series of robots was robot on a controlled path including motion. In this problem space I found things like staying on the 'track' a big issues and control. The second droid thus far has similar issues even though it is more 'autonomys' and is more 'generic'. So I have included shots of the two robots. I find biggest problem is maintaining location and staying on track, and not so much a physical track but the smallest in perfection in the pathing or guidance like a few degrees off on a turn and things can break down quickly. In any case this problem space of navigation in the environment I think is a big one. So I'm thinking that for now I'm not really dividing the problem space from the design pattern but it will give me a place to start. So here goes on some definitions on the MS Windows/Lego Robotics:

    • The BaseLine: 3 out put and 4 input devices with a blue tooth radio and USB download (this is sort of our base line).
    • Navigation: A robotic system designed to navigate in an environment.
    • The Machine: a robotic device designed to preform a specific function in a controlled environment.
    • The Part Droid: a robotic device component that fits together with others to build more complicated machines, robots and droids.
More Posts
© 2007 IdentityMine, Inc.
Powered by Community Server (Commercial Edition), by Telligent Systems