Tech Blog

The guide to Computer Engineering I wish I had: Part 1

Last month’s exams bought an end to four years of Computer Engineering (CE) studies at the University of Canterbury (UC). As I moved through the years, it became clear that the prospectus and other glossy brochures provided by the marketing department are rather deceiving. They give the impression that students would be designing robots, computers and biomedical devices on a daily basis. Not true! I’d therefore like to delve more deeply into my journey through the degree with the intention of providing some of the guidance to future students that I would have appreciated.

It should be noted that the Christchurch earthquakes of 2010 and 2011 struck in the first and second years of my studies, and in many ways shaped my university experience.

The Bachelor of Engineering with Honors degree at the UC is split into a number of departments and specialties. All programs are four years of full time study along with a requirement of 50 days each of practical and professional work completed over the summer breaks, a first-aid course and two workshop courses. The first year is known as the ‘intermediate’ year in which students must complete a number of prescribed courses, with some options depending on their desired specialty. If all the intermediate year courses are passed with sufficiently high grades (the actual marks required depend on the popularity and size of each program), students are admitted to the Engineering faculty proper and complete three ‘professional’ years.

My main interest going into university was programming and I would therefore seem better aligned with a Computer Science degree. I ended up choosing CE on the advice of a number of family members, combined with the persevered higher prestige of an Engineering degree. UC has subsequently introduced a Software Engineering program which I would have chosen had it been available at the time.

Below I go into detail about my experience of the various required courses; however if you want the short version, here it is:

Engineering sucks in Intermediate year but gets progressively more enjoyable as you advance.

I shall qualify that statement shortly but it boils down to the fact that in intermediate year you are forced to do a lot of courses that have little to do with your desired specialty . I believe this is especially pronounced for a ‘fringe’ Engineering specialty such as CE. Much of the physics and mathematics taught at this level is far more relevant to Civil and Mechanical students than it is to CE students.

Intermediate Year Courses

Computer Science

Two first year computer science courses are offered. COSC121 is the introductory programming course, using the Python language. COSC122 is a basic algorithms and data structures course. I found both of these courses to be well taught and my most enjoyable courses of the year. COSC121 is interesting because the distribution of marks in the class always produces a ‘double hump’. This is a well documented occurrence in university ‘programming 101’ courses:

 It is as if there are two populations: those who can program, and those who cannot, each with its own independent bell curve.

COSC122 introduces sorting and searching algorithms, and various data structures. It is one, if not the most important course you will take at university as it is the one that will help you get a job! Every technical job interview I’ve had has asked about concepts from this course – with hashing showing up disproportionately often!


As with computer science, there are two maths papers; one each semester. I would classify both as ‘necessary evils’. They are tough papers with a lot of content being pushed through. It is not uncommon for people to fail the first course, EMTH118, repeat it in second semester and then to take the second paper, EMTH119, in summer school.

The good thing about the maths courses is that they change little from year to year and thus a lot of resources are available and the lecturers are familiar with the material. I found the maths department courses to be the best organized of all of the intermediate year courses. The examinations are also fair and consistent, so good results can be obtained through hard work.

A third required maths course, EMTH171 is taught in second semester. This introduces mathematical modelling using MATLAB. CE oriented students typically excel at this course because they are already familiar with programming. There are a couple of things to be aware of however. Firstly, the course is not offered in summer school, so a failure necessitates a second intermediate year. Secondly, the course contains two major assignments known as ‘case studies’ which are done in pairs. This contributes a significant percentage of the course grade, so it is important you choose a good partner (choosing  good group members is actually a consistent theme to having an enjoyable Engineering degree).


These are two pretty stock standard courses, PHYS101 and PHYS102. The amount of content does make them fairly tough however. The weekly three hour labs and associated lab reports will be one of the worst parts of your year. Manually calculating uncertainties is one of the most boring things you can be made to do!


ENGR101 is a first semester course which is widely regarded as a waste of time. You do learn how to write an engineering report though, which is important. Overall, you can get away with not doing as much work in this one.

In the next post I will talk about the professional years of the degree.

Tech Blog

Final year project – A remote laboratory


As part of my final (3rd Professional) year of Computer Engineering at the University of Canterbury, I have been working on a full year project. The college views these projects as the capstone of the degree program. They are designed to allow students to focus on a specific area, working at their own pass under the guidance of an academic supervisor.

My project is to design a remote laboratory system to aid teaching of Embedded Software in the Electrical and Computer Engineering department. I’ll explain exactly what that means soon, but first some background.

In 2012 students in ENCE361 assigned a project which involved writing an embedded program to control helicopter. The helicopter was to move up/down and left/right in response to button presses and to maintain robust behaviour at all times. The helicopter is fixed in a stand which uses a light sensor to output an analogue voltage proportional to its height. Students are required to read this value using an ADC and to control the helicopter with PWM signals.

Students enjoyed this project, however there were problems in regards to the helicopter in terms of access and breakages. It was hard to ensure each group had equal opportunity to use a helicopter stand.

Around the same time, my supervisor, Dr Steve Weddell was in communication with the University of Technology Sydney (UTS) and had learnt about the concept of remote labs. He figured the helicopter project would be a suitable candidate to be converted to a remote lab format.

The Project

For my project to be successful it would have to provide the following features:

  • Two functioning helicopter rigs.

  • Ability to respond to ‘virtual’ button presses.

  • Ability to upload programs onto the microcontroller remotely.

  • Ability to view the helicopter on a webcam.

I’m pleased to say that all of these requirements have been meet. The video below shows how students might use the system (best viewed full screen):

So, How does it all work?

The key to the whole system is SAHARA Labs, a set of software packages which provide a framework for developing custom remote laboratory setups. SAHARA is open source, released under a BSD license. To view and download the most up-to date code, head to the project’s GitHub repositories.


SAHARA consists of three main components:

  1. Web Interface – this is the components students (or other users of the system are presented with). It provides facility to login and access rigs, queue or make reservations if all are in use. Academics are also able to monitor student usage and download reports through the web interface. Rig pages can be customized with buttons and other control elements.
  2. Rig Client – provides various functions to interact with hardware. It is written in Java and requires further development to provide the final, lowest layer of abstraction to a specific rig.
  3. Scheduling Server – ties multiple rigs together and coordinates user access through the web interface. It has the ability to tie into a universities existing authentication system such as LDAP.

I installed all three of these components on an Ubuntu machine. The next step was to extend the RigClient and to choose hardware to interact with the helicopter and Stellaris development board.

UTS had recently developed a rig with a number of similarities to our planned rig, and they were kind enough to provide us their source code as an example to work from. Their rig involved students programming a Digilent Nexys FPGA, where’s ours uses a Texas Instruments Stellaris EKS-LM31968 development board.


I modified the web interface using HTML5 and JS to include the required buttons. When these are pressed, they fire Rig Client methods which are routed to a custom class. The next decision to make was how to send these logic signals to the microcontroller. preferably using a USB device. I investigated a number of options, including an Arduino board, but ended up choosing a FT245R FTDI device. This provides a bit bang mode which was perfect for this application. The standard way of talking to one of these devices is to write C code, using the libFTDI library. In order to achieve this from the Rig Client (which is written in Java) I used the Java Native Interface (JNI).

The following code snippet shows how pins are asserted in response to buttons presses routed from the web interface:

jboolean Java_au_edu_uts_eng_remotelabs_heli_HeliIO_setByte(JNIEnv *env, jobject thiz, jint addr) {
  if (!deviceExists) {
    // PRINTDEBUG("Cannot set data byte when not connected to Heli");
    return false;

  int pin;
  if (addr == 0) {
    pin = UP_PIN;
  } else if (addr == 1) {
    pin = DOWN_PIN;
  } else if (addr == 2) {
     pin = SELECT_PIN;
  } else if (addr == 3) {
     pin = RESET_PIN;
  } else {
    // Do something sensible.
    return false;

  /* Enable bitbang mode with a single output line */
  ftdi_set_bitmode(&ftdic, pin, BITMODE_BITBANG);

  unsigned char c = 0;
  if (!ftdi_write_data(&ftdic, &c, 1)) {
    return false;

  c ^= pin;

  if (!ftdi_write_data(&ftdic, &c, 1)) {
    return false;

  return true;

Code Upload

The other major bit of functionality required was to provide a way for students to upload binaries of their programs and to automatically program them onto the microcontroller for testing.

Luckily OpenOCD plays nicely with our chosen microcontroller. The Java Rig Client communicates with the OpenOCD daemon by instantiating a Python script, which in turn makes use of the Python Expect library. This is best understood by looking at the source code below:

import pexpect
import argparse
import os
import sys

def main(**kwargs):
if kwargs['format'] == 'bin':

def upload_program(program):
child = pexpect.spawn('telnet localhost 4444')



child.sendline('flash write_image erase ' + program)
child.sendline('sleep 5')

child.sendline('reset run')


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Flash a bitfile to the Stellaris')
parser.add_argument('program', type=str, help='Program name')
parser.add_argument('format', type=str, choices=['bin'], help='Specify the file format')
args = parser.parse_args()


Finally, the whole system is not of much use if students are unable to see the helicopter in action. A Logitech C920 is connected to the rig computer for this purpose. I had envisaged video streaming to be one of the simpler aspects of this project, but unfortunately  it was a pain in the ass to get working! The team at UTS said they used ffserver/ffmpeg, however I had no luck with the version in Ubuntu’s apt-get repository. It turned out, building the latest version from source was the only way to get it working:

sudo git clone git://
cd ffmpeg/
sudo ./configure
sudo makesudo make install
usermod -a -G video username

I was then able to steam SWF, Flash and Motion JPEG using the following configuration file:

# Port on which the server is listening. You must select a different
# port from your standard HTTP web server if it is running on the same
# computer.
Port 7070

# Address on which the server is bound. Only useful if you have
# several network interfaces.

# Number of simultaneous HTTP connections that can be handled. It has
# to be defined *before* the MaxClients parameter, since it defines the
# MaxClients maximum limit.
MaxHTTPConnections 200

# Number of simultaneous requests that can be handled. Since FFServer
# is very fast, it is more likely that you will want to leave this high
# and use MaxBandwidth, below.
MaxClients 100

# This the maximum amount of kbit/sec that you are prepared to
# consume when streaming to clients.
MaxBandwidth 100000

# Access log file (uses standard Apache log file format)
# '-' is the standard output.
CustomLog -

# Suppress that if you want to launch ffserver as a daemon.

# Definition of the live feeds. Each live feed contains one video
# and/or audio sequence coming from an ffmpeg encoder or another
# ffserver. This sequence may be encoded simultaneously with several
# codecs at several resolutions.

<Feed feed1.ffm>


<Stream status.html>
 Format status

<Stream camera1.swf>
 Feed feed1.ffm
 Format swf
 VideoFrameRate 15
 VideoSize 320x240
 VideoBitRate 250
 VideoQMin 3
 VideoQMax 10

<Stream camera1.flv>
 Feed feed1.ffm
 Format flv
 VideoFrameRate 15
 VideoSize 320x240
 VideoBitRate 250
 VideoQMin 3
 VideoQMax 10

<Stream camera1.mjpg>
 Feed feed1.ffm
 Format mpjpeg
 VideoFrameRate 15
 VideoSize 320x240
 VideoBitRate 500
 VideoQMin 3
 VideoQMax 10
 Strict -1

With these tasks complete, the basic system works! A second rig client has also been added – this involves installing another copy of the Rig Client on a second machine, which talks to the Scheduling Server over the network. A number of other features have been added since and I might detail these in a future post.

I have written a paper on this project and will present this at the 2013 Electronics New Zealand Conference (ENZCON) in September. More complete details can be found in my Engineering Report.

Tech Blog

Life in the cloud

For day to day computing, my web browser is the only program I use. Email, documents, spreadsheets, calendar, photos, music, even LaTex documents; it’s all in the cloud these days. The advantages of this move to decentralized computing have been well documented and I won’t go into them here. However, what hasn’t evolved at the same rate is a method of keeping all these services accessible and organized.

Since 1993, bookmarks have been a feature of all major web browsers and the canonical way of keeping sites organized. This worked okay at a time when sites were static and could be easily categorized into subjects and folders. However, these days, one of the main issues I have is remembering what service I stored something on – ‘What was that cool new js library again? Did I star it on Github, or save it to Evernote or Pocket…’. ‘That online banking form we filled in for the club last year, did I save that to Dropbox, or is it loitering in my Gmail account somewhere? or was it my Uni email?’. I’m sure this sort of thought process must be familiar to anyone who is as immersed in web applications as I am, and bookmarks are no help for this sort of problem.

Luckily some other troubled souls realised this was a issue before I did and have created services to try and aggregate various cloud services:

  • Jolidrive – Jolicloud is the new computing platform built around your life in the cloud. Jolicloud is the home for your most precious content.
  • Kippt – Build your online library of amazing things.
  • IFTT – Put the Internet to work for you.
  • CloudKafe – Organize your cloud.
  • Cloud Magic – A better life with every search.

These services all take a slightly different approach to addressing the problem, and each is a step in the right direction. Sadly, my experiences so far have been that they essentially try and do the jobs of the services they are aggregating, just in a less intuitive way or with fewer options. They’re also all relatively young and don’t come without the confidence of a well established company such as Google. For many users it can therefore be a tough sell to learn a whole new way of accessing their content, only for that service to potentially disappear the next day. And then there are the obligatory privacy concerns in giving one company the keys to all of your online information…

At the moment the best solution I’ve found has been to carefully select and limit the number of cloud services I subscribe to. One simple and worthwhile aggregation is to choose one email provider (in my case Gmail) and use it to pull (via POP3), email from all your other email accounts. Then at least all your emails are in one place!

Meanwhile, my search for the perfect tool continues.

Tech Blog

iTunes U – beware

I subscribed to iTunes Match when it was first released but it was only recently that I actually called on its backup functionality – and the results were a little unexpected.

As a quick summary for those unfamiliar with the service, iTunes U is Apple’s cloud music offering enabling users to have their music stored on Apple’s servers – backed up and accessible from anywhere. The main point of difference the service has with some of its competitors is that it will attempt to ‘match’ songs and just put a mark next to them song on Apple’s servers, acknowledging the user’s ownership (optimistically). This provides joint benefits for apple and the user:

  • Apple, in the best case need only store a single copy of each song, rather than a duplicate for every user.
  • There is essentially no upload when a song is matched, so user’s libraries can be backed up much more rapidly.

As a means of accessing songs on my iPad, the service works well. However, it was obviously no help for getting music onto my Android phone.

Recently, I wiped my computer whilst ‘upgrading’ the OS (for those contemplating the move from Windows 7 to 8, don’t!). Upon transferring music from my external hard drive back onto my laptop, I realised that I hadn’t backed up my last couple of month’s worth of new songs. No problem I thought, they’ll just download into iTunes once I’ve signed back into iTunes Match – and indeed they did.

However, they downloaded as AAC files (Apple’s proprietary music format), rather than the MP3 format of the original songs. Thinking about this, it makes sense, as the songs were ‘matched’ rather than uploaded but it is a side-affect I hadn’t considered. I had to convert all the songs back into MP3 format for compatibility with my Android phone (and consistency with the rest of my music library).

Whilst the service works as designed, and the matching performs well, the enforced ties to Apple’s devices and formats is a deal-breaker for me, and I’ve cancelled my iTunes Match subscription. Back to the manual external hard-drive backup for now!