Saturday, January 24, 2009

I Got a Free Whiteboard

It had obviously been used in the gym, since it had instructions to add your name to the wait list for machines, which had been on the board for enough years that it couldn't be erased. I tried the usual tricks; water, white board cleaner, writing over it with new pens, and only the pens worked, but would have taken forever to get it all off. I finally remembered that I have a little bottle of Simple Green in my tool box, and that did the trick (with a 10 minute soak). There are a few scratches on the surface, but for free, its still a good deal.

10 points if you can figure out what circuit that is! Note: It runs on 9-12 volts DC.

Friday, January 16, 2009

Talked to my Adviser

I almost forgot; Wednesday I went to talk to my adviser. Granted, we're required to meet with them every year, since the University has written all engineering majors a blank check as to how many units we can take before graduating, and they want to get us the hell out of here. The unit requirement to graduate is 180 units, my major is 188.

What is exciting about this is that I actually had something to talk to her about. I've finally recovered from the horribleness that was my vector calculus professor, and retalked myself into maybe getting a math minor. My major requires almost all of the lower division math required, so I only have to take one extra class before I can start working on 5 upper division classes, which is all that it requires.

Now all I have to do is figure out which of the classes I want to focus on...

Thursday, January 15, 2009

Bounce a Ball

As I was reading through my feeds today, one of my teacher blogs (not actually ever my teacher) stuck out to me. Kate relates a problem where she had her students try and mark a place on the wall to bounce a ball into the hands of another student (or close enough to catch). At the end, she says she might post a solution in a few days, but I thought I would take a crack at it first.

Granted, my solution isn't really for the problem as she presents it. I also realize that trying to solve any problem with two bounces off the wall and the floor, and in three dimensions, was going to get very ugly, very fast. I am instead solving the somewhat easier problem of:
Given the position of a mark on the floor and another student, in two dimensions, what is the velocity vector required to get the ball to bounce off the floor and land in their hands from a fixed initial position?

Of course, we're going to make all kinds of grandiose assumptions about zero air friction, 100% elastic bounce off the floor, etc, because this is math, not real life (As an engineer, I live to suffer the consequences of this reality).

Given:
All that we are given is our initial position (x0, y0), the position of the mark on the floor (Fx, Fy), and the position of the other student's hands (Sx, Sy).

We need to find the velocity vector V = 〈Vx, Vy

Assumptions:
  • There is no acceleration in the horizontal direction
  • Acceleration in the vertical direction is 9.8 ms2 downwards
  • The ball is essentially a point mass
  • There is no friction or energy lost due to bouncing.
  • The student will catch the ball regardless of the direction it is moving, as long as it passes through the point (Sx, Sy).
Which means that after you do the integration, the position of the ball (x, y) as a function of time (t) is:
x = x0 + Vx t
y = y0 + Vy t - 4.9 ms2 t2


Solution:
Along with the two dimensions of the velocity vector, we're also going to need to know the times when the ball bounces (tb) and when it is caught (tc). This means we're going to need four equations.

The first two for when the ball hits the floor are fairly trivial:
Fx = x0 + Vx tb
Fy = y0 + Vy tb - 4.9 ms2 tb2


Yeah! Basic ballistic motion! Now as for when the ball is actually caught, this is where it starts to get gnarly. When the ball bounces (at time tb), its vertical velocity simply reverses (∴ the new velocity is -[Vy - 9.8 ms2 tb]):
Sx = x0 + Vx tc
Sy = Fy - [Vy - 9.8 ms2 tb] tc - 4.9 ms2 tc2

Yikes... But on the bright side, we now have four equations, and four unknowns (tb, tc, Vx, and Vy), so we can solve this! Solving the x position equations for t is fairly easy, and can be used to substitute out both of the t variables right away:
tb = [Fx - x0] ⁄ Vx
tc = [Sx - x0] ⁄ Vx

And by luck, solving the new equation for when the ball bounces for Vy is fairly easy. So here is the two equations we're left with to solve for V:
Click to enlarge.

So I'll leave substituting the first equation into the second and solving what looks to quite possibly the worst quadratic function ever for Vx as a problem for the reader (read: I'm freakin not going to do it!). Of course, these two equations should still work fine if you give it an impossible setup (mark and student on opposite sides, student in front of mark, etc), it'll just start giving you solutions that are complex.

Can you appreciate why I didn't want to do it in three dimensions with two bounces? I still think this is a fairly honorable hack at the problem.

Sunday, January 11, 2009

Spent the Day at the Western Railway Museum

So since this is the first weekend of the quarter, I decided to take advantage of my general lack of challenging homework and spend Saturday working on the track crew for the Western Railway Museum. Granted, the WRM is in the middle of nowhere, but those are the best kind, and a 50 minute drive sure beats a 6-8 hour drive to Portola.

This was the second time I've worked down there, the first time being this past summer with my dad. The drive from Davis was pretty exciting, if by exciting, you really mean terrifying. After I turned onto 113S from 80W and got out of Dixon, I hit a fog bank that went pretty much all the way to Rio Vista Junction. That wouldn't have been that bad, except there is a 90 degree turn in the middle of 113.
I knew it was coming, but it still caught me by surprise in the fog, and there was a freakin car parked right where I wanted to completely miss the turn and go straight, but I managed to not hit it (freakin car! who parks their car in the middle of the dirt road in the middle of nowhere?!?). Lesson learned; when it's foggy, be an ass and go 25mph, not the speed limit, or the 35mph that I was going, which still wasn't slow enough.

Once I got to the WRM, I met up with Joel Cox and the rest of the track crew, and we got to work. First order of business, get one of the shed doors closed that had hung up on itself. This meant moving a lot of maintenance of way equipment and a steam engine tender. All of the MOW equipment could be moved under their own power, but for the tender we had to get out the 44 tonner diesel (which is the only non-electric engine they have). It was interesting to finally see a 44 tonner running, and Joel even let me run it (under his close supervision), which was impressive since this was my second day. Once we had all the equipment moved, we brought a forklift in, took the weight off the cabled holding the door up, disconnected them, and lower the door.

The next order of business, which took up most of the day, was replacing broken joint bars out about two miles on the main line (WRM has 22 miles of right of way! Lucky ducks!). Joint bars are the plates bolted to the ends of pieces of track to hold them together. The five of us worked a good five hours on this, and managed to get aboout eight bars replaced, which is a healthy rate. The fact that it was foggy in the morning didn't help, because now the track was cold and a little shorter than it should be, making lining the holes up quite a challenge.

Over all, it was a good day. It's always refreshing to get to go out there and work my ass off for a day and be able to come back and say I accomplished something. One of the guys even gave me a CD with pictures of the crew from last year, which included a few shots of my dad and me when we were there in July.
That is Dad and me on the left, and Joel running the tie puller inserting ties on the track. In July, we replaced rotted out ties that had been reduced to little more than tanbark. Of the 20 ties we replaced, we probably got eight big chunks of wood. The rest was removed with shovels. One of the guys found me one of the nails they used to put in the end of the ties to indicate which year they were installed. It was from 1945.

Saturday, January 3, 2009

Setting Up LVM in Linux

Logical Volume Management: A system that allows you to group several hard drive partitions together, and then create arbitrary virtual partitions on top of it. This is super nice because when you run out of space on your hard drive, just add a second one, and instead of dealing with the C: and D: stupidity of Windows, just grow the file system onto the new hard drive invisibly. Want a bigger hard drive, without ever turning off the computer? Plug it in, add to the disk pool, migrate the partition onto it, grow to fit new hard drive, remove old one (note: only works with hot plug hardware, but even without it, still more convenient than the alternative).

Like always, I'm doing all of this in Ubuntu Linux (In this case, Ibex 8.10). Another outstanding guide for this is the Howto Forge's article.

Do realize that LVM is super confusing, so before anything else, have a good time reading the Wikipedia article to get the terminology straight:
  • Physical volume: The real partitions on each individual hard drive.
  • Volume group: The collection of physical volumes.
  • Logical volume: The imaginary partition made from the pool of physical volumes in the volume group.
Realize that LVM is below the file system, so once you create a logical volume, you need to format it before its useful.

My Setup
Two hard drives, sda (120GB) and sdb(100GB). You can have most of the file system (except the /boot/ folder) in LVM, but I'm lazy (and the installer borked) so I first just installed Linux in a 10GB partition on sda, created a 1GB swap space on sdb, and left the rest of it as empty space. The goal here is to make one huge /home/ partition between these two hard drives, giving me about 200GB of storage space. If I need to grow it later, I can take out my CD drives (who uses them after installing Linux anyways?) and install two more hard drives.

sudo apt-get install lvm2

Setting up the Physical Volumes
Now we need to create physical volumes (PVs) on the two hard drives to add to the volume group (VG). Using fdisk, create a partition on each, labeled for LVM:
sudo fdisk /dev/sda
and create a new primary partition, numbering it something not used. (Press m for a list of commands, in thiss case I pressed n enter p enter 2 enter) Use all the free space by hitting enter two more times. Set the partition type by pressing t, and select the partition you just created (2 in my case). Press L to list all the codes, but we just want 8e. When done, w to save and exit. Do the same thing for /dev/sdb as well. Both times, fdisk should crap out with a "WARNING: Re-reading the partition table failed with error 16: Device or resource busy" so reboot to detect the new partitions.

At this point we have:
  • /dev/sda1 (10GB): root for the Linux system
  • /dev/sda2 (~105GB): unformatted
  • /dev/sdb2 (~95GB): unformatted
  • /dev/sdb3 (1GB): swap space
The partition numbers are totally arbitrary (1-4), so if yours are different, just keep track of them.

Now turn these empty partitions into physical volumes:
sudo pvcreate /dev/sda2 /dev/sdb2
and check them with
sudo pvdisplay

Setting up the Volume Group
Now that we have the PVs setup, create a Volume Group to add them to. Once that is setup, we can create the final logical volume to format as a normal file system. We need to name the VG, and I usually just name it after the computer, KWF4 in this case, but you can name it whatever you want.
sudo vgcreate KWF4 /dev/sda2 /dev/sdb2
and check it with
sudo vgdisplay (surprised?)

Setting up the Logical Volume
We now have what appears (through a virtual disk driver) to the computer as a 194GB unformatted hard drive. We now need to create a LV on it to hold the /home/ file system, which I am so cleverly naming "home." I am using the total size of the VG (194.70GB), but that isn't required. You can setup several smaller partitions, but I'm not doing anything that complicated.
sudo lvcreate --name home --size 194.70GB KWF4
and check it with (wait for it...):
sudo lvdisplay

Notice that it lists the LV as /dev/KWF4/home. The LVM driver makes it appear as a normal partition to Linux, which is pretty cool. It's times like these that I really love Linux more than Windows.

Formatting the LV
With the logical volume all ready to go, all we have left is to format it with a file system, and add it to /etc/fstab so it gets mounted every time we turn on the computer. I'm using ext3, since it's standard and I don't have any special need for anything else (Reiser4, XFS, and ext4 come to mind)
sudo mkfs.ext3 /dev/KWF4/home
And since this thing is 200GB, I reset the auto-fsck count to a larger number
sudo tune2fs -c 75 -i 365d /dev/KWF4/home

Finally, add this line to /etc/fstab so the new home partition gets mounted on every reboot.
/dev/KWF4/home /home/ ext3 relatime 0 2

I also mounted the new partition and copied my home folder from the original install as well.
cd /home/
sudo mkdir temp
sudo mount /dev/KWF4/home temp
sudo cp -r kenneth temp/ (This borked on kenneth/.gvfs, still seemed to work fine though)
sudo chown -R kenneth:kenneth temp/kenneth/

And hopefully everything worked and we're done! Now reboot, and run mount to make sure everything worked. (Look for a /dev/mapper/KWF4-home on /home line)


Edit (1/5/09): Something is broken. It all worked fine until I hit Gigabyte #106, which seems to line up just right with the second hard drive, which I know works[1]. This is the first time I've used a slave device on this particular computer. The swap partition worked though, which is driving me nuts. LVM driver problem? Some other error which happens to line up? All I know is that the whole computer locks up and the HHD activity light is full on, with no activity.

[1] Yeah, I know; a little piece of me died when I made that assertion.

Friday, January 2, 2009

Link Dump

I know these are a slippery slope, so know that I don't expect (or want) link dumps to come in any kind of regular interval. Happy New Years. Enjoy these interesting tidbits from my time on the tubes:

Build an 80m Morse code transmitter out of a CFL bulb.
An interesting set of slides from an intro to cryptography class.
Trick to have all SSH traffic for each host through one TCP connection.
Crazy video of an aluminum block in an MRI.
A freakin chair stuck in an MRI.
Rule 110, which I'm going to need to play with at some point.
Where the hell is Matt? Turns out, not very many places...