Friday, July 03, 2009

Batch files and SVN


Batch files are useful for writing small automated scripts in windows.

You just type any command you like into a text-file with the extension ".bat" and it will do the magic for you.

Some extra commands/parameters will help:
%1,%2,%3 ... will let you pass additional paramters
echo will print something to the screen
@echo off will stop the bat file from printing everything to the screen
REM will make a line into a comment
> will let you pipe the output between commands, just like on *nix.
set /p variable= [string] will let you prompt for input
exist will let you test if a file exists

You also have programming constructs including 'if' and 'goto'. (For an example see this batch file sorting routine)

That's pretty much all you could ever need.

So a simple example, named test.bat:

@echo off
echo hello %1

If I call this with "test Adrian" it will print "hello Adrian" to the screen.


@echo off
set /p name= What is your name?
echo hello %name%

This does the same, except prompts me to enter my name.

There are more than just the %1..%n variable for commands, there is also %0 to tell you the name of the bat file. Even better, you can extract the path with %dp0
eg:

@echo off
echo %~dp0


So now you can invoke Tortoise SVN on the command line to download and install your favourite software.

For example:

tortoiseproc /command:checkout /path:%~dp0 pal /url:https://pal.svn.sourceforge.net/svnroot/pal/pal /closeonend:1
tortoiseproc /command:checkout /path:%~dp0 bullet /url:http://bullet.googlecode.com/svn/trunk /closeonend:1


Even better, we can extend this with exists to see if the code is already there, and do an update instead:

if not exist pal\NUL goto nopal
tortoiseproc /command:update /path:%~dp0pal /closeonend:1
goto NEXT
:nopal
tortoiseproc /command:checkout /path:%~dp0 pal /url:https://pal.svn.sourceforge.net/svnroot/pal/pal /closeonend:1


Enjoy!

Thursday, July 02, 2009

Getting started on the PS3

It's been a while since I set up my PS3 with Linux, but I remember it being a lengthy process. Installing Yellow Dog Linux on the PS3 is relatively straight forward, but then getting the compiler tool chain up and running took a while, mostly in just figuring out what to do. If you only have RCA out on the PS3 you need to install Linux in text-mode, which I remember being a bit dramatic (all the instructions assume you have the GUI environment).

Yellow dog has an package manager called 'yum' (Yellow Dog Updater, Modified).

After the install do a 'yum update'.
(Note, if you are behind a proxy you will need to set the http_proxy variable. For other networking issues 'ifconfig' up/down and 'dhclient' are your friends.)
export http_proxy = "http://username:password@proxy.host.com:port"


Now do a search in yum for any SPU/PPU packages, ie: 'yum search spu' and install the relevant ones. (I can't recall which ones, probably libspe2,spu-binutils,spu-gcc,spu-newlib,ppu-binutils). At the end of this you should have spu-gcc, ppu-embedspu, ppu-ar and the usual suspects (gcc/g++).

You have these different compilers because the SPE and the PPE are completely different processors, it's like having two different computers in one box. So the spu-gcc compiles code only for the SPE, and the 'normal' gcc compiles code for the Power PC.

Obviously the first thing to try is 'hello world' for the PPE, but after that a little SPU/PPU program is what to try. You should be able to find some code on the web, (try the GATECH STI website, or Jeremy's SPE hello world examples) so then you just need to build it:
spu-gcc spu-program.cpp -o spu-program
ppu-embedspu -m32 symbol_name binary_name output-embedded.o
ppu-ar -qcs spulib.a output-embedded.o
g++ ppu-program.cpp -lspe spulib.a -o output

Or, as a concrete example:
spu-gcc spumain.cpp -o spumain
ppu-embedspu -m32 hello_spu spumain hello_spu-embed32.o
ppu-ar -qcs hello_spu.a hello_spu-embed32.o
g++ ppu-program.cpp -lspe hello_spu.a -o helloworld

So in Step 1, we are compiling the SPE program, in Step 2 we are embedding it into an object file by providing the symbol name (eg: extern spe_program_handle_t hello_spu), the binary name (the result from spu-gcc), and the final object file.
In Step 3 we are creating a library from the object, and in Step 4 we are linking it all together.

The entire 'embedding' thing can be a bit confusing, but Alex Chow provides a great overview.

(Note: If you are working with windows, putty and winscp will make your life a lot easier. If your new to linux, try the 'nano' editor (or 'pico'), as opposed to the more powerful, and difficult to master vim. You can make something executable with 'chmod +x filename'. If you stuff up the console, typing 'reset' will save the day)

Good luck. You might find this Cell Cheat Sheet useful.

Wednesday, July 01, 2009

Catchup post

The problem with blogging is that you need to find time to keep it moving even when you are very busy. Then, when you get the time you forget everything you wanted to post.

So just a quick catch-up post:

First of all, I've noticed a number of people trying to use CUDA for,.. silly things.
This includes attempting to accelerate databases with CUDA and accelerating downloading with CUDA. I'm somewhat reminded of the Intel marketing campaign that MMX speeds up communications. Someone somewhere needs to explain that your not limited by CPU computations when your downloading things...

Anyway, some more news&articles&programs:
  • the netflix prize probably has a winner.
  • Jeff Moser covers the process of a http connection.
  • I always find this program useful, I've posted on it before:Dependency walker
  • Parallels is a deeply integrated VM, which has some impressive demonstrations on their website, and I'm hoping will be very handy for my new mac.

    I've finished working on the 18m grapples, they invited the Engineers Australia - Women in Engineering to Transmin during the open day, which was great.

    Back to working on PAL, ModBench, the PS3 with Jeremy, and a explicit CUDA groundwater simulation with NTEC.
  • Friday, June 12, 2009

    Python Setup Tools 2.6


    Setting up "easy-setup" (haha, not so easy!) for python 2.6 under windows is a bit of a convoluted process.

    These are the steps:
    1. Install Python.
    2. Download the python egg file
    3. Download ez_setup.py (Takes a while till you find a working one!)

    You may wish to place it into your python 'scripts' folder first.

    Then run the python program "ez_setup setuptools-0.6c9-py2.6.egg".

    Now you can use any setup script that relies on easy setup.

    IT Salary Levels in Perth

    I was having a look at some IT salary survey data for Australia.

    It has always annoyed me that "less difficult" tasks were valued more than more "difficult tasks". For example, a C++ programmer in Perth contracts from $40-$75, a VB developer gets the same, and a .Net developer gets more ($80), with Java winning out at $90. Even web developers get more, starting at $55.

    This has always annoyed me about Perth. However, take a look at a different city, and you will see a different story. Take our nearest neighbor, Adelaide.


    .NET $40-$75, Java to $65, VB to $65, Web developers to $65, With C++ topping it out at $85. Seems a lot more reasonable to me.

    In Adelaide, help desk staff start at $37k and get paid $58k, tops, unlike Perth, where desktop support staff start at $45k and top out at $65k. This is the same starting salary for a C++ developer in Perth. This certainly explains why people in Perth don't bother to stick around if they get a good education. If you can earn as much on help desk straight from school as you can with a university degree as a programmer, why bother?

    What is wrong with Perth?

    Simulating Sensors

    For many robotics tasks getting good readings from the sensors to estimate your current state is very important. The system may come to rely on the sensors so much that any hardware failure for the sensor would cause devastating consequences.

    A few simple noise simulations placed into your sensor readings can help you assert that your system can handle failed sensors. But what to simulate?

    There are a number of academic papers available that discuss sensor noise models, but they are typically highly detailed and specific to one sensor type.

    Here is a list of common faults that you should simulate for testing analog sensors:
  • Completely on/off, this will only happen if there is a problem with the power supply, you will either get 0 or full positive, this helps to detect shorts, etc and other common failures.
    In code: sensor = 0, or sensor = high;
  • An additional DC offset, this will simulate a slowly drifting ground, you may also wish to simulate this with a slow rise/drop over a long time.
    In code : sensor+=dc_offset;
  • Inversion fault, if someone installs a sensor the wrong way round, or wires something up the wrong way.
    In code : sensor = 1-sensor;
  • Random noise, white noise is not really a very common input from the real world, but its a cheap test routine. Adding it to your signal can help determine that your filters have an appropriate noise cut-off level.
    In code : sensor = rand(); or sensor+= signed_rand();
  • Sinewave, you will find sinusoidal interfearence coming from a number of sources, such as interfearance from a nearby radio unit, micro controller, or PWM. Often higher frequency signals will be aliased and presented as a low frequency sine wave.
    In code: sensor = sensor + sin
  • Spikes/Ramps, these will sometimes occur due to the way an analog signal is read or converted to a digital form, or some rotary encoders will droop down. Poorly designed hardware filters can also be the cause.
    In code: sensor = sensor + spike, or sensor = sensor + ramp

    The last one is a little trickier to implement, but some nice common curves can help. First, the smoothstep function:

    float smoothstep(float a, float b, float x) {
    if (x if (x>=b) return 1;
    x = (x-a)/(b-a);
    return x*x * (3 - 2*x);
    }

    (I originally found this function in Texturing & Modeling: A Procedural Approach)


    The spike function:

    double spike(double t) {
    return 1/(1+150*(t-0.5)*(t-0.5));
    }

    you may wish to play with the 150x factor to make it more 'spiky'.
  • Saturday, May 30, 2009

    Link post

    Some assorted interesting sounding tech:

    Thrust is a STL-like tech for CUDA programming. Could be interesting, certainly looks like it is easier to use than CUDA, but just from my feelings it probably won't be worth anything until nVidia let multiple CUDA functions execute in parallel..

    5 optimization tips for CUDA, a nice succinct roundup of some good performance tips for CUDA, including Arithmetic Instruction optimization.

    DANCE framework for Dynamic Animation and Control, definately something I want to check out for potential synergy with the Physics engine Abstraction Layer. Proper animation controllers is something PAL lacks.

    ReactPhysics3d a new open source physics engine, very much in the early stages of development, I've seen a number of engines grow in time, I hope this one succeeds too, but it will need to find a niche if it is to survive..

    Predictive-Corrective Incompressible SPH is a paper on estimating the SPH state without explicitly evaluating it, thereby saving some CPU cycles. I actually had a similar idea, so maybe this is a path for further research. Also on the SPH front, Co-rotated SPH for Deformable Solids, the idea is great, not convinced by their particular implementation though..

    Perhaps these ideas might make it into the SPH routines for PAL..

    and on the lighter side;

    2D boy's prototyping framework for the world of goo.