Posted on

Linear Motion from a Rotary Actuator

Locked State
Box lid prototype in the locked state

This is part of a project I have been playing with on and off for the last 9 months. It is similar in concept to a reverse geocaching box but with cooler locking mechanism. I have always appreciated the giant vault door bolt mechanisms and figured designing a laser cut version controlled by a servo would be an interesting learning exercise.

To accomplish the desired effect I had to solve a fairly simple geometry problem for the linkage mechanism. I figured this might be of use to someone else or my future self so I will walk through the derivation of the basic equations for finding functional linkage lengths.

Continue reading Linear Motion from a Rotary Actuator

Posted on

Selecting Random Items in Amazon SimpleDB

I am in the middle of working on a project that relies heavily on the ability to select random items from an Amazon Web Services SimpleDB domain. A little bit of google-fu turned up an answer to a post over at Stack Overflow which described Amazons recommended approach. A really rough psuedo-code implementation looks like this:
Item selectRandomItem() {
// Generate a random value
String randomValue = generateRandomString();

// Retrieve the data from SDB
Item item = randomLE(randomValue);
if(item == null) {
// Handle the edge case where there are no items
// with randomizers less than the random value
item = randomGE();
}
return item;
}

Item randomLE(String randomValue) {
return sdb.select(
"select * " +
"from MyStore " +
"where randomizer <= '" + randomValue + "'" +
"order by randomizer desc " +
"limit 1"
);
}
Item randomGE(String randomValue) {
return sdb.select(
"select * " +
"from MyStore " +
"where randomizer >= '" + randomValue + "'" +
"order by randomizer asc " +
"limit 1"
);
}
The algorithm stores a randomizer field with a random value on all of the items; when you need a row, generate another random value and select the first item whose randomizer attribute is less than this new random value. Unfortunately this approach is broken. Continue reading Selecting Random Items in Amazon SimpleDB