示例#1
0
def main():
    #neuralNet = NeuralNetwork()

    pendulum = InvertedPendulum()
    for n in np.arange(-0.5, 10, 0.5):
        cart, theta = pendulum.applyforce(u=n, tmax=2.5, timeslice=0.01)
        x, y = transform(theta)
        showGraph(x, y, cart, 0.01, "Relative motion of cart and pendulum u={0}".format(n))
示例#2
0
class Controller (object):

    def __init__(self):
        self.running_flag = False
        self.pendulum = InvertedPendulum()


    def isRunning(self):
        return self.running_flag

    def start(self, impulse=1, freq=0.01):
        if self.running_flag: raise Exception('Already running')

        self.frequency = freq
        self.running_flag = True
        self.pendulum.applyforce(u=impulse)


    def stop(self):
        self.running_flag = False
示例#3
0
    def __init__(self, genome, M=10, m=1, l=1, threshold=0.1):
        self.threshold = threshold
        #there are the physics constants for each individual
        self.M = M
        self.m = m
        self.l = l

        #this is the actual data we are evolving weights for
        self.genome = genome

        #these are the actual weights we are evolving
        self.alleles = [uniform(-10, 10) for n in range(len(genome))]
        self.pendulum = InvertedPendulum(M, m, l)
示例#4
0
class Individual (object):

    def __init__(self, genome, M=10, m=1, l=1, threshold=0.1):
        self.threshold = threshold
        #there are the physics constants for each individual
        self.M = M
        self.m = m
        self.l = l

        #this is the actual data we are evolving weights for
        self.genome = genome

        #these are the actual weights we are evolving
        self.alleles = [uniform(-10, 10) for n in range(len(genome))]
        self.pendulum = InvertedPendulum(M, m, l)



    def fitness(self, func=None):
        if func == None:
            func = self.time_to_ground()
        return func()


    #in this instance we calculate fitness based on how long
    #the pendulum stays up
    #returns milliseconds
    def time_to_ground(self):
        #TODO perform calulatoin
        time = self.pendulum.applyforce2(u=10)


        return 0

    #in this instance we calculate fitness based on how long
    #the pendulum stays within plus or minus the threshold
    #returns milliseconds
    def time_to_threshold(self):
        #TODO perform calulatoin
        return 0
示例#5
0
 def __init__(self):
     self.running_flag = False
     self.pendulum = InvertedPendulum()