I used ScreenToGif to record this. Free software! Wow. https://screentogif.codeplex.com/
Annie Ye's Academic Musings
School related stuff, project I'm working on, other thoughts
Friday, June 26, 2015
Gifs
I'm seriously in awe of the technology at my fingertips.
I used ScreenToGif to record this. Free software! Wow. https://screentogif.codeplex.com/
I used ScreenToGif to record this. Free software! Wow. https://screentogif.codeplex.com/
Hilarious pictures
I don't quite remember where these are from but they're just wonky pictures.
This trail though....?????
Red is supposed to be total energy. ????? LOL
It's stuck
Weird paths...
Stuck in a circle huh
Hey, it looks consistent
wiiibbly wobblllyyy
June 26: Energy graphs
The last time I tried writing some code for adding energy it didn't really work so today I just focused on the accounting.
There's probably a better way to display the code but I'll just dump it here:
from __future__ import division
from visual import *
from visual.graph import *
## INITIAL CONDITIONS
r0 = 3 ## meters, relaxed length of spring
theta0 = math.radians(106.35) ## free angle
h = 5 ## meters, initial height of ball
vx0 = 6 ## initial horizontal velocity
## DEFINE SPRING
initialaxis = vector(r0*math.cos(theta0),r0*math.sin(theta0),0)
spring = helix(pos=(initialaxis.x,h - initialaxis.y,0), axis=initialaxis, radius=0.6,color=color.yellow)
spring.constant = 90 ## N/m
## DEFINE BALL
ball = sphere(pos=(0,h,0), radius=1,make_trail = True)
ball.mass = 1 # kg
ball.velocity = vector(vx0,0,0)
ball.acceleration = vector(0,0,0)
ball.force = vector(0,0,0)
floor = box(size=(50,.1,2),pos=(0,0,0))
## OTHER DEFINITIONS
accelOfGrav = vector(0,-9.8,0) ## acceleration of gravity
K0 = 0.5 * ball.mass * vx0**2
Ugrav0 = ball.mass * 9.8 * h
energy0 = K0 + Ugrav0 ## joules
dt = 0.005
t = 0
## GRAPHING
graph1 = gdisplay()
energygraph = gcurve(color=color.red)
Kgraph = gcurve(color=color.green)
Ugravgraph = gcurve(color=color.white)
Uspringgraph = gcurve(color = color.yellow)
positiongraph = gcurve(color=color.cyan)
while True:
rate(100)
t += dt
ball.force = ball.mass * accelOfGrav
## STANCE PHASE
if ball.pos.y < initialaxis.y:## when spring touches floor
spring.pos.y = 0.1
spring.axis = ball.pos - spring.pos##update spring length
spring.displacement = initialaxis.mag*norm(spring.axis) - spring.axis
## ENERGY ADDITIONS/SUBTRACTIONS
dEnergy = energy0 - energy
springForce = spring.constant * spring.displacement
ball.force += springForce ## update force on ball
## FLIGHT PHASE
else:
spring.pos = ball.pos - initialaxis ##update spring position
spring.axis = initialaxis
spring.displacement = vector(0,0,0)
ball.acceleration = ball.force/ball.mass
ball.velocity += ball.acceleration * dt ##update ball velocity
ball.pos += ball.velocity * dt ##update ball position
## ENERGY ACCOUNTING
K = 0.5 * ball.mass * ball.velocity.mag**2
Ugrav = ball.mass * 9.8 * ball.pos.y
Uspring = 0.5 * spring.constant * spring.displacement.mag**2
energy = K + Ugrav + Uspring #calculate current energy
## UPDATE GRAPHS
energygraph.plot(pos=(ball.pos.x,energy))
positiongraph.plot(pos=(ball.pos.x, ball.pos.y))
Kgraph.plot(pos=(ball.pos.x,K))
Ugravgraph.plot(pos=(ball.pos.x,Ugrav))
Uspringgraph.plot(pos=(ball.pos.x,Ugrav))
There's probably a better way to display the code but I'll just dump it here:
from __future__ import division
from visual import *
from visual.graph import *
## INITIAL CONDITIONS
r0 = 3 ## meters, relaxed length of spring
theta0 = math.radians(106.35) ## free angle
h = 5 ## meters, initial height of ball
vx0 = 6 ## initial horizontal velocity
## DEFINE SPRING
initialaxis = vector(r0*math.cos(theta0),r0*math.sin(theta0),0)
spring = helix(pos=(initialaxis.x,h - initialaxis.y,0), axis=initialaxis, radius=0.6,color=color.yellow)
spring.constant = 90 ## N/m
## DEFINE BALL
ball = sphere(pos=(0,h,0), radius=1,make_trail = True)
ball.mass = 1 # kg
ball.velocity = vector(vx0,0,0)
ball.acceleration = vector(0,0,0)
ball.force = vector(0,0,0)
floor = box(size=(50,.1,2),pos=(0,0,0))
## OTHER DEFINITIONS
accelOfGrav = vector(0,-9.8,0) ## acceleration of gravity
K0 = 0.5 * ball.mass * vx0**2
Ugrav0 = ball.mass * 9.8 * h
energy0 = K0 + Ugrav0 ## joules
dt = 0.005
t = 0
## GRAPHING
graph1 = gdisplay()
energygraph = gcurve(color=color.red)
Kgraph = gcurve(color=color.green)
Ugravgraph = gcurve(color=color.white)
Uspringgraph = gcurve(color = color.yellow)
positiongraph = gcurve(color=color.cyan)
while True:
rate(100)
t += dt
ball.force = ball.mass * accelOfGrav
## STANCE PHASE
if ball.pos.y < initialaxis.y:## when spring touches floor
spring.pos.y = 0.1
spring.axis = ball.pos - spring.pos##update spring length
spring.displacement = initialaxis.mag*norm(spring.axis) - spring.axis
## ENERGY ADDITIONS/SUBTRACTIONS
dEnergy = energy0 - energy
springForce = spring.constant * spring.displacement
ball.force += springForce ## update force on ball
## FLIGHT PHASE
else:
spring.pos = ball.pos - initialaxis ##update spring position
spring.axis = initialaxis
spring.displacement = vector(0,0,0)
ball.acceleration = ball.force/ball.mass
ball.velocity += ball.acceleration * dt ##update ball velocity
ball.pos += ball.velocity * dt ##update ball position
## ENERGY ACCOUNTING
K = 0.5 * ball.mass * ball.velocity.mag**2
Ugrav = ball.mass * 9.8 * ball.pos.y
Uspring = 0.5 * spring.constant * spring.displacement.mag**2
energy = K + Ugrav + Uspring #calculate current energy
## UPDATE GRAPHS
energygraph.plot(pos=(ball.pos.x,energy))
positiongraph.plot(pos=(ball.pos.x, ball.pos.y))
Kgraph.plot(pos=(ball.pos.x,K))
Ugravgraph.plot(pos=(ball.pos.x,Ugrav))
Uspringgraph.plot(pos=(ball.pos.x,Ugrav))
I created graphs, did the energy accounting section, and made the graphs update. I also went and commented everything when I got slightly frustrated.
I had problems with spring potential energy. Like regarding placement of the code or whatnot. I suppose if I actually study algorithms or programming or something these kinds of problems won't appear.
Red is total energy (K+U). Yellow is spring potential energy. Green is kinetic energy. Gravitational potential energy is supposed to be plotted but it's not there. Blue is just position of the ball (x, y). Everything is plotted to the x-position of the ball, not time.
June 19
I want to learn how to use Git/Github to manage the changes in my code.
Alas that might take another time to figure out...(but now is the time!!!)
As for now I'm just saving copies and renaming them version 3.0, 3.1, 4.0, 4.1, 5.0, etc etc. It's quite arbitrary.
LOL I don't know how this is going to work. I feel like a /real software developer/ except I'm really doing a project that's been done before.
I messed with 4.0 to see if I could iron out the problems with too small of a spring constant but didn't get anything out of it so I'm ditching that.
Current task: figure out how to add energy lost.
Gray suggested adding the energy only at the expansion phase (aka when the spring pushes off, energy is added by extra force?).
Hmmm something about power and force and velocity.
Notes:
-first bounce looks good
-second bounce skids to a stop
hypothesis: too much force and in the wrong direction
-proposed solution: change condition of expansion to include spring.axis.x > 0
-results: ball gets "trapped" and bounces in circles
solution 2:
...
June 12 - 16
Successfully made a spring-mass system that bounces in just the y-direction.
Next step (excerpt from an email with mentor):
"The next step is to make stable "running" happen, and the way to do that involves a subtle change to the way you are computing the spring deflection. The most important change is that once the spring hits the ground, its tip never slides. At this point the spring's vector angle and length should be considered separately: the spring will apply a force along the direction it currently happens to be pointing, but this direction is ultimately determined by the COM's motion. You may also want to update the landing condition, because the bounce might begin and end at a different spring angle, and thus a different ball height. With those changes in place, the secret to SLIP running is to tune the initial velocity in x and y, as well as the free spring angle (after the spring leaves the ground, it magically returns to this "free spring angle" in preparation for the next landing). It's a delicate process, but tuning it by hand will give you an intuition about each of those critical parameters."
I worked on the code to change some things:
-make an "initialaxis" that is the initial position, in terms of r0 (relaxed length) and theta0 (the free angle)
I'm having issues with the stance phase condition, like what do I check? I've tried:
ball.pos.y < spring.axis.y
spring.pos.y < 0.1
Which seem to work sometimes.
Issues with spring force:
- spring displacement
Should I calculate this as a vector or as a scalar? Should it be always positive?
-spring force
k * spring.displacement [if spring displacement is a vector]
k * spring.displacement * norm(spring.axis) [if spring displacement is a scalar, norm(spring.axis) is a unit vector in the direction of the spring]
Some problems:
-if spring constant is not high enough weird stuff happens
-spring foot sometimes gets "stuck" at floor
-sometimes ball and spring shoot off in one direction
I was getting a lot of wonky stuff so I went back to the 1D bouncing that worked and managed to get rid of some of the "shooting" behavior.
Maybe it doesn't matter that my model only works sometimes?
June 3
"Dynamic walking and running with robots"
-make a sphere
-make the sphere fall (update position)
-make sphere fall with acceleration (update velocity and position)
-make sphere bounce
-make a spring
I'm following this worksheet to see what I can get from it but it's pretty tricky.
Since I'm a noob (I'm going to extremely simplify and break down the SLIP model into bare bones):
Goals in VPython:
-make spring bounce
Current goal: make a ball bounce on a spring.
Second goal: give it some horizontal velocity.
Third goal: make the ball-spring the inverted pendulum
Subgoal 1: make a regular pendulum.
Subgoal 2: Invert the regular pendulum. (Make the floor move instead of the mass??)
I found another powerpoint on the spring thing. TBH I haven't figured anything out on my own...what I've figured out is where to find resources...
LAME.
In learning new things, there's like, a hierarchy of skill, and creating is the last step. I'm not even at like, replicating yet. Well, I am replicating.
I'm at editing I guess?
May 31 - June 2
My mentor sent me some articles about the nature of research from IEEE Potentials. They were informative.
Began following an introduction to VPython. It's a video course.
Began following an introduction to VPython. It's a video course.
Checked out some of the example programs that came with the VPython packages. THEY'RE SO COOL.
The program for "crystal", while seemingly not useful, is a ball and spring model of a solid. So it is very useful, considering I'm going to be trying to simulate a spring-loaded inverted pendulum. I also found a double pendulum so that'll be useful.
(This whole project still seems pretty daunting. Like...how will I know what angle to strike the ground with?? I feel like there's some differential equation in there and the angle to strike is the solution of it).
Subscribe to:
Posts (Atom)