Integrating GitHub Pull Requests with TeamCity

JetBrains has a nice article on integrating GitHub, TeamCity, and pull requests.

 

 

Posted in SysAdmin | Tagged , , , , , | Leave a comment

Syntax Plugin Upgrade

I was never really thrilled with the WordPress plugins that use <pre>…</pre> for delimiting code, because of bad mojo between the WordPress editor and <pre>, specifically when the two meet the lowly < character. (Specifically, code can disappear without warning.) I detest having to tip-toe around software; humans shouldn’t have to bend to the code.

I’ve installed SyntaxHighlighter Evolved, which uses the [] notation, and doesn’t care how < is encoded.

Quick documentation can be found on WordPress’ Posting Source Code.

Posted in Misc. | Tagged , , , | Leave a comment

Adafruit Motor Shield

For some proof of concepts we bought Adafruit‘s motor shield kit.

 Assembly

The kit was easy to assembly following the instructions on the ladyada.net site. I recommend heeding the advice to use the 16-pin IC sockets and not soldering the L293D motor drivers to the board unless you’re experienced driving motors.

Use

Some of the information is scattered. For driving motors, Adafruit has a library available on github. Instructions can be found here.

Servos

Instructions for servos is sketchy. There are two servo connectors SER1 and SERVO2. According to the schematic, SER1 is connected to Arduino pin D10, and SERVO2 is connected to Arduino pin D9.

Headers

As the kit is, there is no way to stack a shield on top of the motor shield, or make easy connections for proofing. For my purposes, I added female headers to the shield using the holes parallel to the male headers. An alternative would be to use stacking headers instead of the provided male headers.

Headers added to the motor shield.

 

 

Posted in Micro & Hardware, Robotics | Tagged , , | Leave a comment

Hallowe’en Eyes

This is a small Arduino project our family did for Hallowe’en.

In the old cartoons, dark forests were shown as black backgrounds with mysterious eyes that would glow in the dark, often blinking or opening and closing.

Hardware

The electronic hardware is very simple: multiple Arduino digital outputs sporting 330Ω resistors and an LED.

Schematic Overview

Mounting the Eyes

Each LED is mounted in a cardboard toilet paper tube with eyes cut out.

  1. Hold the tube horizontally in front of you.
  2. Cut large eyes in the middle of the tube. Use your imagination to get different expressions.
  3. Cover the eye openings with wax paper or cooking papyrus to act as a diffuser.
  4. Secure with tape.
  5. Cover the ends of the tube with aluminum foil and secure with tape.
  6. Make a hole directly opposite the eyes, and mount the LED, ensuring it’s pointing between the eyes.
  7. Secure the LED with tape.

Run pairs of copper wire from where the eyes will hide in the bushes to the Arduino. (Ensure the Arduino is protected from the weather. I put mine in a small cooler.) Check all connections and connect the battery to the Arduino.

Be sure to use a battery that has enough capacity to run all the lights and the Arduino for several hours. I used a small hobby 6V lead-acid battery.

Software

This is a glorified “blink” program; nothing amazing going on here.

The software consists of a simple coöperative multitasking core that runs simple processes in a round-robin fashion.

Each process has a references to a master array oftapes, or eye programs.

  1. If the processes is sleeping and has not reached its wake time, return.
  2. If the process has no active tape, or reached the end of the tape, choose a new tape at random from the master array of tapes.
  3. Play the instructions at the current tape position.
    1. Turn the LED on or off, as instructed.
    2. Choose a future wake-up time as instructed.
  4. Increment the current tape index.
  5. Return.

As you can see, there’s nothing terribly complicated about any of this. The software may be found on GitHub here.

Posted in Micro & Hardware | Tagged , , | Leave a comment

Including Libraries in the Arduino IDE

There’s an annoying subtlety in the Arduino IDE when using tabs (multiple files in the sketch), that was kindly explained by PaulS on the Arduino forums.

Any Arduino libraries that are needed by the files outside of the sketch (.ino) file must also be listed in the sketch file itself.

Example

You cannot simply do this:

example.h:

#include <Servo.h>

When you attempt to compile, you’ll get an error like,

In file included from test_junk_02.cpp:1:
test.h:7: error: 'Servo' does not name a type

You must also include the library in the sketch:

test.ino:

#include <Servo.h>
#incude "example.h"

Explanation

The explanation that PaulS gave was the following:

The sketch is parsed for include files. The sketch, all included header files, and the corresponding source files, are copied to another directory for compiling. From that directory, library-based include files are NOT available unless they are included in the sketch and copied to the build directory.

Posted in Micro & Hardware, Programming | Tagged , , , , , , | Leave a comment

C++ Polymorphism vs. Arduino

There’s a subtlety in C++’s virtual mechanism that I’ve run across twice now. Many other languages don’t have this problem, but C++ is close enough to the bare metal that this is a problem.

In the world of the small, where you have kilobytes of memory to work with, how you program changes dramatically. It’s highly advisable to avoid dynamic memory operations if at all possible. Global variables and class instances are very common.

For a project I wrote a simple, minimal coöperative multitasking core for the ATmega328P, the microcontroller in the Arduino Uno. Being pleased that it worked well enough, I turned the scheduler and process classes into Arduino libraries. The classes were renamed from “Scheduler” and “Process” to “SCMScheduler” and “SCMProcess”, where SCM stands for Simple Coöperative Multitasking.

The intended idea was that each process would descend from SCMProcess, and the scheduler would be initialized with an array of process class instances. The scheduler is very simple and only calls SCMProcess::execute() to pass control over to the next process.

In the original implementation, the scheduler received an array of Process class instances to operate on. (Each process executed identical code, so only one class was necessary.)

#define PROCESS_COUNT 10
Process processList[PROCESS_COUNT];
Scheduler scheduler(processList, PROCESS_COUNT);

The Scheduler’s constructor looked like:

class Scheduler
{
public:
Scheduler(Process* aProcessList, byte aProcessCount) …

There was no class inheritance involved, so the main loop worked without a hitch:

void Scheduler::run()
{
selectNextProcess();
processes[current].execute();
}

When I abstracted the Process class into a parent (SCMProcess) and a descendent (Process), this broke terribly. (If you’ve had your head in C++ for a long time, you’re probably cringing already.)

The old Scheduler class was removed entirely, and its code lifted to the new generic SCMScheduler class. The constructor was changed to:

class SCMScheduler
{
public:
SCMScheduler(SCMProcess* aProcessList, byte aProcessCount) …

The process class was split into two pieces, the generic base class and the application-specific class:

class Process : public SCMProcess …

The man body of code was only changed to use the new SCMScheduler class.

#define PROCESS_COUNT 10
Process processList[PROCESS_COUNT];
SCMScheduler scheduler(processList, PROCESS_COUNT);

In most other languages, declaring an array of descendents (Process[]) and passing it to a function that expected an array of parents (SCMProcess*), this is not a problem.

In C++, the symptom I saw was code execution that seemingly wandered though memory at random, resetting the machine over and over. At first it was terribly frustrating until I remembered back to something similar biting me the 1990′s.

For polymorphism to work in C++, you have to pass pointers to the parent class type. You can’t pass references or arrays of class instances. The nitty-gritty details of C++ make this impossible.

The correct constructor for the scheduler is:

class SCMScheduler
{
public:
SCMScheduler(SCMProcess** aProcessList, byte aProcessCount) …

The main body of code required me to conceded to using the new operator as a balance between machine space constraints and human labour constraints. (Note that I altered the constructor of the Process class for unrelated reasons of convenience.) I may rework the code so that I’m not using new, but for the time being it’s acceptable.

#define PROCESS_COUNT 9
SCMProcess* processList[PROCESS_COUNT] =
{
new Process(13, Catalogue, CATALOGUE_COUNT),
new Process(5, Catalogue, CATALOGUE_COUNT),
new Process(6, Catalogue, CATALOGUE_COUNT),
new Process(7, Catalogue, CATALOGUE_COUNT),
new Process(8, Catalogue, CATALOGUE_COUNT),
new Process(9, Catalogue, CATALOGUE_COUNT),
new Process(10, Catalogue, CATALOGUE_COUNT),
new Process(11, Catalogue, CATALOGUE_COUNT),
new Process(12, Catalogue, CATALOGUE_COUNT)
};

SCMScheduler scheduler(processList, PROCESS_COUNT);

…

void loop()
{
scheduler.run();
}
Posted in Micro & Hardware, Programming | Tagged , , , , | Leave a comment

Multiple Source Files with the Arduino IDE

Granted, the Arduino IDE isn’t conducive to heavy-duty projects, but it’s useful for quick and dirty programs.

Once you outgrow a single file and wish to break the project up into multiple files, you can do so in the Arduino IDE with multiple tabs. Each tab represents a single file stored in the same directory as the sketch file (.ino).

You create new tabs using the drop-down menu that appears by clicking on the inverted triangle above the upper right-hand corner of the editor.

Showing the Tab Menu in the Arduino 1.0.1 IDE

Note that unlike the sketch’s main .ino file, you will not have automatic access to the Arduino basic definitions. That is easily remedied by including

#include "Arduino.h"

Happy Hacking.

Library Warning

Please note that there is a quirk in the Arduino IDE that can prevent libraries from being included in the compile. The IDE requires all libraries to be #include’d in the main (.ino) file. If you do not do this, the library will not be included, and you’ll get errors during compile.

How It Works

When compiling, the IDE copies all the files to a temporary directory. It scans the .ino file for libraries, and copies the library files to the temporary directory. Finally, it does the actual compile. If you #include a library in any of the tabbed files, but not in the .ino file, the library will not be available to the parser. The IDE only scans the .ino file for libraries.

 

Posted in Micro & Hardware, Programming | Tagged , , , , , | 1 Comment

Hardware Nearly Complete

I’ve been working on a small robot on occasion to exercise some professional skills and simple personal enjoyment. The robot’s purpose is simple — point the sensor board toward the strongest light source.

I’ll post more information when I haven’t more pressing things. These are just pictures for “show and tell”.

Hardware

The hardware is pretty much complete at this point. The mechanical portion consists of four light sensors and two servos.

Mechanics and Sensors

The control board consists of a power regulator, ATmega328P microcontroller, and voltage dividers for the sensors to turn resistance into voltage. There is an optional connector for serial diagnostics. There is a connector in the far right corner for in-system programming (ISP). I’ve been doing some tutoring, and have a number of microcontrollers with stickers that document the pins names that correspond to the Arduino Uno platform.

Component Side of the Control Board

The wiring is done by hand. I use a wirewrap tool to make the initial mechanical connection for soldering. Leads for ICs &c. are typically far to short to use plain wirewrap.

Underside Showing the Wiring

Software

I’ve done proof-of-concept and diagnostic software up to this point. I’ll do testing to ensure the basic functionality is working correctly still, and work on the firmware in earnest.

 

Posted in Micro & Hardware, Robotics | Tagged , , , , | Leave a comment

What is Unicode?

Internationalization and localization have been long-time interests of mine, and I’ve had the privilege to delve deep into it with a large project for the last year. I submitted the following comment on the Real-World Haskell site in hopes that it would be of value for future readers.

In response to Phil’s question, and for general information for those not familiar with Unicode:

Unicode consists of “code points”; numeric values that represents a character or meta-character. This is purely an abstraction that dictates no specific digital representation.

How those numeric values are encoded and stored digitally is a separate issue. The main three encoding systems follow.

UTF-32 uses 32 bit “characters” to store each code point. A pro is that each “character” corresponds exactly to a code point.  A con is that for English text, this quadruples the amount of storage space required, filling memory with a lot of zeroes.

UTF-16 uses 16-bit “characters” to encode code points. It requires either one or two “characters” to represent the entire Unicode set, with the most common values requiring a single “character”. A pro is that it’s more space-efficient than UTF-32. A con is that it’s a variable-length encoding system.

UTF-8 uses 8-bit “characters” to encode code points. It’s designed to be a superset of ASCII. It requires between one and four bytes to encode the entire Unicode set. A pro is that plain ASCII is UTF-8; no conversion is required. A con is that it’s a variable-length encoding, and is inefficient for Asian languages compared to UTF-16 (requiring 3 bytes rather than two for most Asian text).

Posted in Programming | Tagged , , , , , , | Leave a comment

Handy Unicode Tools

In my internationalization and localization work, I have to ensure that UTF-8 is being correctly generated and stored.

The hixie.ch UTF-8 decoder is very flexible on the input it accepts and shows the internals of the decoding.

The rishida.net conversion tool is useful for converting formats.

 

Posted in Programming | Tagged , , , | Leave a comment