Beispiel #1
0
def products():

    result = {}

    x11 = umatrix.matrix([[0,1,2],[4,5,6],[8,9,10],[12,13,14]])
    x10 = umatrix.matrix([[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]])
    x1 = umatrix.matrix([[0.71,-0.71,0.7],[0.71,0.71,0.5],[0,0,1]])
    y_row = umatrix.matrix([[1,0,1]])
    y_col = umatrix.matrix([1, 0, 1], cstride=1, rstride=1)
    result['matrix * scaler'] = matrix_compare(x10*2, umatrix.matrix([[0, 2, 4, 6],[8, 10, 12, 14],[16, 18, 20, 22],[24, 26, 28, 30]]))
    result['matrix * matrix elementwise'] = matrix_compare(x11*x11, umatrix.matrix([[0, 1, 4],[16, 25, 36],[64, 81, 100],[144, 169, 196]]))
    result['row dot matrix 1x3 . 3x3'] = matrix_compare(ulinalg.dot(y_row,x1), umatrix.matrix([[ 0.71, -0.71,  1.7 ]]))
    try:
        result['matrix dot col 3x3 . 3x1'] = matrix_compare(ulinalg.dot(x1,y_col), umatrix.matrix([1.41, 1.21,  1.0], cstride=1, rstride=1), tol=eps)
    except ValueError:
        result['matrix dot col 3x3 . 3x1'] = False
    x = umatrix.matrix([[ 3., -2., -2.]])
    y = umatrix.matrix([[-1.,  0.,  5.]])
    x1 = umatrix.matrix([[ 3., -2.]])
    y1 = umatrix.matrix([[-1.,  0.]])
    result['cross product (x,y)'] = matrix_compare(ulinalg.cross(x,y), umatrix.matrix([[-10.0 , -13.0 , -2.0]]))
    result['cross product (y,x)'] = matrix_compare(ulinalg.cross(y,x), umatrix.matrix([[10.0 , 13.0 , 2.0]]))
    result['cross product 2 (x,y)'] = matrix_compare(ulinalg.cross(x1,y1), umatrix.matrix([[-2.0]]))
    x = umatrix.matrix([[ 3., -2., -2.],[-1.,  0.,  5.]])
    y = umatrix.matrix([[-1.,  0.,  5.]])
    try:
        result['cross product shape mismatch (x,y)'] = matrix_compare(ulinalg.cross(x,y), umatrix.matrix([[-10.0 , -13.0 , -2.0]]))
    except ValueError:
        result['cross product shape mismatch (x,y)'] = True
    return result
Beispiel #2
0
def products():

    result = {}

    x11 = umatrix.matrix([[0,1,2],[4,5,6],[8,9,10],[12,13,14]])
    x10 = umatrix.matrix([[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]])
    x1 = umatrix.matrix([[0.71,-0.71,0.7],[0.71,0.71,0.5],[0,0,1]])
    y_row = umatrix.matrix([[1,0,1]])
    y_col = umatrix.matrix([1, 0, 1], cstride=1, rstride=1)
    result['matrix * scaler'] = matrix_compare(x10*2, umatrix.matrix([[0, 2, 4, 6],[8, 10, 12, 14],[16, 18, 20, 22],[24, 26, 28, 30]]))
    result['matrix * matrix elementwise'] = matrix_compare(x11*x11, umatrix.matrix([[0, 1, 4],[16, 25, 36],[64, 81, 100],[144, 169, 196]]))
    result['row dot matrix 1x3 . 3x3'] = matrix_compare(ulinalg.dot(y_row,x1), umatrix.matrix([[ 0.71, -0.71,  1.7 ]]))
    try:
        result['matrix dot col 3x3 . 3x1'] = matrix_compare(ulinalg.dot(x1,y_col), umatrix.matrix([1.41, 1.21,  1.0], cstride=1, rstride=1))
    except ValueError:
        result['matrix dot col 3x3 . 3x1'] = False
    x = umatrix.matrix([[ 3., -2., -2.]])
    y = umatrix.matrix([[-1.,  0.,  5.]])
    x1 = umatrix.matrix([[ 3., -2.]])
    y1 = umatrix.matrix([[-1.,  0.]])
    result['cross product (x,y)'] = matrix_compare(ulinalg.cross(x,y), umatrix.matrix([[-10.0 , -13.0 , -2.0]]))
    result['cross product (y,x)'] = matrix_compare(ulinalg.cross(y,x), umatrix.matrix([[10.0 , 13.0 , 2.0]]))
    result['cross product 2 (x,y)'] = matrix_compare(ulinalg.cross(x1,y1), umatrix.matrix([[-2.0]]))
    x = umatrix.matrix([[ 3., -2., -2.],[-1.,  0.,  5.]])
    y = umatrix.matrix([[-1.,  0.,  5.]])
    try:
        result['cross product shape mismatch (x,y)'] = matrix_compare(ulinalg.cross(x,y), umatrix.matrix([[-10.0 , -13.0 , -2.0]]))
    except ValueError:
        result['cross product shape mismatch (x,y)'] = True
    return result
Beispiel #3
0
    def update_imu(self, gyroscope, accelerometer):
        """
        Perform one update step with data from a IMU sensor array
        :param gyroscope: A three-element array containing the gyroscope data in radians per second.
        :param accelerometer: A three-element array containing the accelerometer data. Can be any unit since a normalized value is used.
        """
        q = self.quaternion

        # Normalise accelerometer measurement
        if ulinalg.norm(accelerometer) is 0:
            print("accelerometer is zero")
            return
        accelerometer = accelerometer / ulinalg.norm(accelerometer)

        # Gradient descent algorithm corrective step
        f = umatrix.matrix([
            2 * (q[1] * q[3] - q[0] * q[2]) - accelerometer[0, 0], 2 *
            (q[0] * q[1] + q[2] * q[3]) - accelerometer[0, 1], 2 *
            (0.5 - q[1]**2 - q[2]**2) - accelerometer[0, 2]
        ],
                           cstride=1,
                           rstride=1,
                           dtype=float)

        j = umatrix.matrix([
            -2 * q[2], 2 * q[3], -2 * q[0], 2 * q[1], 2 * q[1], 2 * q[0],
            2 * q[3], 2 * q[2], 0, -4 * q[1], -4 * q[2], 0
        ],
                           cstride=1,
                           rstride=4,
                           dtype=float)

        step = ulinalg.dot(j.transpose(), f)
        step = step / ulinalg.norm(step)  # normalise step magnitude

        # Compute rate of change of quaternion
        qdot = (q * Quaternion(0, gyroscope[0, 0], gyroscope[0, 1],
                               gyroscope[0, 2])) * 0.5 - Quaternion(
                                   step.T * self.beta)

        # Integrate to yield quaternion
        q = q + qdot * (self.samplePeriod)
        self.quaternion = q * (1 / ulinalg.norm(q._q))  # normalise quaternion
Beispiel #4
0
        y = int(round(rd * math.sin(math.radians(azm_i[index] - 90)), 0))
        xm = xc + x
        ym = yc + y
        graphics.fill_circle(xm, ym, 2, 1)

        # show current location if visible
        if visible_i[index] == 'Yes':
            rd = int(round(rad * math.cos(math.radians(alc_i[index])), 0))
            x = int(round(rd * math.cos(math.radians(azc_i[index] - 90)), 0))
            y = int(round(rd * math.sin(math.radians(azc_i[index] - 90)), 0))
            xcu = xc + x
            ycu = yc + y
            graphics.circle(xcu, ycu, 2, 1)

        # find path of transit
        A = matrix.matrix([[xr**2, xr, 1], [xm**2, xm, 1], [xs**2, xs, 1]])
        B = matrix.matrix([[yr], [ym], [ys]])
        d_i = linalg.det_inv(A)
        invA = d_i[1]
        X = linalg.dot(invA, B)

        for i in range(xr - xs):
            x = xs + i
            oled.pixel(x, yc - int((X[0] * x**2)) + int(
                (X[1] * x)) + int(X[2]), 1)

        oled.show()
        utime.sleep(10)

    # collect garbage just in case that is causing the crashes
    gc.collect()
Beispiel #5
0
def skyChart(name):
    # display stuff
    oled.text(name, 0, 0)
    oled.text("Visible:", 0, 10)
    oled.text(visible_i[names.index(name)], 80, 10)
    oled.show()

    # sky chart
    xc = 94
    yc = 31
    rad = 29
    graphics.circle(xc, yc, rad, 1)

    # show planet rise azimuth
    x = int(
        round(rad * math.cos(math.radians(azr_i[names.index(name)] - 90)), 0))
    y = int(
        round(rad * math.sin(math.radians(azr_i[names.index(name)] - 90)), 0))
    xr = xc + x
    yr = yc + y
    graphics.fill_circle(xr, yr, 2, 1)

    # show planet set azimuth
    x = int(
        round(rad * math.cos(math.radians(azs_i[names.index(name)] - 90)), 0))
    y = int(
        round(rad * math.sin(math.radians(azs_i[names.index(name)] - 90)), 0))
    xs = xc + x
    ys = yc + y
    graphics.fill_circle(xs, ys, 2, 1)

    # show location at maximum altitude
    rd = int(round(rad * math.cos(math.radians(alm_i[names.index(name)])), 0))
    x = int(
        round(rd * math.cos(math.radians(azm_i[names.index(name)] - 90)), 0))
    y = int(
        round(rd * math.sin(math.radians(azm_i[names.index(name)] - 90)), 0))
    xm = xc + x
    ym = yc + y
    graphics.fill_circle(xm, ym, 2, 1)

    # show current location if visible
    if visible_i[index] == 'Yes':
        rd = int(
            round(rad * math.cos(math.radians(alc_i[names.index(name)])), 0))
        x = int(
            round(rd * math.cos(math.radians(azc_i[names.index(name)] - 90)),
                  0))
        y = int(
            round(rd * math.sin(math.radians(azc_i[names.index(name)] - 90)),
                  0))
        xcu = xc + x
        ycu = yc + y
        graphics.circle(xcu, ycu, 2, 1)

    # find path of transit
    A = matrix.matrix([[xr**2, xr, 1], [xm**2, xm, 1], [xs**2, xs, 1]])
    B = matrix.matrix([[yr], [ym], [ys]])
    d_i = linalg.det_inv(A)
    invA = d_i[1]
    X = linalg.dot(invA, B)

    for i in range(xr - xs):
        x = xs + i
        oled.pixel(x, yc - int((X[0] * x**2)) + int((X[1] * x)) + int(X[2]), 1)

    oled.show()

    # collect garbage just in case that is causing the crashes
    gc.collect()