5 Replies - 1083 Views - Last Post: 11 December 2013 - 01:00 PM Rate Topic: -----

#1 drlou   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-December 13

Modeling Car Doing Donuts

Posted 08 December 2013 - 02:28 PM

I am relatively new to coding and thought it would be pretty cool to try to model a car by using 4 springs and 4 point masses to creat the car and then try to model it doing donuts. In the process I created a frame of a car with the same weight proportions as a porche 911 turbo s. Before i even try to make the car do donuts I just wanted to see if I could get the car to move in a straight line. So i set off and wrote this up. I have been fiddling with it for about 3 or 4 days and I am having some problems that are quite frustrating. First is that I cannot get the code to work with any other time step than something that is incredibly small. The time step that i have in the code right now is the largest that i can make it before all hell breaks loose. Next is that when using this really small time step the acceration that i get is not the same as the acceleration found when using Newtons law F=Ma. Instead the car hits 60 miles per hour in approximatly 8.5 seconds when it should be around 2.9. Now is this due to the system of springs loosing or an error on my part. Help would be really appreciated.

The next problem that i forsee is that I am unable to come up with a way to stear the car so that it can do donuts. I really dont want to resort to taking out the momentum and position update for one of the front wheels because i feel as thought that would be somehow cheating. Any ideas on this part of my problem would be very welcome as well.

from visual import*
from visual.graph import*

lfM=sphere(pos=(0,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)
rfM=sphere(pos=(1.2,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)
lbM=sphere(pos=(0,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)
rbM=sphere(pos=(1.2,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)

eRf=(rfM.pos-lfM.pos)#equilibrium lengths of all the springs
eRl=(lfM.pos-lbM.pos)
eRr=(rfM.pos-rbM.pos)
eRb=(rbM.pos-lbM.pos)


k=1e12#k of springs connecting masses
Fw=16589.4#force wheels
lost=.2#the amount of force lost by the tires spinning
Fwr=Fw/2 #amount of force actually translated to the road per wheel but I took out the lost force to see if could model #the correct 0-60 time of a porche
dt=.00001
t=0

while t<20:
    
    Rf=(rfM.pos-lfM.pos)#new vectors of all the springs
    Rl=(lfM.pos-lbM.pos)
    Rr=(rfM.pos-rbM.pos)
    Rb=(rbM.pos-lbM.pos)

    vRf=norm(Rf-norm(Rf)*mag(eRf))#normal vectors in the orientation of current vectors
    vRl=norm(Rl-norm(Rl)*mag(eRl))
    vRr=norm(Rr-norm(Rr)*mag(eRr))
    vRb=norm(Rb-norm(Rb)*mag(eRb))

    xRf=mag(Rf)-mag(eRf)#change in length to figure out spring force
    xRl=mag(Rl)-mag(eRl)
    xRr=mag(Rr)-mag(eRl)
    xRb=mag(Rb)-mag(eRb)

    FsRf=k*xRf*norm(Rf)
    FsRl=k*xRl*norm(Rl)
    FsRr=k*xRr*norm(Rr)
    FsRb=k*xRb*norm(Rb)
    
    FlfM=FsRf-FsRl#forces by the springs on the masses
    FrfM=-FsRr-FsRf
    FlbM=FsRl+FsRb
    FrbM=FsRr-FsRb
    
    FwlbM=Fwr*norm(Rl)#direction of force of wheels
    FwrbM=Fwr*norm(Rr)

    NlfM=FlfM#Net forces on each object
    NrfM=FrfM
    NlbM=FlbM+FwlbM
    NrbM=FrbM+FwrbM

    lfM.mom=lfM.mom+NlfM*dt
    lfM.pos=lfM.pos+lfM.mom/lfM.mass*dt
    rfM.mom=rfM.mom+NrfM*dt
    rfM.pos=rfM.pos+rfM.mom/rfM.mass*dt
    lbM.mom=lbM.mom+NlbM*dt
    lbM.pos=lbM.pos+lbM.mom/lbM.mass*dt
    rbM.mom=rbM.mom+NrbM*dt
    rbM.pos=rbM.pos+rbM.mom/rbM.mass*dt
    #position and momentum updates

    vCM=mag(lfM.mom+rfM.mom+lbM.mom+rbM.mom)/(lfM.mass+rfM.mass+lbM.mass+rbM.mass)
    print vCM
    print t
    t=t+dt

This post has been edited by andrewsw: 08 December 2013 - 03:37 PM
Reason for edit:: Fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Modeling Car Doing Donuts

#2 MentalFloss   User is offline

  • .
  • member icon

Reputation: 619
  • View blog
  • Posts: 1,590
  • Joined: 02-September 09

Re: Modeling Car Doing Donuts

Posted 10 December 2013 - 06:35 AM

All that happens for me is the spheres slowly inch up to the top of the window and then if I let it keep running, they just slowly get smaller and smaller. Everything happens very slowly for me. Probably my computer.

What is SUPPOSED to happen? I see that this was posted a few days ago. Is this even still a problem for you?

EDIT:

Also, I haven't decided about your variables (normally I would say they are named badly) because I never venture into this mathematical/physics domain. I'm pretty much novice and out of my element. That's why trying to understand your code has been so enjoyable.

Anyway, am I to understand that this is what you are going for?:

LF--F--RF
 |     |
 L     R
 |     |
LB--B--RB


This post has been edited by MentalFloss: 10 December 2013 - 07:21 AM

Was This Post Helpful? 0
  • +
  • -

#3 drlou   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-December 13

Re: Modeling Car Doing Donuts

Posted 10 December 2013 - 11:26 AM

lfM--Rf--lrM
 |        |
 Rl       Rr
 |        |
lbM--Rb--rbM


This is what the model looks like and yeah I am continuing to have the same problem. By them getting smaller and smaller it is just moving because i dont know how to make the origin of the diagram move with the center of mass of the object. And yeah the names are quite confusing but it is a lot easier to understand if you have the diagram next to you. And the problem you have were it runs very slowly is the same problem that I am having because when i attempt to speed it up by increasing the time step (dt) it just doesnt work because the springs become too compressed and then exert a huge amount of force on the objects that destroy it. On another note I am still losing energy or force that makes the object not accelerate as fast as it should. I really appreciate you looking at my model and taking time to figure this out with me.

This post has been edited by andrewsw: 10 December 2013 - 12:12 PM
Reason for edit:: Removed previous quote

Was This Post Helpful? 0
  • +
  • -

#4 MentalFloss   User is offline

  • .
  • member icon

Reputation: 619
  • View blog
  • Posts: 1,590
  • Joined: 02-September 09

Re: Modeling Car Doing Donuts

Posted 10 December 2013 - 09:42 PM

Quote

I am relatively new to coding and thought it would be pretty cool to try to model a car by using 4 springs and 4 point masses to creat the car and then try to model it doing donuts.


I see this statement and then look at the problem you're trying to tackle. I think to myself "This cannot possibly be programming homework - physics or math homework? Maybe... but doubtful". I see a huge disconnect between your knowledge of programming and your knowledge of math. So, I decided (primarily as a test for myself) to refactor the code you have. It was not easy.

Anyway, I am posting a full refactor of the code you posted. Usually, this gets people in trouble and this may be no different but I reason that since you did all the algorithms yourself, jostling what you have into something slightly more manageable might be quite beneficial for you. I am only just learning python so there may be horrible decisions here but let me show you what I have.

You can feel free to use it or not. Hopefully you take the opportunity to learn some programming methods through it.

Let's get started.

The first thing I noticed when looking at your code is that I needed a secret decoder ring to get anywhere. You really should think of better variable names for what you're describing. You'll get there. Just imagine putting this project down for a month and coming back to it - would you know what is going on still? Try it.

Secondly, you have no perception of functions or classes or any of the programming structures. My suggestion is that if you want to program, you start with learning the language constructs.

OK. Enough of that. Here's the code:

from visual import*
from visual.graph import*

"""
    LF--F--RF
     |     |
     L     R
     |     |
    LB--B--RB
"""

k=1e12#k of springs connecting masses (stiffness)
Fw=16589.4#force wheels
lost=.2#the amount of force lost by the tires spinning
Fwr=Fw/2 #amount of force actually translated to the road per wheel but I took out the lost force to see if could model #the correct 0-60 time of a porche
dt=.00001
t=0

class Car(object):
    """
    This is a container for everything.
    """
    
    def __init__(self,lfM,rfM,lbM,rbM):
        self.lfM = lfM
        self.rfM = rfM
        self.lbM = lbM
        self.rbM = rbM
        
        """
        self.lfM = sphere(pos=(0,2.46,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=251.748)
                          
        self.rfM = sphere(pos=(1.2,2.46,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=251.748)
                          
        self.lbM = sphere(pos=(0,0,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=428.652)
                          
        self.rbM = sphere(pos=(1.2,0,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=428.652)
        """
        
        self.front = Spring(self.rfM, self.lfM)
        self.left  = Spring(self.lfM, self.lbM)
        self.right = Spring(self.rfM, self.rbM)
        self.back  = Spring(self.rbM, self.lbM)

    def get_update(self):
    #vCM=mag(lfM.mom+rfM.mom+lbM.mom+rbM.mom)/(lfM.mass+rfM.mass+lbM.mass+rbM.mass)
        momentum = self.get_momentum()
        total_mass = self.get_total_mass()
        return momentum / total_mass

    def get_momentum(self):
        return mag(self.lfM.mom + self.rfM.mom + self.lbM.mom + self.rbM.mom)
        
    def get_total_mass(self):
        return (self.lfM.mass + self.rfM.mass + self.lbM.mass + self.rbM.mass)

    def get_force_lfM(self):
        front = self.front.get_force()
        left  = self.left.get_force()
        return front - left
        
    def get_force_rfM(self):
        right = -self.right.get_force() #why is this negative?
        front = self.front.get_force()
        return right - front
        
    def get_force_lbM(self):
        left = self.left.get_force()
        back = self.back.get_force()
        return left + back #why is this a +?
        
    def get_force_rbM(self):
        right = self.right.get_force()
        back  = self.back.get_force()
        return right - back
        
class Spring(object):
    """
    This represents a single spring in the system.
    FRONT, LEFT, RIGHT, BACK based on what masses(m1,m2) were passed in.
    """
    def __init__(self, m1, m2):
        self.m1 = m1
        self.m2 = m2
        self.equilibrium = self.get_vector()
        
    def get_vector(self):
        return self.m1.pos - self.m2.pos
        
    def get_normal_vector(self):
        R = self.get_vector()
        return norm(R - norm(R) * mag(self.equilibrium))
        
    def get_length_change(self):
        R = self.get_vector()
        return mag(R) - mag(self.equilibrium)
        
    def get_force(self):
        R = self.get_vector()
        X = self.get_length_change()
        return k * X * norm(R)
        
class Wheel(sphere):
    """
    I don't really know about this...
    I just wanted a way to put the methods that the wheels care about somewhere.
    Maybe this was wrong.
    """
    def update(self, momentum_change):
        self.mom = self._update_momentum(momentum_change)
        self.pos += self.mom / self.mass * dt
        
    def _update_momentum(self, change):
        return self.mom + change * dt


lfM=sphere(pos=(0,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)
lfC=Wheel(pos=(0,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)
rfM=sphere(pos=(1.2,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)
rfC=Wheel(pos=(1.2,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)
lbM=sphere(pos=(0,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)
lbC=Wheel(pos=(0,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)
rbM=sphere(pos=(1.2,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)
rbC=Wheel(pos=(1.2,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)
# this code is now going to be a Car() ^^/>/>/>
# but so everything shares references I pass them in as is:
car = Car(lfC,rfC,lbC,rbC)
car2 = Car(lfM,rfM,lbM,rbM)

#equilibrium lengths of all the springs
eRf=(rfM.pos-lfM.pos) # right front - left front
eRl=(lfM.pos-lbM.pos) # left front - left back
eRr=(rfM.pos-rbM.pos) # right front - right back
eRb=(rbM.pos-lbM.pos) # right back - left back
# this code is now part of Car() which has a Spring() for each one. ^^/>/>/>
# it also runs immediately so no need for it here.


#moved to top...
#k=1e12#k of springs connecting masses (stiffness)
#Fw=16589.4#force wheels
#lost=.2#the amount of force lost by the tires spinning
#Fwr=Fw/2 #amount of force actually translated to the road per wheel but I took out the lost force to see if could model #the correct 0-60 time of a porche
#dt=.00001
#t=0
#############

while t<20:
    
    #same formula as equilibrium assignment.
    Rf=(rfM.pos-lfM.pos)#new vectors of all the springs
    front = car.front.get_vector()
    print "Rf=%r, front=%r" % (Rf,front)
    
    Rl=(lfM.pos-lbM.pos)
    left = car.left.get_vector()
    print "Rl=%r, left=%r" % (Rl,left)
    
    Rr=(rfM.pos-rbM.pos)
    right = car.right.get_vector()
    print "Rr=%r, right=%r" % (Rr,right)
    
    Rb=(rbM.pos-lbM.pos)
    back = car.back.get_vector()
    print "Rb=%r, back=%r" % (Rb,back)

    #normal vectors in the orientation of current vectors
    vRf=norm(Rf-norm(Rf)*mag(eRf))
    v_front = car.front.get_normal_vector()
    print "vRf=%r, v_front=%r" % (vRf,v_front)
    
    vRl=norm(Rl-norm(Rl)*mag(eRl))
    v_left = car.left.get_normal_vector()
    print "vRl=%r, v_left=%r" % (vRl,v_left)
    
    vRr=norm(Rr-norm(Rr)*mag(eRr))
    v_right = car.right.get_normal_vector()
    print "vRr=%r, v_right=%r" % (vRr,v_right)
    
    vRb=norm(Rb-norm(Rb)*mag(eRb))
    v_back = car.back.get_normal_vector()
    print "vRb=%r, v_back=%r" % (vRb,v_back)
    # this code is now part of Spring() by accessing get_normal_vector()


    xRf=mag(Rf)-mag(eRf)#change in length to figure out spring force
    x_front = car.front.get_length_change()
    print "xRf=%r, x_front=%r" % (xRf,x_front)
    
    xRl=mag(Rl)-mag(eRl)
    x_left = car.left.get_length_change()
    print "xRl=%r, x_left=%r" % (xRl,x_left)
    
    xRr=mag(Rr)-mag(eRl)
    x_right = car.right.get_length_change()
    print "xRr=%r, x_right=%r" % (xRr,x_right)
    
    xRb=mag(Rb)-mag(eRb)
    x_back = car.back.get_length_change()
    print "xRb=%r, x_back=%r" % (xRb,x_back)
    # this is now part of Spring() by accessing get_length_change()

    FsRf=k*xRf*norm(Rf)
    f_front = car.front.get_force()
    print "FsRf=%r, f_front=%r" % (FsRf,f_front)
    
    FsRl=k*xRl*norm(Rl)
    f_left = car.left.get_force()
    print "FsRl=%r, f_left=%r" % (FsRl,f_left)
    
    FsRr=k*xRr*norm(Rr)
    f_right = car.right.get_force()
    print "FsRr=%r, f_right=%r" % (FsRr,f_right)
    
    FsRb=k*xRb*norm(Rb)
    f_back = car.back.get_force()
    print "FsRb=%r, f_back=%r" % (FsRb,f_back)
    # this is now part of Spring() by accessing get_force()
    
    FlfM=FsRf-FsRl#forces by the springs on the masses
    f_lfm = car.get_force_lfM()
    print "FlfM=%r, car.lfM=%r" % (FlfM,f_lfm)
    
    FrfM=-FsRr-FsRf
    f_rfm = car.get_force_rfM()
    print "FrfM=%r, f_rfm=%r" % (FrfM,f_rfm)
    
    FlbM=FsRl+FsRb
    f_lbm = car.get_force_lbM()
    print "FlbM=%r, f_lbm=%r" % (FlbM,f_lbm)
    
    FrbM=FsRr-FsRb
    f_rbm = car.get_force_rbM()
    print "FrbM=%r, f_rbm=%r" % (FrbM,f_rbm)
    # this is now part of Car() by accessing get_force_XXX()
    
    
    FwlbM=Fwr*norm(Rl)#direction of force of wheels
    fw_left = Fwr * norm(left)
    print "FwlbM=%r, fw_left=%r" % (FwlbM,fw_left)
    
    FwrbM=Fwr*norm(Rr)
    fw_right = Fwr * norm(right)
    print "FwrbM=%r, fw_right=%r" % (FwrbM,fw_right)

    #Net forces on each object
    NlfM=FlfM
    net_lfm = f_lfm
    print "NlfM=%r, net_lfm=%r" % (NlfM,net_lfm)
    
    NrfM=FrfM
    net_rfm = f_rfm
    print "NrfM=%r, net_rfm=%r" % (NrfM,net_rfm)
                   
    NlbM=FlbM+FwlbM
    net_lbm = f_lbm + FwlbM
    print "NlbM=%r, net_lbm=%r" % (NlbM,net_lbm)
    
    NrbM=FrbM+FwrbM
    net_rbm = f_rbm + FwrbM
    print "NrbM=%r, net_rbm=%r" % (NrbM,net_rbm)

    #position and momentum updates
    print
    lfM.mom=lfM.mom+NlfM*dt
    lfM.pos=lfM.pos+lfM.mom/lfM.mass*dt
    car.lfM.update(NlfM)
    print "lfM: mom=%r, pos=%r" % (lfM.mom, lfM.pos)
    print "car: mom=%r, pos=%r" % (car.lfM.mom, car.lfM.pos)
    
    print
    rfM.mom=rfM.mom+NrfM*dt
    rfM.pos=rfM.pos+rfM.mom/rfM.mass*dt
    car.rfM.update(NrfM)
    print "rfM: mom=%r, pos=%r" % (rfM.mom, rfM.pos)
    print "car: mom=%r, pos=%r" % (car.rfM.mom, car.rfM.pos)
    
    print
    lbM.mom=lbM.mom+NlbM*dt
    lbM.pos=lbM.pos+lbM.mom/lbM.mass*dt
    car.lbM.update(NlbM)
    print "lbM: mom=%r, pos=%r" % (lbM.mom, lbM.pos)
    print "car: mom=%r, pos=%r" % (car.lbM.mom, car.lbM.pos)
    
    print
    rbM.mom=rbM.mom+NrbM*dt
    rbM.pos=rbM.pos+rbM.mom/rbM.mass*dt
    car.rbM.update(NrbM)
    print "rbM: mom=%r, pos=%r" % (rbM.mom, rbM.pos)
    print "car: mom=%r, pos=%r" % (car.rbM.mom, car.rbM.pos)
    
    #end position and momentum updates

    vCM=mag(lfM.mom+rfM.mom+lbM.mom+rbM.mom)/(lfM.mass+rfM.mass+lbM.mass+rbM.mass)
    CAR=car.get_update()
    print "vcM=%r, CAR=%r" % (vCM,CAR)
    raw_input('[press enter for next frame]')
    print vCM
    print t
    t=t+dt



What I did here was create classes called Car, Spring, and Wheel. Now, Car holds the components and Spring received most of the formulas and Wheel is simply a way to add functionality to the sphere object from visual. In order to make sure it was right, I left everything of yours in and put my test code along side it. I then printed everything out to make sure all of the numbers match.

At this point, I have as truth that my additional code does exactly what your original code does. Therefore, my next step is to get rid of all of your code (relax, it's just reshuffled. You did all the HARD work with this thing).

from visual import*
from visual.graph import*

"""
    LF--F--RF
     |     |
     L     R
     |     |
    LB--B--RB
"""

k=1e12#k of springs connecting masses (stiffness)
Fw=16589.4#force wheels
lost=.2#the amount of force lost by the tires spinning
Fwr=Fw/2 #amount of force actually translated to the road per wheel but I took out the lost force to see if could model #the correct 0-60 time of a porche
dt=.00001
t=0

class Car(object):
    """
    This is a container for everything.
    """
    
    def __init__(self,lfM,rfM,lbM,rbM):
        self.lfM = lfM
        self.rfM = rfM
        self.lbM = lbM
        self.rbM = rbM
        
        """
        self.lfM = sphere(pos=(0,2.46,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=251.748)
                          
        self.rfM = sphere(pos=(1.2,2.46,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=251.748)
                          
        self.lbM = sphere(pos=(0,0,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=428.652)
                          
        self.rbM = sphere(pos=(1.2,0,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=428.652)
        """
        
        self.front = Spring(self.rfM, self.lfM)
        self.left  = Spring(self.lfM, self.lbM)
        self.right = Spring(self.rfM, self.rbM)
        self.back  = Spring(self.rbM, self.lbM)

    def get_update(self):
    #vCM=mag(lfM.mom+rfM.mom+lbM.mom+rbM.mom)/(lfM.mass+rfM.mass+lbM.mass+rbM.mass)
        momentum = self.get_momentum()
        total_mass = self.get_total_mass()
        return momentum / total_mass

    def get_momentum(self):
        return mag(self.lfM.mom + self.rfM.mom + self.lbM.mom + self.rbM.mom)
        
    def get_total_mass(self):
        return (self.lfM.mass + self.rfM.mass + self.lbM.mass + self.rbM.mass)

    def get_force_lfM(self):
        front = self.front.get_force()
        left  = self.left.get_force()
        return front - left
        
    def get_force_rfM(self):
        right = -self.right.get_force() #why is this negative?
        front = self.front.get_force()
        return right - front
        
    def get_force_lbM(self):
        left = self.left.get_force()
        back = self.back.get_force()
        return left + back #why is this a +?
        
    def get_force_rbM(self):
        right = self.right.get_force()
        back  = self.back.get_force()
        return right - back
        
class Spring(object):
    """
    This represents a single spring in the system.
    FRONT, LEFT, RIGHT, BACK based on what masses(m1,m2) were passed in.
    """
    def __init__(self, m1, m2):
        self.m1 = m1
        self.m2 = m2
        self.equilibrium = self.get_vector()
        
    def get_vector(self):
        return self.m1.pos - self.m2.pos
        
    def get_normal_vector(self):
        R = self.get_vector()
        return norm(R - norm(R) * mag(self.equilibrium))
        
    def get_length_change(self):
        R = self.get_vector()
        return mag(R) - mag(self.equilibrium)
        
    def get_force(self):
        R = self.get_vector()
        X = self.get_length_change()
        return k * X * norm(R)
        
class Wheel(sphere):
    """
    I don't really know about this...
    I just wanted a way to put the methods that the wheels care about somewhere.
    Maybe this was wrong.
    """
    def update(self, momentum_change):
        self.mom = self._update_momentum(momentum_change)
        self.pos += self.mom / self.mass * dt
        
    def _update_momentum(self, change):
        return self.mom + change * dt


lfC=Wheel(pos=(0,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)
rfC=Wheel(pos=(1.2,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)
lbC=Wheel(pos=(0,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)
rbC=Wheel(pos=(1.2,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)

car = Car(lfC,rfC,lbC,rbC)

while t<20:
    
    #same formula as equilibrium assignment.
    front = car.front.get_vector()
    left = car.left.get_vector()
    right = car.right.get_vector()
    back = car.back.get_vector()

    #normal vectors in the orientation of current vectors
    v_front = car.front.get_normal_vector()
    v_left = car.left.get_normal_vector()
    v_right = car.right.get_normal_vector()
    v_back = car.back.get_normal_vector()

    #change in length to figure out spring force
    x_front = car.front.get_length_change()
    x_left = car.left.get_length_change()
    x_right = car.right.get_length_change()
    x_back = car.back.get_length_change()

    f_front = car.front.get_force()
    f_left = car.left.get_force()
    f_right = car.right.get_force()
    f_back = car.back.get_force()
    # this is now part of Spring() by accessing get_force()
    
    #forces by the springs on the masses
    f_lfm = car.get_force_lfM()
    f_rfm = car.get_force_rfM()
    f_lbm = car.get_force_lbM()
    f_rbm = car.get_force_rbM()
    # this is now part of Car() by accessing get_force_XXX()
    
    #direction of force of wheels
    fw_left = Fwr * norm(left)
    fw_right = Fwr * norm(right)

    #Net forces on each object
    net_lfm = f_lfm
    net_rfm = f_rfm
    net_lbm = f_lbm + fw_left
    net_rbm = f_rbm + fw_right

    #position and momentum updates
    car.lfM.update(net_lfm)
    car.rfM.update(net_rfm)
    car.lbM.update(net_lbm)
    car.rbM.update(net_rbm)
    
    #end position and momentum updates
    CAR=car.get_update()
    raw_input('[press enter for next frame]')
    print CAR
    print t
    t=t+dt



So that is still your code but now things have logical places based on what they do. It is still not done obviously but it's starting to look like a manageable program now. Other people (not just you) can now start to work with this. I think getting your problems solved is going to require that this actually look like a program.

Please play around with this and see if it's something that you can work with at all. I know that we've now added a new level of complexity because you're new to programming but you can learn it better now because you actually understand this domain (physics).

I will continue tinkering with this because there is a lot of redundancy in the calculations now. It's just a symptom of first-pass refactoring.

Thanks for letting me see code from a person who doesn't know programming but tackles a complex topic. I've never really had the opportunity.

EDIT:

Now that everything is properly separated, I just find out what's not even being used anymore. I commented them out for now so you can see it but this was just quick glance stuff. I don't need bikeshedding of "oh that or this isn't used anymore."

from visual import*
from visual.graph import*

"""
    LF--F--RF
     |     |
     L     R
     |     |
    LB--B--RB
"""

k=1e12#k of springs connecting masses (stiffness)
Fw=16589.4#force wheels
lost=.2#the amount of force lost by the tires spinning
Fwr=Fw/2 #amount of force actually translated to the road per wheel but I took out the lost force to see if could model #the correct 0-60 time of a porche
dt=.00001
t=0

class Car(object):
    """
    This is a container for everything.
    """
    
    def __init__(self,lfM,rfM,lbM,rbM):
        self.lfM = lfM
        self.rfM = rfM
        self.lbM = lbM
        self.rbM = rbM
        
        """
        self.lfM = sphere(pos=(0,2.46,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=251.748)
                          
        self.rfM = sphere(pos=(1.2,2.46,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=251.748)
                          
        self.lbM = sphere(pos=(0,0,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=428.652)
                          
        self.rbM = sphere(pos=(1.2,0,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=428.652)
        """
        
        self.front = Spring(self.rfM, self.lfM)
        self.left  = Spring(self.lfM, self.lbM)
        self.right = Spring(self.rfM, self.rbM)
        self.back  = Spring(self.rbM, self.lbM)

    def get_update(self):
    #vCM=mag(lfM.mom+rfM.mom+lbM.mom+rbM.mom)/(lfM.mass+rfM.mass+lbM.mass+rbM.mass)
        momentum = self.get_momentum()
        total_mass = self.get_total_mass()
        return momentum / total_mass

    def get_momentum(self):
        return mag(self.lfM.mom + self.rfM.mom + self.lbM.mom + self.rbM.mom)
        
    def get_total_mass(self):
        return (self.lfM.mass + self.rfM.mass + self.lbM.mass + self.rbM.mass)

    def get_force_lfM(self):
        front = self.front.get_force()
        left  = self.left.get_force()
        return front - left
        
    def get_force_rfM(self):
        right = -self.right.get_force() #why is this negative?
        front = self.front.get_force()
        return right - front
        
    def get_force_lbM(self):
        left = self.left.get_force()
        back = self.back.get_force()
        return left + back #why is this a +?
        
    def get_force_rbM(self):
        right = self.right.get_force()
        back  = self.back.get_force()
        return right - back
        
class Spring(object):
    """
    This represents a single spring in the system.
    FRONT, LEFT, RIGHT, BACK based on what masses(m1,m2) were passed in.
    """
    def __init__(self, m1, m2):
        self.m1 = m1
        self.m2 = m2
        self.equilibrium = self.get_vector()
        
    def get_vector(self):
        return self.m1.pos - self.m2.pos
        
    def get_normal_vector(self):
        R = self.get_vector()
        return norm(R - norm(R) * mag(self.equilibrium))
        
    def get_length_change(self):
        R = self.get_vector()
        return mag(R) - mag(self.equilibrium)
        
    def get_force(self):
        R = self.get_vector()
        X = self.get_length_change()
        return k * X * norm(R)
        
class Wheel(sphere):
    """
    I don't really know about this...
    I just wanted a way to put the methods that the wheels care about somewhere.
    Maybe this was wrong.
    """
    def update(self, momentum_change):
        self.mom = self._update_momentum(momentum_change)
        self.pos += self.mom / self.mass * dt
        
    def _update_momentum(self, change):
        return self.mom + change * dt


lfC=Wheel(pos=(0,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)
rfC=Wheel(pos=(1.2,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)
lbC=Wheel(pos=(0,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)
rbC=Wheel(pos=(1.2,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)

car = Car(lfC,rfC,lbC,rbC)

while t<20:
    
    #same formula as equilibrium assignment.
    # no longer needed because we always just call get_vector
    #front = car.front.get_vector()
    #left = car.left.get_vector()
    #right = car.right.get_vector()
    #back = car.back.get_vector()

    #normal vectors in the orientation of current vectors
    # get_normal_vector FIRST calls get_vector()
    # I don't even know where these are used in the first place....
    #v_front = car.front.get_normal_vector()
    #v_left = car.left.get_normal_vector()
    #v_right = car.right.get_normal_vector()
    #v_back = car.back.get_normal_vector()

    #change in length to figure out spring force
    # get_force() calls get_length_change internally so no point.
    #x_front = car.front.get_length_change()
    #x_left = car.left.get_length_change()
    #x_right = car.right.get_length_change()
    #x_back = car.back.get_length_change()

    # car.get_force_XXX() calls get_force() on each thing properly.
    # no need for this.
    #f_front = car.front.get_force()
    #f_left = car.left.get_force()
    #f_right = car.right.get_force()
    #f_back = car.back.get_force()
    # this is now part of Spring() by accessing get_force()
    
    #forces by the springs on the masses
    # this part can probably be thrown into a single method and stored on the
    # car.... TODO
    f_lfm = car.get_force_lfM()
    f_rfm = car.get_force_rfM()
    f_lbm = car.get_force_lbM()
    f_rbm = car.get_force_rbM()
    # this is now part of Car() by accessing get_force_XXX()
    
    #direction of force of wheels
    # we now just call get_vector() directly on the proper spring.
    fw_left = Fwr * norm(car.left.get_vector())
    fw_right = Fwr * norm(car.right.get_vector())

    #Net forces on each object
    net_lfm = f_lfm
    net_rfm = f_rfm
    net_lbm = f_lbm + fw_left
    net_rbm = f_rbm + fw_right

    #position and momentum updates
    car.lfM.update(net_lfm)
    car.rfM.update(net_rfm)
    car.lbM.update(net_lbm)
    car.rbM.update(net_rbm)
    
    #end position and momentum updates
    CAR=car.get_update()
    raw_input('[press enter for next frame]')
    print CAR
    print t
    t=t+dt



Now I delete everything so you can see the full scope of the change:

while t<20:
    
    #forces by the springs on the masses
    # this part can probably be thrown into a single method and stored on the
    # car.... TODO
    f_lfm = car.get_force_lfM()
    f_rfm = car.get_force_rfM()
    f_lbm = car.get_force_lbM()
    f_rbm = car.get_force_rbM()
    # this is now part of Car() by accessing get_force_XXX()
    
    #direction of force of wheels
    # we now just call get_vector() directly on the proper spring.
    fw_left = Fwr * norm(car.left.get_vector())
    fw_right = Fwr * norm(car.right.get_vector())

    #Net forces on each object
    net_lfm = f_lfm
    net_rfm = f_rfm
    net_lbm = f_lbm + fw_left
    net_rbm = f_rbm + fw_right

    #position and momentum updates
    car.lfM.update(net_lfm)
    car.rfM.update(net_rfm)
    car.lbM.update(net_lbm)
    car.rbM.update(net_rbm)
    
    #end position and momentum updates
    CAR=car.get_update()
    raw_input('[press enter for next frame]')
    print CAR
    print t
    t=t+dt



And it STILL needs a lot of work but things are easier now.

EDIT:

OK. So, what I did this time was create a new class called Car_RF because I am refactoring the Car class but I don't know if my changes are right. So, I did the same thing as the first time which was verify all numbers match against different objects with same attribute values (different references).

Everything matched the first time and now everything still matches so I can be confident that what I changed has not actually broken anything (arguably it has not fixed anything either).

from visual import*
from visual.graph import*

"""
    LF--F--RF
     |     |
     L     R
     |     |
    LB--B--RB
"""

k=1e12#k of springs connecting masses (stiffness)
Fw=16589.4#force wheels
lost=.2#the amount of force lost by the tires spinning
Fwr=Fw/2 #amount of force actually translated to the road per wheel but I took out the lost force to see if could model #the correct 0-60 time of a porche
dt=.00001
t=0

class Car_RF(object):
    """
    This is work on Car class to make sure changes are not breaking things.
    """
    def __init__(self,lfM,rfM,lbM,rbM):
        self.lfM = lfM
        self.rfM = rfM
        self.lbM = lbM
        self.rbM = rbM
        
        self.lfM_force = 0.0
        self.rfM_force = 0.0
        self.lbM_force = 0.0
        self.rbM_force = 0.0
        
        self.net_lfM = 0.0
        self.net_rfM = 0.0
        self.net_lbM = 0.0
        self.net_rbM = 0.0
        
        self.front_force = 0.0
        self.back_force = 0.0
        self.right_force = 0.0
        self.left_force = 0.0
        
        """
        self.lfM = sphere(pos=(0,2.46,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=251.748)
                          
        self.rfM = sphere(pos=(1.2,2.46,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=251.748)
                          
        self.lbM = sphere(pos=(0,0,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=428.652)
                          
        self.rbM = sphere(pos=(1.2,0,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=428.652)
        """
        
        self.front = Spring(self.rfM, self.lfM)
        self.left  = Spring(self.lfM, self.lbM)
        self.right = Spring(self.rfM, self.rbM)
        self.back  = Spring(self.rbM, self.lbM)

    def get_update(self):
    #vCM=mag(lfM.mom+rfM.mom+lbM.mom+rbM.mom)/(lfM.mass+rfM.mass+lbM.mass+rbM.mass)
        momentum = self.get_momentum()
        total_mass = self.get_total_mass()
        return momentum / total_mass

    def update_pos_and_mom(self):
        self.lfM.update(self.net_lfM)
        self.rfM.update(self.net_rfM)
        self.lbM.update(self.net_lbM)
        self.rbM.update(self.net_rbM)

    def get_momentum(self):
        return mag(self.lfM.mom + self.rfM.mom + self.lbM.mom + self.rbM.mom)
        
    def get_total_mass(self):
        return (self.lfM.mass + self.rfM.mass + self.lbM.mass + self.rbM.mass)

    def update_forces(self):
        self.lfM_force = self.get_force_lfM()
        self.rfM_force = self.get_force_rfM()
        self.lbM_force = self.get_force_lbM()
        self.rbM_force = self.get_force_rbM()
        
    def update_wheel_force(self):
        self.left_force = self.left.get_force_on_wheels()
        self.right_force = self.right.get_force_on_wheels()
    
    def update_net_forces(self):
        #Net forces on each object
        self.net_lfM = self.get_force_lfM()
        self.net_rfM = self.get_force_rfM()
        self.net_lbM = self.get_force_lbM() + self.left_force
        self.net_rbM = self.get_force_rbM() + self.right_force
    
    def get_force_lfM(self):
        front = self.front.get_force()
        left  = self.left.get_force()
        return front - left
        
    def get_force_rfM(self):
        right = -self.right.get_force() #why is this negative?
        front = self.front.get_force()
        return right - front
        
    def get_force_lbM(self):
        left = self.left.get_force()
        back = self.back.get_force()
        return left + back #why is this a +?
        
    def get_force_rbM(self):
        right = self.right.get_force()
        back  = self.back.get_force()
        return right - back


class Car(object):
    """
    This is a container for everything.
    """
    
    def __init__(self,lfM,rfM,lbM,rbM):
        self.lfM = lfM
        self.rfM = rfM
        self.lbM = lbM
        self.rbM = rbM
        
        """
        self.lfM = sphere(pos=(0,2.46,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=251.748)
                          
        self.rfM = sphere(pos=(1.2,2.46,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=251.748)
                          
        self.lbM = sphere(pos=(0,0,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=428.652)
                          
        self.rbM = sphere(pos=(1.2,0,0),
                          mom=vector(0,0,0),
                          radius=.25,
                          color=color.red,
                          mass=428.652)
        """
        
        self.front = Spring(self.rfM, self.lfM)
        self.left  = Spring(self.lfM, self.lbM)
        self.right = Spring(self.rfM, self.rbM)
        self.back  = Spring(self.rbM, self.lbM)

    def get_update(self):
    #vCM=mag(lfM.mom+rfM.mom+lbM.mom+rbM.mom)/(lfM.mass+rfM.mass+lbM.mass+rbM.mass)
        momentum = self.get_momentum()
        total_mass = self.get_total_mass()
        return momentum / total_mass

    def get_momentum(self):
        return mag(self.lfM.mom + self.rfM.mom + self.lbM.mom + self.rbM.mom)
        
    def get_total_mass(self):
        return (self.lfM.mass + self.rfM.mass + self.lbM.mass + self.rbM.mass)

    def get_force_lfM(self):
        front = self.front.get_force()
        left  = self.left.get_force()
        return front - left
        
    def get_force_rfM(self):
        right = -self.right.get_force() #why is this negative?
        front = self.front.get_force()
        return right - front
        
    def get_force_lbM(self):
        left = self.left.get_force()
        back = self.back.get_force()
        return left + back #why is this a +?
        
    def get_force_rbM(self):
        right = self.right.get_force()
        back  = self.back.get_force()
        return right - back
        
class Spring(object):
    """
    This represents a single spring in the system.
    FRONT, LEFT, RIGHT, BACK based on what masses(m1,m2) were passed in.
    """
    def __init__(self, m1, m2):
        self.m1 = m1
        self.m2 = m2
        self.equilibrium = self.get_vector()
        
    def get_vector(self):
        return self.m1.pos - self.m2.pos
        
    def get_normal_vector(self):
        R = self.get_vector()
        return norm(R - norm(R) * mag(self.equilibrium))
        
    def get_length_change(self):
        R = self.get_vector()
        return mag(R) - mag(self.equilibrium)
        
    def get_force(self):
        R = self.get_vector()
        X = self.get_length_change()
        return k * X * norm(R)
    
    # new addition to the Springs.    
    def get_force_on_wheels(self):
        #Fwr * norm(car.left.get_vector())
        return Fwr * norm(self.get_vector())
        
class Wheel(sphere):
    """
    I don't really know about this...
    I just wanted a way to put the methods that the wheels care about somewhere.
    Maybe this was wrong.
    """
    def update(self, momentum_change):
        self.mom = self._update_momentum(momentum_change)
        self.pos += self.mom / self.mass * dt
        
    def _update_momentum(self, change):
        return self.mom + change * dt


lfC=Wheel(pos=(0,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)
lfX=Wheel(pos=(0,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)

rfC=Wheel(pos=(1.2,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)
rfX=Wheel(pos=(1.2,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)

lbC=Wheel(pos=(0,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)
lbX=Wheel(pos=(0,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)

rbC=Wheel(pos=(1.2,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)
rbX=Wheel(pos=(1.2,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)

car = Car(lfC,rfC,lbC,rbC)
car2 = Car_RF(lfX,rfX,lbX,rbX) # pass in different references.

while t<20:
    
    #forces by the springs on the masses
    # this part can probably be thrown into a single method and stored on the
    # car.... TODO
    f_lfm = car.get_force_lfM()
    f_rfm = car.get_force_rfM()
    f_lbm = car.get_force_lbM()
    f_rbm = car.get_force_rbM()
    car2.update_forces()
    print "f_lfm=%r, car2.lfM_force=%r" % (f_lfm,car2.lfM_force)
    print "f_rfm=%r, car2.rfM_force=%r" % (f_rfm,car2.rfM_force)
    print "f_lbm=%r, car2.lbM_force=%r" % (f_lbm,car2.lbM_force)
    print "f_rbm=%r, car2.rbM_force=%r" % (f_rbm,car2.rbM_force)
    # this is now part of Car() by accessing get_force_XXX()
    
    #direction of force of wheels
    # we now just call get_vector() directly on the proper spring.
    fw_left = Fwr * norm(car.left.get_vector())
    fw_right = Fwr * norm(car.right.get_vector())
    car2.update_wheel_force()
    print "fw_left=%r, left2=%r" % (fw_left, car2.left_force)
    print "fw_right=%r, right2=%r" % (fw_right, car2.right_force)
    

    #Net forces on each object
    net_lfm = f_lfm
    net_rfm = f_rfm
    net_lbm = f_lbm + fw_left
    net_rbm = f_rbm + fw_right
    car2.update_net_forces()
    print "net_lfm=%r, car2.net_lfm=%r" % (net_lfm,car2.net_lfM)
    print "net_rfm=%r, car2.net_rfm=%r" % (net_rfm,car2.net_rfM)
    print "net_lbm=%r, car2.net_lbm=%r" % (net_lbm,car2.net_lbM)
    print "net_rbm=%r, car2.net_rbm=%r" % (net_rbm,car2.net_rbM)

    #position and momentum updates
    car.lfM.update(net_lfm)
    car.rfM.update(net_rfm)
    car.lbM.update(net_lbm)
    car.rbM.update(net_rbm)
    car2.update_pos_and_mom()
    print "C1:lfM - pos=%r, mom=%r" % (car.lfM.pos,car.lfM.mom)
    print "C2:lfM - pos=%r, mom=%r" % (car2.lfM.pos, car2.lfM.mom)
    print
    print "C1:rfM - pos=%r, mom=%r" % (car.rfM.pos,car.rfM.mom)
    print "C2:rfM - pos=%r, mom=%r" % (car2.rfM.pos, car2.rfM.mom)
    print
    print "C1:lbM - pos=%r, mom=%r" % (car.lbM.pos,car.lbM.mom)
    print "C2:lbM - pos=%r, mom=%r" % (car2.lbM.pos, car2.lbM.mom)
    print
    print "C1:rbM - pos=%r, mom=%r" % (car.rbM.pos,car.rbM.mom)
    print "C2:rbM - pos=%r, mom=%r" % (car2.rbM.pos, car2.rbM.mom)
    
    #end position and momentum updates
    CAR=car.get_update()
    CAR_RF = car2.get_update()
    print "CAR=%r, CAR_RF=%r" % (CAR,CAR_RF)
    print t
    raw_input("[press enter for next frame]")
    t=t+dt



Since I verified that all calculations are still being done accurately and identically, I can remove all of the previous code. The new version now looks like this:

from visual import*
from visual.graph import*

"""
    LF--F--RF
     |     |
     L     R
     |     |
    LB--B--RB
"""

k=1e12#k of springs connecting masses (stiffness)
Fw=16589.4#force wheels
lost=.2#the amount of force lost by the tires spinning
Fwr=Fw/2 #amount of force actually translated to the road per wheel but I took out the lost force to see if could model #the correct 0-60 time of a porche
dt=.00001
t=0

class Car(object):
    """
    This is work on Car class to make sure changes are not breaking things.
    """
    def __init__(self,lfM,rfM,lbM,rbM):
        self.lfM = lfM
        self.rfM = rfM
        self.lbM = lbM
        self.rbM = rbM
        
        self.lfM_force = 0.0
        self.rfM_force = 0.0
        self.lbM_force = 0.0
        self.rbM_force = 0.0
        
        self.net_lfM = 0.0
        self.net_rfM = 0.0
        self.net_lbM = 0.0
        self.net_rbM = 0.0
        
        self.front_force = 0.0
        self.back_force = 0.0
        self.right_force = 0.0
        self.left_force = 0.0
        
        self.front = Spring(self.rfM, self.lfM)
        self.left  = Spring(self.lfM, self.lbM)
        self.right = Spring(self.rfM, self.rbM)
        self.back  = Spring(self.rbM, self.lbM)

    def get_update(self):
    #vCM=mag(lfM.mom+rfM.mom+lbM.mom+rbM.mom)/(lfM.mass+rfM.mass+lbM.mass+rbM.mass)
        momentum = self.get_momentum()
        total_mass = self.get_total_mass()
        return momentum / total_mass

    def update_pos_and_mom(self):
        self.lfM.update(self.net_lfM)
        self.rfM.update(self.net_rfM)
        self.lbM.update(self.net_lbM)
        self.rbM.update(self.net_rbM)

    def get_momentum(self):
        return mag(self.lfM.mom + self.rfM.mom + self.lbM.mom + self.rbM.mom)
        
    def get_total_mass(self):
        return (self.lfM.mass + self.rfM.mass + self.lbM.mass + self.rbM.mass)

    def update_forces(self):
        self.lfM_force = self.get_force_lfM()
        self.rfM_force = self.get_force_rfM()
        self.lbM_force = self.get_force_lbM()
        self.rbM_force = self.get_force_rbM()
        
    def update_wheel_force(self):
        self.left_force = self.left.get_force_on_wheels()
        self.right_force = self.right.get_force_on_wheels()
    
    def update_net_forces(self):
        #Net forces on each object
        self.net_lfM = self.get_force_lfM()
        self.net_rfM = self.get_force_rfM()
        self.net_lbM = self.get_force_lbM() + self.left_force
        self.net_rbM = self.get_force_rbM() + self.right_force
    
    def get_force_lfM(self):
        front = self.front.get_force()
        left  = self.left.get_force()
        return front - left
        
    def get_force_rfM(self):
        right = -self.right.get_force() #why is this negative?
        front = self.front.get_force()
        return right - front
        
    def get_force_lbM(self):
        left = self.left.get_force()
        back = self.back.get_force()
        return left + back #why is this a +?
        
    def get_force_rbM(self):
        right = self.right.get_force()
        back  = self.back.get_force()
        return right - back
        
class Spring(object):
    """
    This represents a single spring in the system.
    FRONT, LEFT, RIGHT, BACK based on what masses(m1,m2) were passed in.
    """
    def __init__(self, m1, m2):
        self.m1 = m1
        self.m2 = m2
        self.equilibrium = self.get_vector()
        
    def get_vector(self):
        return self.m1.pos - self.m2.pos
        
    def get_normal_vector(self):
        R = self.get_vector()
        return norm(R - norm(R) * mag(self.equilibrium))
        
    def get_length_change(self):
        R = self.get_vector()
        return mag(R) - mag(self.equilibrium)
        
    def get_force(self):
        R = self.get_vector()
        X = self.get_length_change()
        return k * X * norm(R)
    
    # new addition to the Springs.    
    def get_force_on_wheels(self):
        #Fwr * norm(car.left.get_vector())
        return Fwr * norm(self.get_vector())
        
class Wheel(sphere):
    """
    I don't really know about this...
    I just wanted a way to put the methods that the wheels care about somewhere.
    Maybe this was wrong.
    """
    def update(self, momentum_change):
        self.mom = self._update_momentum(momentum_change)
        self.pos += self.mom / self.mass * dt
        
    def _update_momentum(self, change):
        return self.mom + change * dt


lfC=Wheel(pos=(0,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)
rfC=Wheel(pos=(1.2,2.46,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=251.748)
lbC=Wheel(pos=(0,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)
rbC=Wheel(pos=(1.2,0,0),mom=vector(0,0,0),radius=.25,color=color.red,mass=428.652)

car = Car(lfC,rfC,lbC,rbC)

while t<20:
    car.update_forces()
    car.update_wheel_force()
    car.update_net_forces()
    car.update_pos_and_mom()
    
    #end position and momentum updates
    CAR = car.get_update()
    print "CAR=%r" % (CAR)
    print t
    #raw_input("[press enter for next frame]")
    t=t+dt



Is this now easier or harder to understand? I still can't decide.

This post has been edited by MentalFloss: 10 December 2013 - 11:27 PM

Was This Post Helpful? 1
  • +
  • -

#5 MentalFloss   User is offline

  • .
  • member icon

Reputation: 619
  • View blog
  • Posts: 1,590
  • Joined: 02-September 09

Re: Modeling Car Doing Donuts

Posted 11 December 2013 - 01:11 AM

I found your problem. You can keep your original code if you want. It looks like all python is written like that or something. So, I'm just going to fall back to the statement that I don't know what I'm doing.

Anyway, k=1e12#k of springs connecting masses is not what you want. Once I changed it to k=112 it does a lot more interesting things. By the way, with this I was able to change time to .01 as well.

Oh and I found out that you want to have a call to rate() to establish the frame count. Everyone seems to be setting it to 100.

while t<20:
    rate(100)
    # rest of your stuff



OK? Sorry for totally confusing the issue. It was fun playing around with regardless though.
Was This Post Helpful? 1
  • +
  • -

#6 drlou   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 08-December 13

Re: Modeling Car Doing Donuts

Posted 11 December 2013 - 01:00 PM

Wow your a miracle worker! It looks fantastic even though I am lost for about 90% of it. It will be my goal to by the end of this week understand whats going on and find my physics in there.I really appreciate the work you have done and I'm sure improving my code to your level is going to keep me busy for a long while to come. I really needed this push in the right direction and I'm glad you took your time in helping me along my way. Hopefully they keep this little thread open because i would really like to talk to you in the future! Again Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1