CVPM buggy lab with computational modeling
The buggy lab is a staple of modeling and many other physics classes. Take a bunch of tumble buggys, modify a few to run slow (short one of the batteries by wrapping it in foil), and then send students off devise an experiment to measure the velocity of their particular buggy. You can read a more thorough description of this experiment on Kelly’s blog.
I want to describe a particular variation on this lab I’ve created that helps students to see the power of computational thinking. Often, I’ve concluded the buggy lab by asking students to figure out, on the basis of their whiteboards, which buggy would win a race. Then, after the class reaches agreement, we test it. This is a great question I got from Frank Noschese that really pushes students to begin to put their newfound CVPM knowledge to use. But I’d like to push this even further and get students to make their first foray into computational modeling.
I’ve written a lot of about computational thinking and modeling before, and I’ve sometimes had students modify a ready made program so that the motion of the buggy on the screen matches the motion of their actual cart. This only takes two lines of editing (the position and velocity statements), and I think it shows students that they can begin to understand a fairly complicated program just by diving in and playing around.
Still, creating a computer model a single cart doesn’t really do much to highlight the power of computational thinking. What if instead, we could somehow run a race of all of the carts together on the computer? Given that the buggies have a tendency to curve, which often makes a race impossible, being able to create a simulated race where the buggies would move in a straight line is a clear example of building a model that disregards unimportant features (the curving motion) and allows us to predict and visualize a race we might not even be able to carry out in real life.
I don’t really want to force students to learn how to make 8 objects move in their program on the second day of class when many of them have no previous exposure to programming.
What if there were a way to automate this? What if I could write a program to take the student’s changes from their individual buggy code and merge them into a single program to simulate the race? Now that would highlight computational thinking.
Here’s how I managed to get this working.
- Students modify their code to simulate the motion of the buggy they studied.
- Students then cut and paste the two lines of code they modified into a google form.
- A python program running on my machine downloaded the form entries from all of the students and then writes a python program that models the race.
Here’s a video of what the merged program looks like that recreates the original experiment with all of the carts on the same table.
Here’s a video of what the race program looks like—the carts have all be turned to move int he same direction and start from the origin.
How this works
Thanks to Josh, I learned about the awesome googlecl (google command line) interface which lets you do almost anything you can do with google apps on the command line. In this case, I’d like to access and download the form data from my google form into a cdv file.
To do this you must first install googlecl, which also requires you install the Google data python client, gdata. This took a bit of fiddling, as I found some incompatibilities between various versions of googlecl and data, but eventually, I found googlecl-0.9.13 and data 2.0.14 are compatible.
With this installed you can now have python make a system call along the following lines:
os.system('/Applications/googlecl-0.9.13/build/scripts-2.7/google docs get CVPMProgramResponses --format csv /Users/jburk/Dropbox/_archive/_Teaching/_SAS\ Teaching/Courses/Honors\ Physics\ 13-14/01-CVPM/Python')
This is simply telling the os to run the googlecl app, and has it get the responses from the google doc CVPMProgramResponses in csv format and then save the on my machine.
After that, I wrote a python program to generate the two programs. I’ve put all of the necessary python files in this github repo. Be forewarned—this is mostly hacked spaghetti code I wrote to get the program working like I wanted.
A gentle introduction
My hope is that this will be a short 5-10 minute introduction to VPython. Students will see that they can modify large programs and observe how easy it is to manipulate objects in VPython. They’ll also get a taste of the real power of computing to merge all of our programs into a single program and create a more simulation that they can then play with and analyze.