Sniff is a "Scratch-like" programming language that's designed to help Scratchers move gently from Scratch to more conventional languages. They can start writing programs, without having to learn a new language because Sniff is based on Scratch. They learn a little more about variables, compiling, syntax errors (!), and they can have fun controlling real hardware while they're doing it.

Wednesday, 17 September 2014

Wedo physics

I'm really excited about getting the Wedo working with Sniff - it seems to be a missing piece of the puzzle that makes it easier to get in on the fun of physical computing without having to wire stuff up, or worry about class 6B shorting out the GPIO on all your Pi's!

It's been ages since we've done any science here on the Sniff blog, so lets do some basic physics with the Wedo...

One of the really useful parts - perhaps one of the most culturally significant of its day is the discovery of the pendulum. A pendulums period depends on its length, and NOT its mass. That let people build clocks, and measure time accurately - without the pendulum there'd be not time keeping, which rules out accurate navigation (remember the original Longitude prize?), pretty much any kind of science (cause we're always measuring how long things take), no school time tables, and no iWatch. I'm sure you could integrate this into a wider cross curriculum activity about time and timekeeping, but for now lets get back to the experiment.

This is the easiest Lego build ever:At one end we've got the Wedo, and an axle. On the axle is a long brick, which is connected to other long bricks to make the arm. At the end of the arm are a couple of tires to make a weight. A little way down the arm I 've attached the wedo tilt sensor, so that its horizontal when the arm is vertical. Strictly for this to work the arm should be much lighter than the weight - we'll see how that works out...

make wedo device
make wedoConnector number

make wedoValue number
make startTime number

when start
.set wedoConnector to 1
..repeat until wedoValue=1
...tell wedo to "readTilt"
..repeat until not wedoValue=1
...tell wedo to "readTilt"
..say [timer - startTime]
..set startTime to timer

The code is equally trivial. If we ignore the timer code for now, we wait until the sensor is reading one indicating the sensor is tipped forwards, then wait until it leaves that region. At the moment the sensor stops reading 1 we print out the time since we started, then go back ground, and wait for it to happen again.

It turns out to be pretty accurate - our makeshift pendulum is accurate to within a few hundredths of a second. Using the internationally recognised standard of unit of measurement : the Lego Stud, out arm is 49studs long and has a period of 1.2 seconds (give or take about 2 hundredths of a second). 

Taking out 2 of the bars gives us a length of 27studs, and a pretty reliable period of 0.9s.

So what does the maths tell us to expect? Well assuming a "perfect" pendulum, swinging over a small angle, then:

T_0 = 2\pi\sqrt{\frac{\ell}{g}}

Where T is the time period, l is the pendulum length, and g is the gravitational force which on earth is 1226studs per second squared (you may be more familiar with the metric version of 9.81 m/s/s).

Plugging 49 studs into this equation gives 1.25s, while 27studs give 0.93s

WOW!!!!! That's pretty much spot on...

But there's another way to spin this - I knew T and l, and I looked up g (then converted it to Lego). I used that to check my experiment. My experiment was how accurate is a lego Wedo pendulum at keeping time (pretty good!).

But there's something in that equation that we actually might not have known: g. It's been pretty well measured and documented, but when did you last check?

We can rearrange that equation, and using 49studs and 1.2 seconds we get g=1343studs/s/s  (or 10.7m/s/s). That's about a 10% error, which considering the pendulum equation is only an approximation, and we build it out of Lego, that's pretty amazing.