Sunday, 10 April 2016

Arc Welding Arduino Code

From my YouTube Video:



int ledPin = 13; // LED connected to digital pin 13

void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop()
{
int i,count;
count=random(10,60);
for (i=0;i<count;i++)
{
digitalWrite(ledPin, HIGH); // set the LED on
delay(random(60));
digitalWrite(ledPin, LOW); // set the LED off
delay(random(200));
}
delay(random(800,2000)); // wait a random bit of time
}

Monday, 4 April 2016

Junk PC - Celeron to Core 2 Quad

You may guess I've taken what was basically a junk PC from the in-laws and turned it into a fairly decent machine, what could it do?... Well it was reported to be showing "video like an old slide-show", "internet pages took so long to load we could boil the kettle" and a myriad other little things.

To hear those kind of reports from regular users of 70+ years of age, rang alarm bells, something needed to be fixed.

The machine was:

Intel Celeron 450 @ 2.2ghz
1GB DDR2 400Mhz RAM
Intel HD 3000 Graphics (on board)
320GB western digital carvier blue HDD

I've raided ebay, Amazon and my own spares, and the machine is now, re-cased, with new air-flow/cooling, and it's significantly improved:

Intel Core 2 Quad Q6600 @ 2.4ghz
4GB DDR2 800Mhz RAM
Asus GeForce 610 GT (1GB DDR3)
120GB Scandisk Performance SSD

With a nice new box, the thermal paste, a cleaning air-can and all the bits I needed the upgrade cost just shy of £60.

And the new incarnation of the machine runs:

World of Warships - High Settings - 50FPS
World of Tanks - High Settings - 50-60FPS
Minecraft - Fullscreen - 100+FPS
Arma 3 - Medium Settings - 25FPS
Arma 2 - High Settings - 60FPS
H1Z1 - Medium Settings - 50FPS

This is impressive performance from a bog standard Intel G33 Motherboard and a bunch of spare parts.

Certainly £60 was a very fair price for all this kit, and I can't help but thank the moron on ebay who sent me a mail abusing me for listing "such old shit at a high price"... because through whatever machinations I kept the kit, and here we are just a month on with is back in use and blowing through performance like no-ones business.


Saturday, 2 April 2016

PC upgrades, and more coding ideas

As you can see, I'm in the middle of working on some PC kit.  Upgrading the in-laws old kit and retiring one of mine in the process.

I'm going to be working on the second part of my functional programming post later today, covering some alternate languages and better explaining maintainable code with relation to those parameters being passed.

Friday, 1 April 2016

Coding Standards: Functional Programming (Code Maintainability)

Functional Programming

When I were a lad, and was being taught to program, I read a bunch of Basic code and wrote great long lists of instructions; that's pretty much how many people in the 90's described programmers, coders or hackers "someone who spends lots of times typing great long lists of instructions into their computer" - Robert X Cringley.

However, long lists only get you so far, so my next step into the world of programming was to learn Pascal, and I first read a simple book as part of my A-Level, by P. M. Heathcote, which introduced very basic programs in Pascal, something like...

program HelloWorld (input, output)
begin
    println ('hello world');
end;

So, I suddenly had this idea of putting the long lists of instructions into sort of functions:

program HelloWorld2 (input, output)

   procedure foo()
   begin
       println ('foo');
   end;
   
   procedure bar()
   begin
       println ('bar');
   end;
   
begin
   print ('hello ');
   foo();
   print (' and hello ');
   bar();
end;

(Note: before you call me out and say you can "GOSUB" or "CALL" other functions in BASIC, not in the dialect I first learned, all you could do was SUB to a line number, following the instructions until you used RET to go back to where you were... So they were technical functions, or procedures, but they were really just more lines of code within the huge list of lines of code, no indentified in anyway, except by comments, as being functions).

Interestingly at this time, I was taught there were two kinds of functions you could call, ones which returned a value, known as "functions" in Pascal, and ones which didn't return anything known as "Procedures".  These latter you'll be very aware of from other langugages like C, where the return type is part of the function declaration, so "void foo();" obviously doesn't return anthing, whilst "int bar();" returns an integer.

That "Procedure/Function" definition stuck with me a long while, I was a kid, I was taught something and got a certificate to say to the world "He knows what he's talking about", so it was with some trepidation, years later, that I had to admit it was rubbish and everything was a function.

And this revelation came with my being taught about "Functional Programming", this was important for large projects written in languages like C, because you really wanted to start to learn how to keep functions doing one task.  So when you designed, named, write and test a piece of code, you can break it down, and know each piece, or each function, is doing just one job.

"void Max(const int& p_Left, const int& p_Right, int& p_Result)"

Here I've just defined a function prototype, even without my explaining, I'm pretty sure you could guess what it does... Yes, it takes the left and right integers given and decides which is the bigger, placing that value in the result.

We can design code, define the prototype, and hand the nitty gritty of the actual code body of to someone else, to write the body of it, or just to test our implementation works.  And though this is a trivial example, think about a single function to say format a disk, it might contain calls to dozens, or hundreds, of other functions, but it itself does one task, and each sub task is itself kept in a single function so you break the whole job down.  Within your large projects therefore you maintain a level of ease in how to debug, maintain and update the code, if your "foo" function doesn't work, just fix that one function and re-test, there shouldn't be multiple-foo's and there shouldn't be more than one task performed within the code inside "foo".

This was the first major meeting, and teaching, I had on "Functional Programming", and it was something I took to heart.  My code took on very much a "one function" style, where each function had a single purpose.

Twenty years on, and even in an Object Orientated world (of C++, C# and Java) I utilise the functional idea.

The main thing applying the single function ideal to my code has lead to is a vast improvement in maintainability, this has been important for my job and on going sanity with large projects.

However, there are other caviates, for there are other parts to functional thinking which have to be taken into account.  For example, are you going to allow functions in your code to have just one, or multiple exit points from a function?  For example:

const int bar (const int& p_i)
{
   return p_i * 2;
}

const int foo ()
{
    if ( x > 0)
    {
        return bar(x);
    }
    else
    {
    return bar(-x);
    }
}

This is perfectly reasonable code, foo does one job, deciding upon the value of x which value to pass, however, this is a trivial example, what if there are tens, hundreds or even thousands of different paths you could take as the result of foo?... A case statement with every character possible already throws hundreds of options our way, so it's not out of the ordinary.

You could be tracing through this code and ANY of those many exit points could fail, causing a crash, which you then have to dig through after the stack has all unwound.

Using many exit points is fine, if you can justify it, please don't get the impression I'm hating on the concept, if you have a low memory situation for example, I can see you won't have space spare for my suggested solution; and this is part of the many trade-offs you will learn about in a career of programming, when to, and when not to employ a technique.

But in the above example, I would change foo as follows:

const int foo ()
{
    int l_result = 0;
    if ( x > 0)
    {
l_result = bar(x);
    }
    else
    {
    l_result = bar(-x);
    }
    return l_result;
}

So, you see I have a local value copy, this is using more memory, and wants to allocate that memory... and there are other options than allocating that as a local variable, but for maximum maintainability keeping that value within the actual function is a key feature of this example.

And so how does this assist in maintainability?  Well, we can now debug the function a lot more easily, we can see the value of "l_result" at any moment in a watch within the debugger, we can wrap individual - failing - calls to "bar" into try-catch statements and debug the returned value for the whole function at the return at the bottom.

I've seen some horrors in the poor use of both returning from within a function, where return points are hidden three, four or more nestings deep, and it's made for nothing but frustration, try to avoid multiple function exit points.

What else does functional programming offer us?... Well, it also offers us an easy way to make code self-documenting, if we have a function like the "max" function earlier, it explained itself in just it's definition, take advantage of that fact.

But what about functions inside objects?  I hear you cry, well lets take a pure C++ example, in C++ (or at least most C++ compilers) we're allowed to just define a function prototype and go to town, but that's really; technically; C not C++.  To make things C++ we really should have the functions all inside a class definition... I stick to this idea, even if we just need a pseudo class of static functions:

class Helpers
{
    public:
    
          static void Max(const int& p_Left, const int& p_Right, int& p_Result);
          
          static const int Sum(const int& p_Left, const int& p_Right);
          
 };

 One can see what the functions mean, and the function have meaningful names, the class itself can have, a useful name, and indeed the class can then be in a namespace which itself has an even more useful name.  So we build up not complexity, as some assume, but ease of division of functionality, breaking numbers from user interfaces from strings from file management, break it down, divide and conquer, that was the original purpose of functions in computing, and so that original function is now emphasised in the languages and methods we employ today.

 C++, C#, java, Python, all can benefit from using the function idiom... Your projects certainly can.

Thursday, 31 March 2016

RIP Ronnie Corbett

And it's good night now from them both...


A comedian and entertainer, surpassed perhaps only by the other half of the Ronnie Duet which so defines his legacy, I'm so sad to hear of his passing this morning.

Though many consider his career in terms of his work with the late Mr Barker, Ronnie Corbett was by far the better man in the conversational prose, his work with the audience from a simple seat in the post-light is quintessentially the definition of his comedic genius, and no-one can deliver quite like Ronnie did from that position.

His warmth, passion for entertainment, and quick-wit always shone through, and he'll be missed.

Yet another great gone in 2016.

Tuesday, 29 March 2016

Wiring, Monitors, Ponies and Virgin Media

Sorry for the long delay since my last update, in the interim time I have been working on improving my recording technique from Arma 3 - so much so I have accrued around 25gb of footage, covering four different operations in the game, in long play mode - however, due to Virgin Media currently screwing me over (more about this later) I'm unable to upload any of it within a decent time-line.

So, what have I been up to apart from playing Arma 3?... Well, I've taken delivery of a new monitor, and Asus MX27AQ, which is absolutely lovely.  I've gone from running, and recording the games I play, in 1280x1050 to playing them in 2540x1440 and shadow play is recording them in 1080p.

Counter-intuitively for Arma 3 however, it's performance has improved, I've changed no settings, just moved from rendering over DVI at the lower resolution to using HDMI in the higher resolution, and the FPS has gone up, I now get 40-50 in a busy server (20 in towns) where I was getting, 10-15 in a busy server and 2-3 fps in towns.... Which is totally bonkers, and something I need to look at more closely.

In personal coding time, I'm totally on hiatus, I've been playing with Ackermans function, a few other code projects, the 2D engine for Dungeon crawling has been tinkered with, but I'm just so busy there has been no personal coding time.

I have however, finally had time, with the arrival of the monitor to sort out my desk wiring and networking, I've got the solid cat-6 cable from the router up through the floor and now going to a 12 port hub, from this I have my laptop, two PC's and a Pi working.  They're providing lots of working network points basically, for streaming or work.

I've then sorted the power wiring, to include  power smoothing extension now, which has 3 power smoothed and surge protected slots on it, these power the main PC's.

We've also been busy with Gerty, the pony, she had her first meeting with the dentist recently, having to have her baby teeth crowns removed to allow her adult teeth through, and the removal of two wolf teeth...


As you can see, she was pulling some funny faced afterwards.

And now VirginMedia, the wife asked me a couple of months ago to check our bill... £50 ish we're paying... and I figured, we're on the 200mbit, Tivo box, with channels galore, no problem... That's about right, I saw the newly named "Vivid 200" offer for £49.95, and figured we were on that... and left it be.

However, having tried to upload this serious amount of data over the Easter weekend, and been totally hampered by their throttling the upload down (yes, they still do this https://my.virginmedia.com/traffic-management/traffic-management-policy-thresholds.html) to nearly nothing, I got onto the chat help with them to ask for information... And it was very worrisome to hear the member of their staff telling me that they don't throttle things down.... Reading their live, current, traffic management policy, they do just that... so what hymn sheet are their staff reading from?

"Your downloads are not managed"... Whatever, I am talking about UPLOADS!

They just were of no help, and I figured, it's Easter, they'll be in some foreign call centre being paid pennies to read the answers from an expert system which is scripted to make them sound a little less useless then someone paid pennies to read a screen, should sound.

Today, I've logged into VM to see what my account status is, and not only am I now clamouring to talk to them, but I'm fucking furious... I'm paying over £50 a month for the M package!... the medium... 50mbps... 

For that same price one can get on the Vivid 200 package!... So I automatically hit the button to check what offers they'll give my account... they're only offering me the Vivid 100.... 

Why's this making me furious?.... Because I was told I was getting 200mbps just the other day, how can I be when my package is capped at 50?... GAH... so now I'm trying to chase this all up.... Watch this space.

Oh, and now their support site is fucked... VIRGIN FIX YOUR EGAIN SYSTEM!

Thursday, 10 March 2016

Arma 3 - Grenade Worries

Last night I decided to take a look at come add-ons for Arma 3, notably the ACE3 pack, I was unfortunately disappointed with the pack, it seems to obfuscate so much of the learned functionality and change so much as to make it feel alien rather than a helper.

One notable problem was, no matter what I did, I could not lock nor fire an AT missile from a Titan Compact launcher, even dropping into the editor, sitting a target in the open and trying to fire point blank it'd not lock on.



Reboot and try without Ace, everything was fine, and this leads to a problem Dyslexi has passed the mantle of his excellent looking grenade mod over to Ace, if that grenade mod ends up mixed into the mash up within ace then it maybe impossible to separate it back out and run it without the perceived confusion Ace has caused me.


The other thing I looked at in the edit, as one can see from the above screenshot, was wind direction and it's affect on the battlefield.  Primarily I looked at this because I've been continually gravitating on the Zeus Community Server, however, their server seems to never have any weather other than the occasional splatter of rain.  So seeing wind make smoke drift was interesting.

Don't forget, you can find highlights and full streams of my adventures in Arma 3 on youtube now.