Esempio n. 1
0
def main():
    print("Main Start")
    g = gr.Graph()
    g.readVertexFile('vertices.txt')
    g.readEdgeFile('only_with_pairs.txt')
    print(len(g.V))
    drawing.setID(g)  # вставь граф
    physics.setConstans(g)

    while True:
        physics.physStep(g)
        drawing.drawing(g) #вставь граф
        drawing.canvas.update()
        rotate.rotate(g, [1, 2, 3], 0.01)
def main():

    # default simulation parameter values
    g = 10
    dt = 0.04
    m1 = float(input("Mass 1 : "))
    m2 = 7.0
    t1 = t2 = 0.5
    w1 = w2 = 2.5
    L1 = L2 = 1.0

    # default window dimensions
    cwidth = cheight = 500

    # by default, use the Euler-Lagrange equations to simulate the system
    lagrangian = True

    # in test mode, no window is displayed (only text output is produced)
    test_mode = False

    # initialize the double pendulum
    if lagrangian == True:
        from dp_lagrangian import DoublePendulumLagrangian
        obj = DoublePendulumLagrangian(g, m1, m2, t1, t2, w1, w2, L1, L2)
    else:
        from dp_hamiltonian import DoublePendulumHamiltonian
        obj = DoublePendulumHamiltonian(g, m1, m2, t1, t2, w1, w2, L1, L2)

    step = 0

    # maximum energy change (compared to E0): too large => unstable simulation

    # set up the clock and the output window
    if test_mode == False:
        pygame.init()
        clock = pygame.time.Clock()
        canvas = pygame.display.set_mode((cwidth, cheight), pygame.RESIZABLE)
        pygame.display.set_caption("double pendulum")

    # keep running the simulation until the user closes the window
    while True:

        # redraw the double pendulum at a maximum rate of 25 fps
        if test_mode == False:
            drawing.drawing(obj, canvas, cwidth, cheight, dt)
            clock.tick(25)
        # advance one time step
        obj.time_step(dt)
        step += 1
Esempio n. 3
0
def main2():
    print("Main Start")
    g1 = gr.Graph()
    g2 = gr.Graph()
    g1.createCircle(2)
    g2.createCircle(2)
    g3 =  gr.multiply(g1, g2)
    g4 =  gr.multiply(g1, g3)
    g = gr.multiply(g1, g3)

    print(len(g.V))
    drawing.setID(g)  # вставь граф
    physics.setConstans(g)

    while True:
        physics.physStep(g)
        physics.physStep(g)
        drawing.drawing(g) #вставь граф
        drawing.canvas.update()
        rotate.rotate(g, [1, 2, 3], 0.001)
        time.sleep(1/60)
Esempio n. 4
0
def printMap():
    draw = drawing.drawing()
    draw.setAxes(x_min=-1000, x_max=13000, y_min=-1000, y_max=18000)
    draw = drawObstacle(draw)
    map_data = readJsonFile(path + filename)
    for key in map_data.keys():
        is_enable = map_data[key]['enable']
        x_cood = map_data[key]['cood'][0]
        y_cood = map_data[key]['cood'][1]
        if is_enable == True:
            draw.drawCircle(x_cood, y_cood, 50, "#A4C520", True)
        if is_enable == False:
            draw.drawCircle(x_cood, y_cood, 50, "#717171", True)

    draw.show()
Esempio n. 5
0
def main():

  er_sum = 0
  num = 0

  #基地局からの距離
  dis_deviceA = 0
  dis_deviceB = 0
  dis_deviceC = 0

  c = np.mat([[1, 0], [0, 1]])
  p_1 = np.mat([[AP_A_X], [AP_A_Y]])
  p_2 = np.mat([[AP_B_X], [AP_B_Y]])
  p_3 = np.mat([[AP_C_X], [AP_C_Y]])

  draw = drawing.drawing()
  draw = setDraw(draw)

  '''
  # 歩いていると仮定した場合
  for i in range(POINT_NUM):
    truePosition = selectPosition(i + 1)
    draw.drawCircle(truePosition[0][0], truePosition[1][0], 100, "#050A11", True)'''

  
  if filter == 1:
      kf = kalman.KalmanFilter(TRUE_POSITION_1_X, TRUE_POSITION_1_Y, p_1, p_2, p_3)
      #kf = kalman.KalmanFilter(0, 0, p_1, p_2, p_3)
      kf.setModel(o_walk=O_WALK, o_range=O_RANGE)
      #kf.setModel(O_WALK, O_RANGE, r)
  elif filter == 2:
      bf = bayesian.BaysianFilter(POINT_1_GRID, p_i, sigma_range)
      bf.readMap(map_path)
  elif filter == 3:
      bkm = bkmixture.BKmixture(p_i)
      bkm.setKalman([TRUE_POSITION_1_X, TRUE_POSITION_1_Y], p_1, p_2, p_3, O_WALK, O_RANGE, r)
      bkm.setBayesian(sigma_range, map_path)

  with open(write_path + write_file + '8' + '.csv', mode='w') as fw:
     with open(read_path + read_file + 'A' + '.csv', encoding='utf-8', mode='r') as f:
      for line in f:
          data = line.split(',')
          distanceMm = int(data[0])
          getID = int(data[4])
          #truenum = int(data[5])

          #ファイルから取得したデータをcalibrate
          if getID == DEVICE_A_ID:
            dis_deviceA = calibration(getID, distanceMm)
          elif getID == DEVICE_B_ID:
            dis_deviceB = calibration(getID, distanceMm)
          elif getID == DEVICE_C_ID:
            dis_deviceC = calibration(getID, distanceMm)

          #測距結果を用いて測位
          if dis_deviceA != 0 and dis_deviceB != 0 and dis_deviceC != 0:
            Z = np.mat([[dis_deviceA], [dis_deviceB], [dis_deviceC]])
            time = 0
            if filter == 1:
              kf.estimate()
              #kf.filter(Z)
              kf.filter(np.square(Z))
              x = kf.getStatus()
            elif filter == 2:
              grid = 1
              was_grid = 0
              for key in range(8):
                was_grid = grid
                bf.prediction()
                x, grid = bf.update(Z)
                if grid != was_grid:
                  time += 1
                print(str(grid) + ',' + str(was_grid))
            elif filter == 3:
              x, grid = bkm.estimate(Z)

            dis_deviceA = 0
            dis_deviceB = 0
            dis_deviceC = 0
            #er = error(x, num + 1)
            #er_sum += er
            fw.write(str(int(x[0, 0])) + ',' + str(int(x[1, 0])) + ',' + str(time) + ',' + '\n')
            mod = num % 8
            if mod == 0:
              draw.drawCircle(x[0, 0], x[1, 0], 100, "#EDAD0B", True)
            elif mod == 1:
              draw.drawCircle(x[0, 0], x[1, 0], 100, "#C7243A", True)
            elif mod == 2:
              draw.drawCircle(x[0, 0], x[1, 0], 100, "#D8E212", True)
            elif mod == 3:
              draw.drawCircle(x[0, 0], x[1, 0], 100, "#23AC0E", True)
            elif mod == 4:
              draw.drawCircle(x[0, 0], x[1, 0], 100, "#0086AB", True)
            elif mod == 5:
              draw.drawCircle(x[0, 0], x[1, 0], 100, "#3261AB", True)
            elif mod == 6:
              draw.drawCircle(x[0, 0], x[1, 0], 100, "#5D639E", True)
            elif mod == 7:
              draw.drawCircle(x[0, 0], x[1, 0], 100, "#A52175", True)
            num += 1
            #print('a')
            #draw.pause(0.1)
      draw.show()

  '''
  for num in range(POINT_NUM):
    filename = FILE_NAME
    truePosition = selectPosition(num + 1)
    print("now:" + str(now_grid))
    print("position:" + str(truePosition))
    draw.drawCircle(truePosition[0, 0], truePosition[1, 0], 100, "#050A11", True)
    if filter == 1:
      #kf = kalman.KalmanFilter(truePosition[0, 0], truePosition[1, 0], p_1, p_2, p_3)
      kf = kalman.KalmanFilter(0, 0, p_1, p_2, p_3)
      kf.setModel(O_WALK, O_RANGE, r)
    elif filter == 2:
      bf = bayesian.BaysianFilter(now_grid, p_i, sigma_range)
      # bf.readMap('/Users/andy/Wifi_rtt/mapInfo.json')
      bf.readMap(map_path)
    elif filter == 3:
      bkm = bkmixture.BKmixture(p_i)
      bkm.setKalman([truePosition[0, 0], truePosition[1, 0]], p_1, p_2, p_3, O_WALK, O_RANGE, r)
      bkm.setBayesian(sigma_range, map_path)

    with open(write_path + write_file + str(num+1) + '.csv', mode='w') as fw:
     with open(read_path + read_file + str(num+1) + '.csv', encoding='utf-8', mode='r') as f:
      f.readline()
      for line in f:
          data = line.split(',')
          distanceMm = int(data[0])
          getID = int(data[4])
          #truenum = int(data[5])

          #ファイルから取得したデータをcalibrate
          if getID == DEVICE_A_ID:
            dis_deviceA = calibration(getID, distanceMm)
          elif getID == DEVICE_B_ID:
            dis_deviceB = calibration(getID, distanceMm)
          elif getID == DEVICE_C_ID:
            dis_deviceC = calibration(getID, distanceMm)
            
          #測距結果を用いて測位
          if dis_deviceA != 0 and dis_deviceB != 0 and dis_deviceC != 0:
            Z = np.mat([[dis_deviceA], [dis_deviceB], [dis_deviceC]])
            if filter == 1:
              kf.estimate()
              #kf.filter(Z)
              kf.filter(np.square(Z))
              x = kf.getStatus()
            elif filter == 2:
              grid = 1
              was_grid = 0
              for key in range(5):
                was_grid = grid
                bf.prediction()
                x, grid = bf.update(Z)
                print(str(grid) + ',' + str(was_grid))
            elif filter == 3:
              x, grid = bkm.estimate(Z)
            
            dis_deviceA = 0
            dis_deviceB = 0
            dis_deviceC = 0
            er = error(x, num + 1)
            er_sum += er
            fw.write(str(x[0, 0]) + ',' + str(x[1, 0]) + ',' + str(er) + ',' + '\n')
            draw.drawCircle(x[0, 0], x[1, 0], 100, "#EDAD0B", True)
            #print('a')
            #draw.pause(0.1)
  '''
  #draw.show()
  return
Esempio n. 6
0
# coding=utf-8
import argparse
from drawing import drawing

parser = argparse.ArgumentParser(description=u"Aplica efeito de desenho a lápis em foto.")
group = parser.add_mutually_exclusive_group()

group.add_argument("-v", "--verbose", action="store_true")
group.add_argument("-q", "--quiet", action="store_true")

parser.add_argument("foto", type=str, help=u"Nome da foto que será transformada. Ex.: foto.jpg")
parser.add_argument("desenho", type=str, help=u"Nome da foto depois de transformada. Ex.: desenho.jpg")
parser.add_argument("--blur", type=int, default=25, dest="blur", help=u"Configura o valor da desfocagem. Ex.: 25")
parser.add_argument("--alpha", type=float, default=1.0, dest="alpha", help=u"Configura o valor da transparencia. Ex.: 0.5 para 50% de transparencia")

args = parser.parse_args()

drawing(args.foto, args.desenho, blur=args.blur, alpha=args.alpha)

if args.quiet:
    pass

elif args.verbose:
    print "A imagem {0} foi convertida para {1}".format(args.foto, args.desenho)
    print "Com blur: {0} e alpha: {1}".format(args.blur, args.alpha)

else:
    print "{0} -> {1}".format(args.foto, args.desenho)
Esempio n. 7
0
        result_value.append(temp_value)
        true_value.append(math.sin(tt))
        tt += 0.1
    return result_value, true_value


t = [i for i in range(0, 11)]
y = []

true_value = []

for i in t:
    noise = np.random.normal(loc=0, scale=0.2)
    y.append(math.sin(i) + noise)

#used to dot the noise values
yy = [None for _ in range(101)]
for i in range(0, 11):
    yy[i * 10] = y[i]

t = np.array(t)
y = np.array(y)

phi = np.vander(t)
x = np.dot(np.linalg.inv(phi), y.T)

result, true_value = calc(x)

print(y)
drawing(yy, result, true_value, '10dim')
Esempio n. 8
0
def update_graph(checklist, range_l, n):
    return draw.drawing(df, checklist, range_l)
Esempio n. 9
0
import drawing
drawing.drawing()