Archive | February 2019

A class on engineering, electronics, and the Maker Mindset

At my school, rather than pass through grade levels, students have levels of autonomy – from “Explorers” who do mostly teacher-directed projects and products, to “Pathfinders” who do almost completely student-created projects and products, and job internships. I’m teaching an “Explorer” level class, so I’m introducing new learners to things they might not have known they would like but we’re asking them to try it. Other teachers with Explorer classes are doing things like creating pollinator boxes, producing a play, and studying floodplains. My venture project is called “Whimsical Inventions” and it’s a class about learning how to be a maker and a tinkerer. I began by presenting content about coding, electronics and circuitry, 3-D design, and doing research… but also teaching about the mindset of an inventor. Inventors solve problems, true, but inventors also make things because making things is joyful. We make stuff that is a little over-engineered because it makes us and others happy. We take everyday things and make them more beautiful, musical, entertaining, weird, or funny. If you’re making a thing to be happy, you’re more likely to take risks, to try something that might not work, to iterate on your design and make it better. This is the premise behind the class. To learn about coding, electronics, design, and engineering for the smiles.

As students finish with their final projects I am just feeling so blessed with the circumstances I got to teach in. The kids have come a long way with coding and Arduino. My makerspace is buzzing with 3-D printers and the laser cutter. Kids solder skillfully and safely. And they are doing a great job cleaning up and putting things away. I was lucky to get a class in which many kids were interested in the topic but many others just got placed there to try something new. My class is evenly split between boys and girls. It’s mixed-age with kids ranging from 6th grade to 10th grade. And I have gifted kids, kids with IEP’s, second-language learners, kids from all areas of town. It is just awesome. When I have a diverse group of learners I am a very happy teacher and this has been a phenomenal group.

And look at some of the fun stuff they’re making! One child is making a 3-D printed ferris wheel with a stepper motor and some LED’s. It’s coming along well! She downloaded the Ferris wheel design from Thingiverse.

Another student is making a motion-activated Moo machine. You know those cylinders that you tip upside down and it moos? He’s going to attach it to a servo and mount it in a stand with a motion sensor on it. When you walk by it will moo at you! Here’s the base beginning to print. He designed it himself!

A pair of students is making a light-up holder for your Instax photos. They’ve learned to solder and program these RGB LED strips and they’re going to mount some clips here to show off their photos. Another girl is using the same idea to make a light-up phone case. She has printed several iterations of the perfect phone case to make sparkly with the LED strips.

I have one pair of students that decided to make their own battery-powered car. They designed the car chassis themselves and soldered together the battery packs and switch and motors, and they’re doing to attach wheels and I’m just so excited to see how it turns out.

It’s just been fun. Part of our requirement for the project is that kids have to do a research project as well, and I’ve found that they really are engaged in their research which I didn’t expect. Early on in the class we did readings and watched videos on the value of tinkering and inventing useless things – we watched videos from Simone Giertz, Adam Savage, Ayah Bdeir and others. One of my favorites is this TED Talk from Steven Johnson which tells the story of how seemingly useless inventions can change the world. I’ve taught electronics classes before, but this is the first time I’ve really focused on teaching the mindset of an inventor, and I really think it has positively shaped the culture of the class. When I reflected on the times I learned the most and grew the most as a maker, those times tended to happen when I was making something I personally cared about but was just a fun side job, a useless invention. I hoped to give my students that same experience. I really believe most of them are, and it’s a very happy class to teach.

Sometimes when I’ve taught engineering classes before, the classes would end up being not very diverse (kids tend to sign up who already know they will like it, and I tended to have mostly boys in those classes), and I never felt like I had time to teach about maker culture. With a diverse class and making the culture/mindset front and center in the learning, it’s been a very fun experience and I can’t wait to show you how the exhibition products turn out.

Advertisements

Pre-calc, Trig, Physics, and Planetary Motion – a coding project

I mentioned earlier that I get the privilege of teaching pre-calc for the first time this year. As a capstone project for our unit on trig, I created a project on planetary motion. It had been on my radar since we studied conic sections and learned about how planetary motion is a real-world example of an ellipse. I browsed around for some examples of planetary motion simulators, and found this one written in Python.

https://fiftyexamples.readthedocs.io/en/latest/gravity.html

The link above uses real-world values for masses of planets and the value of big G, but I thought the students would enjoy “playing God” and creating their own planets and velocities and creating the big G constant for their little universe. In the process we would learn about the physics of planetary motion and about how trigonometric functions can be used to model periodic motion in a coordinate plane. Yay math!

My pre-calc students have not yet had high school physics, so I had the opportunity to set the groundwork for some basic mechanics. I know I gained a lot by watching these little videos from Crash Course and PBS. I had the students watch them both, and we processed them afterward.

 

After this first video, the main mind-blowing concepts were: a) centrifugal force is kind of a “fake force”, it’s just the balancing force to centripetal force that pulls you inward, b) in a circular path, your velocity is tangent to the circle, and c) students knew that force could be described by the equation: F=ma, but after the video we talked about a special version of the formula that describes circular motion, F=mv²/r.

Together we wrote, earlier in the unit, a basic computer program on Khan Academy that made a little planet orbit around a bigger sun using trig functions to find the x and y coordinates. Fun but not an accurate planetary model. I’m not sure if the computer program playback will work here, but here’s the basic model.

animate

https://www.khanacademy.org/computer-programming/animate/5088658953502720/embed.js?editor=yes&buttons=yes&author=yes&embed=yes

Made using: Khan Academy Computer Science

Since we had briefly learned about Kepler’s laws during our unit on ellipses, I told the kids I wanted the model to change so it actually modeled planetary motion – faster when close to the planet, slower when farther away, making an ellipse with the “sun” at one focus. And to do that, we’d have to learn a little about how planets exert force on each other and how that impacts their motion. So we watched the next video.

 

So from this video, we learned many more mind-blowing things. Among them, there is ANOTHER formula for force: F=GMm/r². These formulas are all related to each other. We would now modify our computer simulation to show how they all work.

Ok so here are the basics of programming an animation. This structure is common to pretty much all game programming as well. You have setup code and then an animation loop, that runs over and over again. Most of the time, the animation loop runs around 60x per second.

In the setup code, we initialize all of our variables. In the animation loop, we’ll calculate all of the forces and accelerations and velocities and positions, and once everything is updated, we’ll re-draw the scene. You always re-draw the whole scene from the objects in the “back” (such as the background) to the objects in the “front” (such as the moving planets). For simplicity, my model doesn’t take into account the planet’s effect on the sun… just the sun’s effect on the planet.

Step 1: In the animation loop, draw the background and the sun. In the Khan Academy programming environment, (200,200) is the center of the canvas since the canvas is a 400×400 grid. This code places a circle, 40 pixels in diameter, right at the center. The fill() and background() commands are used for colors.

var draw = function() {
background(0,0,0);
fill(164, 244, 245);
ellipse(200,200,40,40);

};

Step 2: In the setup code, create variables for the sun’s mass and the planet’s mass. I just told the kids to make up numbers, one a LOT bigger than the other, like 100 times bigger or more. I just made these up on the fly. The units are totally fake. Just have fun making up weird numbers.

var smass = 34782;
var pmass = 7.2;

Step 3: We need to place a planet. We’ll create variables for the planet’s x and y positions and draw a smaller circle at that position. I recommended to the students that they place the planet so that it is directly above, below, or to the left or right of the sun. In other words, the x or y coordinate is the same as the sun’s, but the other coordinate is different. My planet starts out 170 pixels ABOVE the sun (because the y axis is upside down).

Setup code:

var px = 200;
var py = 30;

Animation loop (at the end of the var draw function, before the last curly brace)

fill(153, 242, 126);
ellipse(px, py, 10, 10);

Step 4: You’ll need to calculate how far away you are from the sun at any time in order to correctly calculate the force. So make a variable to store this distance, and then re-calculate the distance every frame. Normally you would use the distance formula, sqrt((x2 – x1)² + (y2 – y1)²)  however Khan’s math library has a function called “dist” that simply takes the parameters x1, y1, x2, y2 and returns the distance between them.

Setup code:

var pdist;

Animation loop (before you draw the planet. I added a comment above this to show where we are doing all of the math)

//MATH
pdist = dist(px, py, 200, 200);

 

Step 5: Now we have *almost* all of the information needed to calculate the force on our planet. We know the masses of the two planets and we know how far away they are at any time. We do NOT know big G, our gravitational constant. For now we’re going to make up a number. It’ll be wildly wrong. We will fix it in a bit. We’ll calculate force using our wrong constant for now. The students enjoyed thinking about how when you create your own universe you get to decide things like how big the universal gravitational constant is.

Setup code:

var G = 10;  // just make something up
var pforce;

Animation loop (after you calculate distance but before you draw the planet)

pforce = G * smass * pmass / (pdist * pdist);

Step 6: Now we need to explore the relationship between position, velocity, acceleration, and time. We already have variables for the planet’s x and y position. We will need to break velocity and acceleration down the same way. Velocity is how much the planet’s position changes with each time interval. Acceleration is how much the *velocity* changes with each time interval. If our object starts at the top of the circular path, it begins with a fairly large x-velocity and a zero y-velocity. As it moves around the circle clockwise, the x-velocity and y-velocity change so that by the time it gets around 90 degrees, the x-velocity has slowed to zero and the y-velocity is at a maximum. And the cycle repeats around the circle. A periodic function!

So after position is established we will give our planet a starting velocity. Since my planet started at the “top” of its circular path, I will give it an x-velocity but no y-velocity. A student that put their planet to the side would give their planet a y-velocity but no x-velocity.  When you run this code now, you will see the planet move in a straight line tangent to its circular path. It follows Newton’s first law – no force, no change in velocity. Bye!

Setup code:

var vx = 4;
var vy = 0;

Animation loop (put this code right before you draw the planet):

px = px + vx;
py = py + vy;

 

Step 7: We need to calculate the acceleration in the x- and y- direction every frame. This is where the trig comes in. This step really consists of three substeps. First, we need to find the angle of rotation between the planet and sun. Second, we find the x- and y- components of the acceleration. Third, we add the acceleration to the velocity (remember acceleration is the change in velocity every frame). For the first substep, we can calculate the angle of rotation easily – the planet’s position is a certain y-distance and a certain x-distance away from the planet, so if we use inverse-tangent, we can find the angle. Khan’s math library has a function “atan2” that calculates an angle given the y-distance and x-distance. Note the sun is at (200,200) so that’s why those numbers are hard-coded. Substep 1:

Startup code:

var ptheta;


In animation loop:

ptheta = atan2(200-py, 200-px);

 

Substep 2. Calculate acceleration components. Here we use our original force formula: F = ma. We calculated force, we know mass, so acceleration is easy – just Force / mass. Then we have to multiply that acceleration times sin(theta) for the y-component and times cos(theta) for the x-component. These use the definitions of sin and cos as you relate them to a unit circle. The code!

Setup code:

var ax;
var ay;

 

Animation Loop (after you calculate ptheta):

ax = (pforce / pmass) * cos(ptheta);
ay = (pforce / pmass) * sin(ptheta);

 

Substep 3. This part is easy. Add the acceleration to the velocity every frame. Do this before you re-calculate position in the animation loop.

vx = vx + ax;
vy = vy + ay;

 

You’ll run your code. The planet will either fly off into the unknown or crash into the sun. I encouraged the kids to play with the value of G, but sometimes the animation runs so quickly that it’s hard to even tell if you should dial up G or dial it down. So we had to come up with a better way to find a universal gravitational constant that would make our little solar system dance instead of fall apart.

Here’s where our other formulas for Force come in. For uniform circular motion, the centripetal force that keeps a body in a stable circular path is: F=mv²/r.  For planetary motion, the force affecting the planet and sun can be modeled as: F=GMm/r².   We know all of the variables in both equations EXCEPT a value for G that makes the orbit stable. So set one equal to the other and solve for G. I used some contrived numbers in my model and all of my students had different contrived numbers. Mine were:

M = 34782

m = 7.2

r = 170 (since my planet started at y = 30 and my sun was at y=200 and the x-coordinates were the same)

v = 4 (I just made up a velocity of 4 pixels per frame)

When I solved for G, I got a value of 0.078. So I modified my program and plugged in this value for G and guess what happened? Uniform circular motion and the feeling that I AM GOD of my own little universe.

You can make tiny changes to the planet’s initial velocity, for example change it to 2 instead of 4, and see the planet travel in an elliptical comet-like path instead of a circular path.

Here is the entire working program.

PLANETS

https://www.khanacademy.org/computer-programming/planets/5392591280308224/embed.js?editor=yes&buttons=yes&author=yes&embed=yes

Made using: Khan Academy Computer Science

 

When I taught this lesson, we went through the steps as a class just as I went through them in this blog, discussing them along the way. For a final product, the students will write an essay (!) describing their understanding of the physics of planetary motion. I will also give them a brief quiz. I have not yet written a rubric but will share it when I do.

I really enjoyed working on this little coding project and was so pleased that I could connect periodic functions and the physics of motion. If you make any modifications or try this with your students, please let me know.