Archive for July, 2011

C++ Vectors [quick overview]

Saturday, July 9th, 2011

Vector is a dynamic container type in OpenFrameworks (and C++) that is able to hold multiple elements of the same type. It functions like a special type of array that can be expanded and contracted while the application runs. Vector elements are stored in contiguous locations so they can be accessed easily using operators, iterators, and pointers. You can download a pdf version of this tutorial here. Here is a link to the C++ vector reference page.

Declaration
When you declare a vector you need to specify the type of data that it will contain. This enables the compiler to know how much memory to allocate to a vector instance.

syntax: vector < data_type > vector_name;
example: vector < ofTouchEventArgs > touches;

Add Element
To add a new element to the end of a vector you use the push_back() method. This method accepts an object as an argument. This object is placed at the end of the array. The object must be of the appropriate data type, otherwise you will receive a “No matching function” error.

syntax: vector_name.push_back(new_object);
example: touches.push_back(touches);

Get Element
To access objects from an Vector you can use several different approaches. The most common ones are the operator [index] and the at(index) method. The difference between these approaches is that at() throws an exception if the index is out of range).

syntax: vector_name[index]
example: touches.at(index)

Iterators and pointer math can also be used to access objects from a Vector. To learn more about how to use these approaches check out the C++ reference website.

Remove Element
To remove elements from a Vector the best approach is to use the erase() method. This function takes an iterator as an argument. The vector methods begin() and end() both return iterators; the former returns an iterator that points to the first element in the Vector, the later returns an iterator that points to the last element in the Vector.

syntax: vector_name.erase(iterator);
example: touches.erase(touches.begin() + i);

You can also use the pop_back() function to remove the last element from a vector.

syntax: vector_name.pop_back();
example: touches.pop_back();

Vector Iterators
An iterator is an object that has the ability to iterate through the elements of a range, such as a vector or array. Vectors have a special iterator that can go through its elements using operators such as increment (++) and decrement (–). Iterators are used as input arguments for several of the modification methods in the vector class and for looping through all the elements in an array.

To get an iterator from a vector you can use the begin() and end() methods. These methods return an iterator that resolves to the first and last positions of the vector respectively. Below is sample of code that demonstrates how to use an iterator to loop through the elements in a vector.

vector my_vector;
  for (int i=1; i<=5; i++)
    my_vector.push_back(i);
vector::iterator my_iterator;
  for (my_iterator = my_vector.begin(); my_iterator < my_vector.end(); ++my_iterator)
    cout << " " << * my_iterator;

Random Stuff
Here is a brief overview of a few other vector methods worth knowing about. Check out the full reference for more information about vectors.
- empty(): checks if a vector empty, and returns true if it is.
- size(): returns the number of elements in a vector.
- capacity(): returns the amount of space allocated to the vector.

Thank You
I hope this short tutorial has been helpful since the reference pages can sometimes be a bit cryptic. If you have any comments or questions email me at julioterra at gmail dot com.


Open Frameworks [intro to building apps for iOS]

Friday, July 8th, 2011


This past weekend I attended a one-day workshop to learn how to create applications for iOS devices using Open Frameworks. During this intimate session led by ITP veterans Amit Pitaru and David Nolen we covered a lot of ground, though of course we barely scratched the surface of the iceberg (if I may mix my metaphors).

We started the day by getting an overview of Apple’s iOS Model View Controller (MVC) model, and how Open Framework applications fit into this framework. Then we dove into xCode to get OF and the iOS SDK up and running. The last half of the workshop was spend working on iOS apps, which involved little more then touch tracking.

I have created a nice 8-page presentation using my notes from the workshop. These slides focus on how to get Open Frameworks set-up so that you can create applications for iOS devices in five relatively easy (though not necessarily quick) steps. [download a pdf version here]

I plan to write a post about Apple’s implementation of the Model View Controller framework in the next couple of weeks, as soon as I have my head wrapped around it better.


Stackables [laser cut stackable bins]

Tuesday, July 5th, 2011

Stackable [photos]

A few weeks ago I went out looking for a set of stackable bins. I was looking for bins for my work table, which is located in my small apartment’s living room/office; so I wanted to find something that looks good. After spending a many hours searching on google, amazon, container store, and ebay I decided to design my own set of bins.

Stackables were created to store small electronic components for my physical computing projects. This includes a wide range of resistors, capacitors, switches, leds, pots, sensors, ICs, wires, etc. I designed Stackables so that they can be easily and securely stacked and re-arranged.

Each bin measures 3″ wide x 3″ tall  x 6″ deep.  The internal dimensions are slightly smaller, 2.75″ x 2.5″ x 5.75″. The bins were designed to be assembled using 1/8″-thick acrylic sheets.

I’ve posted the details of this project on thingiverse. There you can find the laser cut files along with instructions on how to create your own stackable. If you do decide to build one, let me know how it goes.

Here is a slideshow of photos from my first Stackable prototypes:


AMUP air [ableton midi map]

Monday, July 4th, 2011

In preparation to finalize the code for each AMUP component I have developed the midi maps below. These maps assign every button, switch, and sensor to an action and, where appropriate, to a midi message.

For the monome I am using the standard midi message set-up from MonomeSerial. Under this configuration the monome outputs midi note on and off messages on channel 1. Notes 1 through 64 are assigned to the monome buttons.

Though this may be a bad decision, I have decided to completely disregard existing midi protocols. I am using control messages across channels one through four to control tracks one through four. The control messages within each channel are grouped by function:

  • mixer functions: control numbers 1 – 10;
  • device functions: control numbers 11 – 20;
  • clip functions: control numbers 21 – 30;
  • multi-function: control numbers 31 – 40.

Transport control messages are sent on channel 16, using control numbers 1 – 10. Below is a detailed midi maps of the AMUP component and monome controllers.

AMUP MIDI Map
amup air midi map

Monome MIDI Map
monome midi map


FabLab Tutorial [laser cutter & engraver - first draft]

Monday, July 4th, 2011

Late last week I finished the first draft of the tutorial for the Epilog Mini laser cutter and engraver from the Sustainable South Bronx (SSX) studio. I am designing this tutorial to help the staff and students at SSX learn how to use the Epilog Mini.

To help make it easier to use the Epilog Mini, I have saved the settings for cutting and engraving the most common materials. I have also created laser template files for both Illustrator and Inkscape. Here is the tutorial draft followed by links to the laser template files. [download the pdf version of the tutorial]

Tutorial Slideshow

Laser Template Downloads:
inkscape laser template || adobe illustrator laser template


Arduino Switch Library [digital and analog switches handling]

Monday, July 4th, 2011

To support the new modular design of AMUP I needed to find an efficient way to handle various types of switches across multiple different components. With this in mind, I decided to create a library for Arduino that features 9 separate classes that are able to handle different types of inputs such as switches, buttons, rotary encoders, potentiometers and proximity sensors.

The benefits provided by this library includes that all input types can be integrated using the same design pattern into your code. Debouncing and smoothing functionality is also integrated into these classes to help filter noise.

Here is an image that shows the class hierarchy for the AMUP Input Library, followed by a short description of each class. The code for this library is available here on github. Feel free to use and change this code, but at your own risk.

AMUP library hierarchyAMUP library descriptions