General BLOG stuff

Making an external connection to a Blaknight MySQL database

You can connect to a Blacknight MySQL database from an external tool (e.g. mysql or mysqlimport commandline) if you change some of the database’s settings. This can be useful if you need to manage your database, for example if you need to perform a large database import (one that is so large it causes phpMyAdmin to time out).

First you need to configure the database to allow external connections, in the Blacknight control panel choose to edit the database’s settings and check the ‘Access from external hosts’ check-box. This change on its own isn’t sufficient, next you must add your ip address to the ‘Access Hosts’ list.

enable_external_access

When on the database properties page, click on the ‘Access Hosts’ tab, click on ‘Add new access host’ and add your ip address. To find your IP address, just google ‘my ip address’ and your address will be displayed near the top of the results page.

add_ip_address_blacknight

Once you have made these changes you should be able to make external connections to the database. When you are finished it is probably a good idea to remove external access again.

You can now do something like import a database, get the hostname from the ‘external hostname’ field on the blacknight control panel:

mysql --host="mysq12666.cp.blacknight.com"   --user='u1273449_the_user' --password="ThePassword" database_name < ./db4.sql

Software Requirements Specification

software_requirements_1

I am currently of writing a fairly large software requirements specification for a client. I am acutely aware that in general people don’t like to read documents, and that large terse documents like software development specifications can be especially challenging. To help reduce the amount of effort that readers will have to put into reading and reviewing the document while attempting to increase its usefulness I am doing my best to follow some simple self enforced rules:

1. Avoid using abbreviations (TLAs)
2. Avoid mentioning technologies – this is a requirements spec. after all!
3. Avoid unnecessary Capitals As Much As Possible!
4. Avoid repeating words in a sentence for no good reason
5. Run the spell checker
6. Add a revision number
7. Print out and properly review on paper before releasing to to the client.

Hopefully if I stick to these rules, then the specification will end up as a slightly ‘better’ read.

Mathematica to be bundled with Raspberry Pi

The register reports that Mathematica is to be bundled with the RaspberryPi which to my ears is fantastic news as Mathematica is by far my favourite mathematical tool even if the forces of convention force me to use the slightly duller Mathlab most of the time…

sudo apt-get update && sudo apt-get install wolfram-engine

Algorithm to calculate speed from two GPS latitude and longitude points and time difference

To estimate average speed of travel between two close GPS points.

A relatively simple method involves treating the globe as a sphere with a radius of 6378100 metres and calculating positions on this sphere for the two locations, of course the earth isn’t a sphere, but as we are aiming to calculate the speed of travel between 2 quite close points we should be OK.

First we plot the two GPS points on a spherical model of the earth, then calculate the angle between them using a dot product, then calculate the ‘Great Circle’ distance using this angle and the earth’s radius and finally we divide by the elapsed time to approximate the speed.

Here is some code to demonstrate the calculation.

This function takes the latitude and longitude in signed decimal format and returns the distance in metres, I have left in the ‘r’s for clarity but if efficiency is what you’re after then they can be removed.

//
//
double distance_on_geoid(double lat1, double lon1, double lat2, double lon2) {
    // Convert degrees to radians
    lat1 = lat1 * M_PI / 180.0;
    lon1 = lon1 * M_PI / 180.0;
    lat2 = lat2 * M_PI / 180.0;
    lon2 = lon2 * M_PI / 180.0;
    // radius of earth in metres
    double r = 6378100;
    // P
    double rho1 = r * cos(lat1);
    double z1 = r * sin(lat1);
    double x1 = rho1 * cos(lon1);
    double y1 = rho1 * sin(lon1);
    // Q
    double rho2 = r * cos(lat2);
    double z2 = r * sin(lat2);
    double x2 = rho2 * cos(lon2);
    double y2 = rho2 * sin(lon2);
    // Dot product
    double dot = (x1 * x2 + y1 * y2 + z1 * z2);
    double cos_theta = dot / (r * r);
    double theta = acos(cos_theta);
    // Distance in Metres
    return r * theta;
}

Now once you have the distance between the points you can estimate the average speed by dividing this distance by the time between the two position measurements, something like this:

 

//
//
auto dist = distance_on_geoid(p1.latitude, p1.longitude, p2.latitude, p2.longitude);
// timestamp is in milliseconds
auto time_s = (p2.timestamp - p1.timestamp) / 1000.0;
double speed_mps = dist / time_s;
double speed_kph = (speed_mps * 3600.0) / 1000.0;

This code assumes that p1 and p2 represent the first and second measured GPS positions and that the time-stamp recorded at each is enumerated in milliseconds, it calculates both metres per second and kilometres per hour. It is important to note that this is only an estimate of the average speed between the two points and its accuracy will depend on various factors including the distance and time elapsed between the two GPS measurements.

Computer Vision in the Cloud? – Amazon makes Nvidia GPUs available

I just came across this article from The Register that mentions that Amazon is making Nvidia GPU cores available:

http://www.theregister.co.uk/2013/11/05/aws_gpu_grid_service/

Makes me think again about the possibilities of doing Computer Vision / Machine Vision in the cloud (taking advantage of GPGPU techniques via OpenCL etc.), however like most of Amazon’s stuff it would probably be way too expensive, interesting though – I must look into it if I ever get the time…

New Look Website

If you are a repeat visitor you may (or may not) have noticed that we have launched our brand new-look website.  There are still a few tweaks to do so if you notice anything dodge please let us know!

Many thank to Ridge Design, Wicklow for the fantastic web design!

C++11 Lambda Expressions

It appears that using lambda expressions in C++ makes me surprisingly happy, they can be positively good for the soul it seems!

Fedora released for Raspberry Pi

Another OS option for your Pi – Fedora Remix has been released for the Raspberry Pi, it is based on the Fedora ARM secondary architecture project, more details can be found here:

http://zenit.senecac.on.ca/wiki/index.php/Raspberry_Pi_Fedora_Remix_FAQ

I love the 4th. item in the FAQ, it is entitled – “Why is the Remix slow?” lol

It makes me very curious, just how slow is it? I guess I will have to install it to find out! :-)

Enterprise Architect UML – Add C++ #include code statements for dependency relationship

By default #include statements are not inserted into files for dependency relationships when generating C++ code from UML models in Sparx Enterprise Architect – this is a bit annoying but we are well used to UML editors doing annoying things so at least it’s not a terrible surprise!

 

In Enterprise Architect’s defence it is quite easy to add this missing functionality. In order to get it to generate #include statements we have to edit two of the code generation templates: “Import” and “Import Section”.

 

To edit the templates go to the “Settings / Code Generation Templates…”, menu and you should see a list of the templates on the left-hand side of the screen.

 

Change the “Import” template so that it looks like this:

$file = %importFileName%
%if $file == "" or importInFile=="T" or $file == fileName%
%endTemplate%
#include "$file"

And then change the “Import Section” template so that it looks like this:

$COMMENT="WARNING: THIS IS AN ADVANCED TEMPLATE"
$COMMENT="DO NOT MODIFY UNLESS YOU ARE AN"
$COMMENT="ADVANCED USER!"
$imports += %list="Import" @separator="\n" importFromDependency=="T"%
%REMOVE_DUPLICATES($imports, "\n")%

%fileImports%

Now when you generate C++ code from your modle #include statements should be inserted to satisify dependency relationships.

 

Thanks to this article for the instructions (in German!).

 

Machine Vision on the Raspberry Pi anybody?

Here’s is a blog post that has some pictures of the (hopefully) soon to arrive camera for the Pi.

 

http://www.raspberrypi.org/archives/3224

 

It will be interesting to see what cone be done from a machine vision or computer vision point of view with the Pi once cameras are available.