예제 #1
0
 def draw(self):
     x,y,z = motion.get_attitude() if use_motion else scene.gravity()
     r,g,b = abs(x), abs(y), abs(z)  # No negative colors
     scene.background(r, g, b)
     scene.tint(1-r, 1-g, 1-b)
     scene.text(fmt.format(x, y, z), font_size=32,
                x=self.center.x, y=self.center.y)
예제 #2
0
 def draw(self):
     x,y,z = motion.get_attitude() if use_motion else scene.gravity()
     r,g,b = abs(x), abs(y), abs(z)
     scene.background(r, g, b)
     super(Advice, self).draw()
     scene.tint(1-r, 1-g, 1-b)
     scene.text(self.answer, 'Futura', 45, *self.center)
예제 #3
0
def environ_data(sender):
    import motion
    import location

    motion.start_updates()
    location.start_updates()

    x = motion.get_attitude()
    environ['att'].text = str(x) + '\n' + environ['att'].text
    x = motion.get_gravity()
    environ['grav'].text = str(x) + '\n' + environ['grav'].text
    x = motion.get_user_acceleration()
    environ['acc'].text = str(x) + '\n' + environ['acc'].text
    x = motion.get_magnetic_field()
    environ['mag'].text = str(x) + '\n' + environ['mag'].text

    x = location.get_location()
    coord = {'latitude': x['latitude'], 'longitude': x['longitude']}
    print(coord)
    y = location.reverse_geocode(coord)
    print(y)
    environ['geo'].text = str(x)

    motion.stop_updates()
    location.stop_updates()
예제 #4
0
def motion_color(): 
    if not main_view.on_screen : 
        motion.stop_updates()
        sys.exit(999)
    color=  motion.get_attitude()
    main_view.background_color = color
    ui.delay(motion_color, .1)
예제 #5
0
def motion_color():
    if not main_view.on_screen:
        motion.stop_updates()
        sys.exit(999)
    color = motion.get_attitude()
    main_view.background_color = color
    ui.delay(motion_color, .1)
예제 #6
0
def main():
    num_samples = 1000000
    arrayA = []
    arrayM = []
    #arrayG = []
    arrayP = []
    arrayJ = []
    arrayGPS = []  #GPS
    dataArray = []

    CMAltimeter = ObjCClass('CMAltimeter')
    NSOperationQueue = ObjCClass('NSOperationQueue')
    if not CMAltimeter.isRelativeAltitudeAvailable():
        print('This device has no barometer.')
        return
    altimeter = CMAltimeter.new()
    main_q = NSOperationQueue.mainQueue()
    altimeter.startRelativeAltitudeUpdatesToQueue_withHandler_(
        main_q, handler_block)
    motion.start_updates()
    location.start_updates()  # GPS
    print("Logging start...")
    sleep(1.0)
    for i in range(num_samples):
        sleep(0.05)
        a = motion.get_user_acceleration()
        m = motion.get_magnetic_field()
        j = motion.get_attitude()
        gps = location.get_location()  # GPS
        if a[1] > 0.8:
            break
        dataArray.append([relativeAltitude, a[2], m[0], m[1]])
        arrayA.append(a)
        arrayM.append(m)
        arrayJ.append(j)
        arrayP.append(relativeAltitude)
        arrayGPS.append(gps)  #GPS

    motion.stop_updates()
    location.stop_updates()  # GPS
    altimeter.stopRelativeAltitudeUpdates()
    print("Logging stop and Saving start...")
    import pickle
    f = open('yokohama.serialize', 'wb')
    #pickle.dump([arrayA, arrayM, arrayP],f)
    pickle.dump([arrayA, arrayM, arrayJ, arrayP, arrayGPS], f)  #GPS
    f.close
    print("Saving is finished.")
    x_values = [x * 0.05 for x in range(len(dataArray))]
    for i, color, label in zip(range(3), 'rgb', 'XYZ'):
        plt.plot(x_values, [g[i] for g in arrayM], color, label=label, lw=2)
    plt.grid(True)
    plt.xlabel('t')
    plt.ylabel('G')
    plt.gca().set_ylim([-100, 100])
    plt.legend()
    plt.show()
예제 #7
0
    def draw(self):
        global box_node, box
        global pitch, roll, yaw, ax, ay, az, gx, gy, gz
        global main_view
        global ax1, fig
        #処理が追い付かないのでタイマーをいれる
        #time.sleep(0.01)
        #加速度、ジャイロの値を更新
        ax, ay, az = motion.get_user_acceleration()
        gx, gy, gz = motion.get_gravity()
        gravity_vectors = motion.get_attitude()
        mgx, mgy, mgz, mga = motion.get_magnetic_field()

        pitch, roll, yaw = [x for x in gravity_vectors]
        # ラジアン→度へ変換
        pitch = -pitch * 180 / 3.1415926
        roll = roll * 180 / 3.1415926
        yaw = -yaw * 180 / 3.1415926
        #再描画
        box_node.runAction_(
            SCNAction.rotateToX_y_z_duration_(math.pi * pitch / 180,
                                              math.pi * roll / 180,
                                              -math.pi * yaw / 180, 0))
        #加速度、ジャイロ、地磁気センサーの値を表示
        main_view['ax'].text = str(round(ax, 2))
        main_view['ay'].text = str(round(ay, 2))
        main_view['az'].text = str(round(az, 2))

        main_view['gx'].text = str(round(gx, 2))
        main_view['gy'].text = str(round(gy, 2))
        main_view['gz'].text = str(round(gz, 2))

        main_view['mx'].text = str(round(mgx, 2))
        main_view['my'].text = str(round(mgy, 2))
        main_view['mz'].text = str(round(mgz, 2))
        # graphics
        self.py.pop(0)
        self.ry.pop(0)
        self.yy.pop(0)  # left
        self.py.append(pitch)
        self.ry.append(roll)
        self.yy.append(yaw)  # add data

        ax1.plot(self.xl, self.py, color='lightgreen', lw='1')  # pitch graph
        ax1.plot(self.xl, self.ry, color='red', lw='1')  # roll graph
        ax1.plot(self.xl, self.yy, color='skyblue', lw='1')  # yaw graph

        plt.savefig('rt.png')  # save the graph on the consolen
        main_view['imageview1'].image = ui.Image.named('rt.png')  # imageview
        plt.cla()  # clear graph
        plt.close()  # close graph
        fig = plt.figure()  #
        ax1 = fig.add_subplot(111)  #
        ax1.grid(True)
        ymin = -180
        ymax = 180
        plt.ylim(ymin, ymax)
예제 #8
0
    def update(self):

        UIDevice = ObjCClass('UIDevice').currentDevice()
        #print(UIDevice.orientation())
        # https://developer.apple.com/documentation/uikit/uideviceorientation?language=objc
        # 6 = UIDeviceOrientationFaceDown

        self.ori.text = str(UIDevice.orientation())

        att = motion.get_attitude()
        self.att.text = '{:.3f} {:.3f} {:.3f}'.format(math.degrees(att[0]),
                                                      math.degrees(att[1]),
                                                      math.degrees(att[2]))
예제 #9
0
def ios(rate=quantity(1, units.second)):
    """Retrieve motion information from an iOS device.

    This component requires the `motion` module provided by Pythonista.

    Parameters
    ----------
    rate: time quantity, required
        Rate at which motion data will be retrieved.

    Yields
    ------
    records: dict
        Records will contain information including the current acceleration due to gravity and the user, along with device attitude.
    """

    import time
    import motion # pylint: disable=import-error

    rate = rate.to(units.seconds).magnitude

    motion.start_updates()

    try:
        while True:
            gravity = quantity(motion.get_gravity(), units.meters * units.seconds * units.seconds)
            acceleration = quantity(motion.get_user_acceleration(), units.meters * units.seconds * units.seconds)
            attitude = quantity(motion.get_attitude(), units.radians)

            record = dict()
            add_field(record, ("gravity", "x"), gravity[0])
            add_field(record, ("gravity", "y"), gravity[1])
            add_field(record, ("gravity", "z"), gravity[2])

            add_field(record, ("acceleration", "x"), acceleration[0])
            add_field(record, ("acceleration", "y"), acceleration[1])
            add_field(record, ("acceleration", "z"), acceleration[2])

            add_field(record, ("attitude", "roll"), attitude[0])
            add_field(record, ("attitude", "pitch"), attitude[1])
            add_field(record, ("attitude", "yaw"), attitude[2])

            yield record

            time.sleep(rate)

    except GeneratorExit:
        motion.stop_updates()
예제 #10
0
	def draw(self):
		x,y,z = motion.get_attitude() if use_motion else scene.gravity()
		r,g,b = abs(x), abs(y), abs(z)
		scene.background(r, g, b)
		scene.tint(1-r, 1-g, 1-b)
		scene.text(answer.format(x, y, z), font_size=45, x=self.center.x, y=self.center.y)
		for p in self.particles:
			p.update()
			p.draw()
		for t in self.touches.values():
			for p in self.particles:
				tx, ty = t.location.x, t.location.y
				d = (p.x - tx)*(p.x - tx)+(p.y - ty)*(p.y - ty)
				d = sqrt(d)
				p.vx = p.vx - 5/d*(p.x-tx)
				p.vy = p.vy - 5/d*(p.y-ty)
				p.colour = Color(random.random(), random.random(), random.random())
예제 #11
0
    def draw(self):
        gravity_vectors = motion.get_attitude()
        roll, pitch, yaw = [
            x if x < 1.0 else 1.0 for x in [abs(x) for x in gravity_vectors]
        ]
        background(pitch, roll, yaw)

        tint(1, 1, 1)
        self.fpslist.append(1 / self.dt)
        self.fps = mean(self.fpslist, 5)

        fpstext = str(self.fps)[:4] + ' FPS'
        text(fpstext, x=5, y=5, alignment=9)

        rgbtext = 'R: ' + str(pitch)[:5] + '  G: ' + str(
            roll)[:5] + '  B: ' + str(yaw)[:5]
        text(rgbtext, x=self.size.w - 5, y=5, alignment=7)
예제 #12
0
    def update(self):
        m = motion.get_magnetic_field()
        self.mf.text = '{:.1f} {:.1f} {:.1f} {:.3f}'.format(
            m[0], m[1], m[2], m[3])

        acc = motion.get_user_acceleration()
        self.acc.text = '{:.3f} {:.3f} {:.3f}'.format(acc[0], acc[1], acc[2])

        grav = motion.get_gravity()
        self.grav.text = '{:.3f} {:.3f} {:.3f}'.format(grav[0], grav[1],
                                                       grav[2])

        #determine screen orientation. Portrait modes flip 180 deg if the device is face down. Use local z gravity to detect.

        orient = int(self.wv.eval_js('window.orientation'))

        if (orient == 0):
            #portrait, home button on bottom
            if grav[2] <= 0.:
                init_angle = -90
            else:
                init_angle = 90

        elif (orient == 90):
            #landscape, home button on right
            init_angle = 0

        elif (orient == -90):
            #landscape, home button on right
            init_angle = 180

        else:
            #portrait, home button on top
            if grav[2] <= 0.:
                init_angle = 90
            else:
                init_angle = -90

        self.ori.text = str(orient)

        att = motion.get_attitude()
        self.att.text = '{:.3f} {:.3f} {:.3f}'.format(att[0], att[1], att[2])

        ang = (init_angle - int(math.degrees(att[2]))) % 360
        self.ang.text = str(ang)
예제 #13
0
def main():
    console.alert('Magentic Experiment 2',
                  'yo gang gang, we gonna measure this motion', 'Continue')
    motion.start_updates()
    sleep(0.2)
    print('Capturing motion data...')
    while True:
        sleep(0.5)
        current = motion.get_attitude()
        newMotion = [0, 0, 0]
        for i in range(len(current)):
            newMotion[i] = (current[i] * (10**2)) // 1
        roll = newMotion[0]
        pitch = newMotion[1]
        yaw = newMotion[2]
        print(roll, pitch, yaw)
    motion.stop_updates()
    print('Capture finished, plotting...')
예제 #14
0
 async def gravity(self, instance, async_lib):
     motion.start_updates()
     try:
         while True:
             timestamp = time.time()
             gravity = motion.get_gravity()
             user_acceleration = motion.get_user_acceleration()
             attitude = motion.get_attitude()
             magnetic_field = motion.get_magnetic_field()
             await self.gravity.write(value=gravity, timestamp=timestamp)
             await self.user_acceleration.write(value=user_acceleration,
                                                timestamp=timestamp)
             await self.attitude.write(value=attitude, timestamp=timestamp)
             await self.magnetic_field.write(value=magnetic_field,
                                             timestamp=timestamp)
             await async_lib.library.sleep(0.01)
     finally:
         # TODO: put in @gravity.shutdown when in released version
         motion.stop_updates()
예제 #15
0
def Main(socket):   
    print('Server Started')
    
    s.listen(1)
    c, addr = s.accept()
    print('Connection From: ' + str(addr))
    
    motion.start_updates()
    while True:
        xaccel, yaccel, zaccel= motion.get_gravity()
        xrot, yrot, zrot= motion.get_attitude()
        message= str(xaccel)[:6] + ',' + str(yaccel)[:6] + ',' + str(zaccel)[:6] + ','+ str(xrot)[:6] + ',' + str(yrot)[:6] + ',' + str(zrot)[:6]
        print(message)
        try:
            c.send(str(message))
            time.sleep(0.05)
        except:
            break
    c.close()
    Main(socket)
예제 #16
0
    def check_motion(self):
        s1 = 1.0
        s2 = 1.5

        b = 0.2
        n = motion.get_attitude()
        c = self.calib
        x = round((n[0] - c[0]) * s1, 2) * self.accelerometer_speed
        z = round((n[2] - c[2]) * s2, 2) * self.accelerometer_speed
        d1 = ""
        d2 = ""

        if not (x > b or x < -b):
            x = 0.0
        else:
            d1 = "Looking %s" % ("down" if x > 0 else "up")

        if not (z > b or z < -b):
            z = 0.0
        else:
            d2 = "Looking %s" % ("left" if z > 0 else "right")

        self.label.text = "%s\t%s\n%s\t%s" % (x, d1, z, d2)
        self.label.set_needs_display()
        if x != 0.0 or z != 0.0:
            try:
                getRenderEngine().look_f([-z, -x])
            except NotImplementedError:
                print "Function Not Implimented"

        m = self.dir_move
        d3 = ''
        d4 = ''
        if m[1] != 0:
            d3 = 'Moving %s' % ('forward' if m[1] > 0 else
                                'backward' if m[1] < 0 else '')
        if m[0] != 0:
            d4 = 'Strafe %s' % ('left'
                                if m[0] > 0 else 'right' if m[0] < 0 else '')
        self.label2.text = '%s\n%s' % (d3, d4)
        self.label2.set_needs_display()
예제 #17
0
 def draw(self):
     x, y, z = motion.get_attitude() if use_motion else scene.gravity()
     r, g, b = abs(x), abs(y), abs(z)
     scene.background(r, g, b)
     scene.tint(1 - r, 1 - g, 1 - b)
     scene.text(answer.format(x, y, z),
                font_size=45,
                x=self.center.x,
                y=self.center.y)
     for p in self.particles:
         p.update()
         p.draw()
     for t in self.touches.values():
         for p in self.particles:
             tx, ty = t.location.x, t.location.y
             d = (p.x - tx) * (p.x - tx) + (p.y - ty) * (p.y - ty)
             d = sqrt(d)
             p.vx = p.vx - 5 / d * (p.x - tx)
             p.vy = p.vy - 5 / d * (p.y - ty)
             p.colour = Color(random.random(), random.random(),
                              random.random())
예제 #18
0
 def check_motion(self):
     s1 = 1.0
     s2 = 1.5
     
     b = 0.2
     n = motion.get_attitude()
     c = self.calib
     x = round((n[0] - c[0]) * s1, 2) * self.accelerometer_speed
     z = round((n[2] - c[2]) * s2, 2) * self.accelerometer_speed
     d1 = ""
     d2 = ""
     
     if not (x > b or x < -b):
         x = 0.0
     else:
         d1 = "Looking %s" % ("down" if x > 0 else "up")
         
     if not (z > b or z < -b):
         z = 0.0
     else:
         d2 = "Looking %s" % ("left" if z > 0 else "right")
     
     self.label.text = "%s\t%s\n%s\t%s" % (x, d1, z, d2)
     self.label.set_needs_display()
     if x != 0.0 or z != 0.0:
         try:
             getRenderEngine().look_f([-z, -x])
         except NotImplementedError:
             print "Function Not Implimented"
     
     m = self.dir_move
     d3 = ''
     d4 = ''
     if m[1] != 0:
         d3 = 'Moving %s' % ('forward' if m[1] > 0 else 'backward' if m[1] < 0 else '')
     if m[0] != 0:
         d4 = 'Strafe %s' % ('left' if m[0] > 0 else 'right' if m[0] < 0 else '')
     self.label2.text = '%s\n%s' % (d3, d4)
     self.label2.set_needs_display()
예제 #19
0
 def attitude(self):
     return {
         key: val
         for key, val in zip(('roll', 'pitch',
                              'yaw'), motion.get_attitude())
     }
예제 #20
0
    def draw(self):
        #set the background color to the theme's background color
        self.background_color = self.theme["backgroundColor"]

        time.sleep(0.05)  #time between each redraw
        self.timerCount += 1  #add to the timer to animate and do things

        #Title Text
        tint(self.theme["titleColor"])
        # text('Thread', font_name='Courier', font_size=16.0, x=self.centerX2, y=self.centerY2+self.scale+400, alignment=5)

        #Locations recorded count
        tint(self.theme["locationCount"])
        locationCountText = "Locations: " + str(len(self.locations))
        text(locationCountText, font_name='Verdana', font_size=10, x=50, \
        y=self.centerY2+self.scale+400, alignment=5)

        #print the amount of locations left on the journey
        def remainingText(self):
            locationLeftText = "Remaining: " + str(len(self.locationsLeft))
            text(locationLeftText, font_name='Verdana', font_size=10, \
            x=self.size.x-60, y=self.centerY2+self.scale+400, alignment=5)

        if self.functionState == 4:
            remainingText(self)

        #motion vectors
        gravX, gravY, gravZ = motion.get_gravity()
        gravityVectors = motion.get_attitude()
        pitch = gravityVectors[0]
        roll = gravityVectors[1]
        yaw = gravityVectors[2]

        #convert yaw to degrees
        yaw = -yaw * 180 / math.pi
        pitch = -pitch * 180 / math.pi
        roll = -roll * 180 / math.pi

        #draw Reset Button
        def makeResetButton(self):
            fill(self.theme["buttonFill"])
            stroke_weight(0)
            ellipse(self.centerX2-self.scale*3-self.scale,\
            self.centerY2-self.scale-130,self.scale*2,self.scale*2)
            tint(self.theme["buttonText"])
            text('Reset', font_name='Verdana', font_size=12.0, \
            x=self.centerX2-112, y=self.centerY2+self.scale-167, alignment=5)

        #LOCATION GET
        current = location.get_location()
        #latLong will be the location used through every redraw
        latLong = (round(current['latitude'],
                         4), round(current['longitude'], 4))
        #solved the close points problem using rounding
        picTaken = latLong in self.photoLocations

        #orientation calculation
        yawSin = math.sin(math.radians(yaw))
        yawCos = math.cos(math.radians(yaw))

        #derive the direction (NSEW) from the degrees
        def directionText(yaw):
            directionSym = ''
            #Direction
            if yaw > 60 and yaw <= 120:
                directionSym = 'N'
            elif yaw > 120 and yaw <= 150:
                directionSym = 'NE'
            elif (yaw > 150 and yaw <= 180) or (yaw >= -180 and yaw <= -150):
                directionSym = 'E'
            elif yaw > -150 and yaw <= -120:
                directionSym = 'SE'
            elif yaw > -120 and yaw <= -60:
                directionSym = 'S'
            elif yaw > -60 and yaw <= -30:
                directionSym = 'SW'
            elif yaw > -30 and yaw <= 30:
                directionSym = 'W'
            elif yaw > 30 and yaw <= 60:
                directionSym = 'NW'
            else:
                directionSym = ''
            return directionSym

        #draw the compass on the bottom right and make it work
        def drawCompass(self):
            #compass draw
            tint(self.theme["compassTint"])
            stroke(self.theme["compassStroke"])
            stroke_weight(0)
            fill(self.theme["compassFill1"])
            ellipse(self.centerX2+self.scale*3-self.scale,self.centerY2-\
            self.scale-130,self.scale*2,self.scale*2)
            stroke_weight(0)
            ellipse(self.centerX2+self.scale*3-self.scale+3,self.centerY2-\
            self.scale-127,self.scale*1.85,self.scale*1.85)
            ellipse(self.centerX2+self.scale*3-self.scale+6,self.centerY2-\
            self.scale-124,self.scale*1.7,self.scale*1.7)

            stroke_weight(2)
            stroke(self.theme["compassStrokeSouth"])
            line(self.centerX2-yawCos*self.scale+self.scale*3,self.centerY2-\
            yawSin*self.scale-130,self.centerX2+yawCos*self.scale+\
            self.scale*3,self.centerY2+yawSin*self.scale-130)
            stroke(self.theme["compassStrokeNorth"])
            line(300,72.5,self.centerX2+yawCos*self.scale+self.scale*3,\
            self.centerY2+yawSin*self.scale-130)

            #circle on top of compass
            stroke_weight(0)
            stroke(self.theme["compassStroke"])
            fill(self.theme["compassTopFill"])
            ellipse(self.centerX2+self.scale*3-self.scale+9.5,\
            self.centerY2-self.scale-120.5,self.scale*1.5,self.scale*1.5)

            #compass text
            tint(self.theme["buttonText"])
            if self.compassStat == False:
                text(directionText(yaw), font_name='Verdana', font_size=10.0, \
                x=self.centerX2+self.scale*3, y=self.centerY2+self.scale-167, \
                alignment=5)
            else:
                tempYaw = yaw + 180 + 90
                if tempYaw > 360:
                    tempYaw = tempYaw % 360
                yawString = str(int(round(tempYaw, 0))) + chr(186)
                text(yawString, font_name='Verdana', font_size=10.0, \
                x=self.centerX2+self.scale*3, y=self.centerY2+self.scale-167, \
                alignment=5)

        #Center Screen Text (decide what is being displayed)
        def centerScreenText(self):
            tint(self.theme["mainTextColor"])
            if self.measuringOn == False and self.functionState == 0:
                text('Tap to Start', font_name='Verdana', font_size=16.0, \
                x=self.centerX2, y=self.centerY2+self.scale+150, alignment=5)
            elif self.measuringOn == True and self.functionState == 1:
                if self.timerCount // 20 % 3 == 0:
                    text('Recording Journey.', font_name='Verdana', \
                    font_size=16.0, x=self.centerX2, \
                    y=self.centerY2+self.scale+150, alignment=5)
                elif self.timerCount // 20 % 3 == 1:
                    text('Recording Journey..', font_name='Verdana', \
                    font_size=16.0, x=self.centerX2, \
                    y=self.centerY2+self.scale+150, alignment=5)
                elif self.timerCount // 20 % 3 == 2:
                    text('Recording Journey...', font_name='Verdana', \
                    font_size=16.0, x=self.centerX2, \
                    y=self.centerY2+self.scale+150, alignment=5)
                text('Tap to Stop', font_name='Verdana', font_size=16.0, \
                x=self.centerX2, y=self.centerY2+self.scale+120, alignment=5)
            elif self.measuringOn == False and self.functionState == 2:
                text('Calculating', font_name='Verdana', font_size=16.0, \
                x=self.centerX2, y=self.centerY2+self.scale+150, alignment=5)

            #if not enough values are recorded, say that they need more
            tint(self.theme["needMoreText"])
            if self.needMore == True:
                text("Need to record more locations.", font_name='Verdana', \
                font_size=16.0, x=self.size.x/2, y=self.size.y/2-20, \
                alignment=5)

        makeResetButton(self)

        drawCompass(self)

        centerScreenText(self)

        #When measuring is on record locations and put into array of locations
        def measuring(self):
            tint(self.theme["buttonText"])
            if picTaken == False:
                #camera mode
                stroke_weight(0)
                fill(self.theme["buttonFill"])
                tint(self.theme["buttonText"])
                ellipse(self.size.x/2-self.scale/2,0-self.scale/2+72,\
                self.scale,self.scale)
                text('Snap', font_name='Verdana', font_size=8.0, \
                x=self.centerX2, y=self.centerY2+self.scale-167, alignment=5)

            #to avoid repeats, only add if the location is not in the list
            if latLong not in self.locations:
                self.locations += [latLong]
                if self.activator == True:
                    self.activator = False
                self.loopPromptState = 0

            #if you travel in a loop ask the user if they want to keep the loop
            #or break it and get rid of the points in the loop from the path
            elif latLong in self.locations[0:-5] and self.activator == False:
                #sound.play_effect('arcade:Laser_1')
                self.loopPrompt = True
                self.activator = True

            #if you say tes to continuing, then you it will keep Recording
            #repeated points until you reach a point not in the list.
            if self.loopPromptState == 1:
                if self.currentLoc != latLong:
                    self.currentLoc = latLong
                    self.locations += [latLong]

            #if they say yes to breaking the loop, remove everything from the
            #end til that point in the list
            elif self.loopPromptState == 2:
                loc = self.locations.index(latLong)
                self.locations = self.locations[0:loc]
                self.loopPromptState = 0

        #when its in measuring state, measure.
        if self.measuringOn == True:
            measuring(self)

        #after measuring is off, setup array to use on the way back
        elif self.functionState == 2 and len(self.locations) > 3:
            self.locationsLeft = copy.deepcopy(self.locations)

            #do this to avoid tapping too early
            self.functionState += 1

        #after the array set up, tap to get back to where you were
        elif self.functionState == 3:
            tint(self.theme["mainTextColor"])
            text('Tap to return to start', font_name='Verdana', \
            font_size=16.0, x=self.centerX2, \
            y=self.centerY2+self.scale+150, alignment=5)

        #function state 4 is about getting back to the original location
        elif self.functionState == 4:

            #tracing back steps
            if latLong in self.locationsLeft:
                loc = self.locationsLeft.index(latLong)

                #chopping off everything til the point that it recognizes in
                #the list is way better than using .remove because now if I
                #loop into the list or the location sensor picks up late, I
                #can subvert those problems and allow Thread to work seamlessly

                # self.locationsLeft.remove(latLong) #dont use this
                self.locationsLeft = self.locationsLeft[0:loc]

            #pull the last location, that is the destination
            x, y = self.locations[0]
            x = round(x, 10)
            y = round(y, 10)
            loc = "[" + str(x) + ", " + str(y) + "]"
            fill(self.theme["buttonFill"])
            stroke(self.theme["titleColor"])
            stroke_weight(0)
            # rect(0,560,self.size.w,50)
            # # text('Destination:', font_name='Verdana', font_size=12.0, x=70, y=550, alignment=5)
            # # text(loc, font_name='Verdana', font_size=12.0, x=230, y=550, alignment=5)

            #calculate total distance traveled by using the distance formula
            totalDistanceTraveled = 0
            for i in range(len(self.locations) - 1):
                firstPosX, firstPosY = self.locations[i]
                nextPosX, nextPosY = self.locations[i + 1]
                dist = ((nextPosX - firstPosX)**2 + \
                (nextPosY - firstPosY)**2)**0.5
                totalDistanceTraveled += dist

            #not displaying the distance traveled because it is unnecessary
            #and usually incorrect because of the nature of the data
            # text('Distance Traveled:', font_name='Verdana', font_size=12.0, \
            # x=70, y=585, alignment=5)
            # text(str(totalDistanceTraveled), font_name='Verdana', \
            # font_size=12.0, x=230, y=585, alignment=5)

            #formatting
            textPosX = self.size.x / 2
            textPosY = self.size.y / 2

            #displaying the arrow that guides you back
            #if you have more than one, an arrow will point you back
            #if not it will say "Welcome Back."
            if (len(self.locationsLeft) > 1):
                #if you have more than 5 points left, use the average location
                #of the next 4 points on the path to get an accurate direction
                #back because points are recorded on a grid, so going from
                #point to point will be either left right forward or backward
                #and nothing in between.
                if (len(self.locationsLeft) > 4):
                    currPosX, currPosY = latLong
                    # currPosX, currPosY = self.locationsLeft[-1]
                    nextPosX, nextPosY = self.locationsLeft[-2]
                    secondPosX, secondPosY = self.locationsLeft[-3]
                    thirdPosX, thirdPosY = self.locationsLeft[-4]
                    fourthPosX, fourthPosY = self.locationsLeft[-5]

                    #use the average location to get a good direction
                    xNextAverage = (nextPosX + secondPosX + \
                    thirdPosX + fourthPosX)/4
                    yNextAverage = (nextPosY + secondPosY + \
                    thirdPosY + fourthPosY)/4

                #if there are 3 or 2 points left then just use what's left
                elif (len(self.locationsLeft) > 2):
                    currPosX, currPosY = self.locationsLeft[-1]
                    nextPosX, nextPosY = self.locationsLeft[-2]
                    secondPosX, secondPosY = self.locationsLeft[-3]

                    xNextAverage = (nextPosX + secondPosX) / 2
                    yNextAverage = (nextPosY + secondPosY) / 2

                elif (len(self.locationsLeft) > 1):
                    currPosX, currPosY = self.locationsLeft[-1]
                    nextPosX, nextPosY = self.locationsLeft[-2]

                    xNextAverage = (nextPosX) / 1
                    yNextAverage = (nextPosY) / 1

                #this formula was from: "https://www.igismap.com/formula
                #-to-find-bearing-or-heading-angle-between-two-points-
                #latitude-longitude/"
                xVal = math.cos(math.radians(xNextAverage))*\
                math.sin(math.radians(yNextAverage-currPosY))

                yVal = math.cos(math.radians(currPosX))*\
                math.sin(math.radians(xNextAverage))-\
                math.sin(math.radians(currPosX))*\
                math.cos(math.radians(xNextAverage))*\
                math.cos(math.radians(yNextAverage-currPosY))

                radianAngle = (math.atan2(xVal, yVal))
                degreeAngle = math.degrees(radianAngle)

                #had to derive this method on my own
                if degreeAngle < 0:
                    degreeAngle = 360 + degreeAngle

                trueDegree = degreeAngle

                #draw directing arrow: have to use this formula
                #it allow you to spin the phone and it will still point you in
                #the right direction
                tempYaw1 = -(360 - yaw + trueDegree)
                trueDegreeSin = math.sin(math.radians(tempYaw1))
                trueDegreeCos = math.cos(math.radians(tempYaw1))

                #draw the arrow that points you back
                def pointMaker(self, roll, pitch, yaw):
                    stroke_weight(20)
                    stroke(self.theme["guiderBack"])
                    line(self.centerX2-trueDegreeCos*130, \
                    self.centerY-trueDegreeSin*130, \
                    self.centerX2+trueDegreeCos*130, \
                    self.centerY+trueDegreeSin*130 )
                    stroke(self.theme["compassStrokeNorth"])
                    #make the point by increasing length
                    #and reducing stroke weight (thickness)
                    for i in range(20):
                        stroke_weight(20 - i)
                        line(self.centerX2+trueDegreeCos*(130+(i*2)), \
                        self.centerY+trueDegreeSin*(130+(i*2)), \
                        self.centerX2 ,self.centerY )

                #draw the point
                pointMaker(self, roll, pitch, yaw)

                stroke_weight(0)
                #display images when you are in the location that
                #an image is in
                if latLong in self.photoLocations \
                and self.imageModeOpen == False:

                    photoLoc = len(self.photoLocations) - \
                    self.photoLocations.index(latLong)

                    self.imageMode = True

                    tint(self.theme["textColor2"])
                    fill(self.theme["notificationColor"])
                    stroke(self.theme["notificationColor"])

                    #display a banner that says there is a landmark here!
                    rect(0, 150, self.size.w, 50)
                    text("Landmark! Tap here to see!", font_name='Verdana', \
                    font_size=16.0, x=self.centerX2, y=150+25, alignment=5)
                    self.currentImage = self.photoLibrary.assets[-photoLoc]
                    self.photoWidth = self.currentImage.pixel_width
                    self.photoHeight = self.currentImage.pixel_height

                    #get the image ready for display when the banner is tapped
                    self.ui_image = self.currentImage.get_ui_image()

            else:
                #when there are no locations left display Welcome Back.
                text("Welcome Back.", font_name='Verdana', font_size=16.0, \
                x=textPosX, y=textPosY, alignment=5)

        #the more state buttons to be displayed
        fill(self.theme["needMoreText"])
        tint(self.theme["textColor2"])
        if self.MoreState == True:
            #to seperate the active buttons from the non active ones
            fill(self.theme["transparentFill"])
            rect(0, 0, self.size.x, self.size.y)

            #SOS Button draw
            fill(self.theme["needMoreText"])
            tint(self.theme["textColor2"])
            ellipse(self.centerX2-0.0-self.scale,self.centerY2-self.scale-130,\
            self.scale*2,self.scale*2)
            text('SOS', font_name='Verdana', font_size=12.0, x=self.centerX2, \
            y=self.centerY2+self.scale-167, alignment=5)

            #only display certain buttons when it is over an amount of points
            if len(self.locations) >= 2:

                #MAP Button draw
                fill(self.theme["mapButton"])
                tint(self.theme["otherButtonTexts"])
                ellipse(self.centerX2-self.scale*3-self.scale,\
                self.centerY2-self.scale-20,self.scale*2,self.scale*2)
                text('Map View', font_name='Verdana', font_size=12.0, \
                x=self.centerX2-112, y=self.centerY2+self.scale-57,alignment=5)

                #Share Button Draw
                fill(self.theme["shareButton"])
                tint(self.theme["otherButtonTexts"])
                ellipse(self.centerX2-self.scale,self.centerY2-self.scale-20,\
                self.scale*2,self.scale*2)
                text('Share', font_name='Verdana', font_size=12.0, \
                x=self.centerX2, y=self.centerY2+self.scale-57, alignment=5)

                #let user know the text was copied after pressing share
                tint(self.theme["copiedText"])
                if self.clipState == True:
                    text('Copied to Clipboard', font_name='Verdana', \
                    font_size=16.0, x=self.size.x/2, y=self.size.y/2-65, \
                    alignment=5)

            #trace button draw
            fill(self.theme["traceButton"])
            tint(self.theme["otherButtonTexts"])
            ellipse(self.centerX2+self.scale*3-self.scale,\
            self.centerY2-self.scale-20,self.scale*2,self.scale*2)
            text('Trace', font_name='Verdana', font_size=12.0, \
            x=self.centerX2+112, y=self.centerY2+self.scale-57, alignment=5)

            #SOS Button Draw
            fill(self.theme["SOScolor"])
            tint(self.theme["otherButtonTexts"])
            ellipse(self.centerX2-0.0-self.scale,\
            self.centerY2-self.scale-130,self.scale*2,self.scale*2)
            text('SOS', font_name='Verdana', font_size=12.0, \
            x=self.centerX2, y=self.centerY2+self.scale-167, alignment=5)

            #Theme switching button draw
            fill(self.theme["themeButton"])
            tint(self.theme["themeText"])
            ellipse(self.centerX2-self.scale,self.size.y-115,\
            self.scale*2,self.scale*2)
            text('Theme', font_name='Verdana', font_size=12.0, \
            x=self.centerX2, y=self.size.y-77, alignment=5)

        #More button at the bottom of screen
        elif self.MoreState == False:
            fill(self.theme["moreColor"])
            ellipse(self.size.x/2-self.scale/2,0-self.scale/2-5,\
            self.scale,self.scale)

        #photo border when the photo is displayed
        if self.imageModeOpen == True:
            fill(0, 0, 0, 0.5)
            rect(0, 0, self.size.x, self.size.y)
            fill(self.theme["photoBorder"])
            rect(5, self.halfScreenFrame, self.widthFrame, self.heightFrame)

        #this function draws the path out in the frame that you can access
        #after pressing the trace button.
        def drawPath(self):
            fill(self.theme["pathBorder"])
            rect(14, self.size.y / 2 - 55, self.size.x - 28,
                 self.size.y / 3 + 12)
            fill(self.theme["pathScreenFill"])
            rect(19, self.size.y / 2 - 50, self.size.x - 38,
                 self.size.y / 3 + 2)

            tint(self.theme["pathEndColor"])
            fill(self.theme["pathEndColor"])
            stroke(self.theme["pathEndColor"])
            stroke_weight(2)
            iPointX, iPointY = self.locations[0]
            newLocs = [(0, 0)]
            maxDiffX = 0
            maxDiffY = 0
            xSepVals = []
            ySepVals = []

            #take the differences between the latLong points and essentially
            #simplify the data
            for loc in self.locations[1:]:
                nPointX, nPointY = loc
                dataX = (iPointX - nPointX) * 100000
                dataY = (iPointY - nPointY) * 100000
                newLocs += [(dataX, dataY)]

            #split up x and y values
            for loc in newLocs:
                xSepVals += [loc[0]]
                ySepVals += [loc[1]]

            #look for the maximum difference between the x vals and y values
            maxDiffX = (max(xSepVals) - min(xSepVals))
            maxDiffY = (max(ySepVals) - min(ySepVals))

            #scale it based on the maximum difference so the graph looks scaled
            #properly and one axis isn't many times smaller than the other
            generalMaxDiff = max(maxDiffX, maxDiffY)

            #make everything positive
            miniX = min(xSepVals)
            jumpX = 0 - miniX
            evenedLocsX = []
            for val in xSepVals:
                evenedLocsX += [val + jumpX]

            miniY = min(ySepVals)
            jumpY = 0 - miniY
            evenedLocsY = []
            for val in ySepVals:
                evenedLocsY += [val + jumpY]

            #start drawing in the frame
            #the color changes from red to black as you go farther from your
            #current location
            #changes from red to blue in dark mode
            xCenter = self.size.x / 2
            yCenter = self.size.y / 2 - 50 + 2
            colorCount = len(newLocs)
            for i in range(len(newLocs) - 1):
                xLoc1, yLoc1 = evenedLocsX[i], evenedLocsY[i]
                xLoc2, yLoc2 = evenedLocsX[i + 1], evenedLocsY[i + 1]
                #add if statements
                if self.theme == self.darkMode:
                    stroke(((255 / colorCount) * i) / 255, 0, 0.15)
                    fill(((255 / colorCount) * i) / 255, 0, 0.15)
                elif self.theme == self.lightMode:
                    stroke(((255 / colorCount) * i) / 255, 0, 0)
                    fill(((255 / colorCount) * i) / 255, 0, 0)
                #draw lines between points
                line((335/generalMaxDiff)*xLoc1+20,(222/generalMaxDiff)*\
                yLoc1+yCenter, (335/generalMaxDiff)*xLoc2+20,\
                (222/generalMaxDiff)*yLoc2+yCenter)
                #draw points, but they will be one shade lighter than the
                #line they are between because it looks cooler and stands out
                if len(self.locations) > 20:
                    ellipse((335/generalMaxDiff)*xLoc1+20-1,\
                    (222/generalMaxDiff)*yLoc1+yCenter-1,2,2)
                else:
                    ellipse((335/generalMaxDiff)*xLoc1+20-2,\
                    (222/generalMaxDiff)*yLoc1+yCenter-2,4,4)
            ellipse((335/generalMaxDiff)*evenedLocsX[-1]+20-2,\
            (222/generalMaxDiff)*evenedLocsY[-1]+yCenter-2,4,4)

        #if you push the trace button and you have locations, reveal the path
        if self.pathState == True and len(self.locations) > 0:
            drawPath(self)

        #when someone walks in a circle, prompt the user to decide what to do:
        #delete the looped area, or keep that path of travel.
        def loopPromptBox(self):
            fill(self.theme["loopPromptColor"])
            stroke_weight(0)
            #prompt for the loop
            rect(50, self.size.y / 2 - 50, self.size.x - 100,
                 self.size.y / 6 + 40)
            tint(self.theme["loopPromptTextColor"])
            text("Stop Moving!", font_name='Verdana', font_size=18.0, \
            x=self.size.x/2, y=self.size.y/2+65, alignment=5)
            text("Looks like you\'ve made a loop", font_name='Verdana', \
            font_size=13.0, x=self.size.x/2, y=self.size.y/2+38, alignment=5)
            stroke(self.theme["loopPromptTextColor"])
            stroke_weight(3)
            line(50, self.size.y / 2, self.size.x - 50, self.size.y / 2)
            line(self.size.x / 2, self.size.y / 2 - 50, self.size.x / 2,
                 self.size.y / 2)
            text("Continue", font_name='Verdana', font_size=15.0, \
            x=self.size.x/2-70, y=self.size.y/2-25, alignment=5)
            text("Break", font_name='Verdana', font_size=15.0, \
            x=self.size.x/2+70, y=self.size.y/2-25, alignment=5)

        #prompt when the user goes in a loop/crosses paths with recorded path
        if self.loopPrompt == True:
            loopPromptBox(self)
"""
Send a stream of pitch, yaw, roll values to other devices on a multipeer network.
Uses Pythonista's motion.get_attitude() to get data and @mikaelho's multipeer to send.
Install multipeer on two iOS devices and run this code on one and multipeer.py on the
other.  You should see a stream of attitude data which change as the device is moved.

TODO (cclauss): Upgrade to multipeer streams in latency becomes an issue.

https://forum.omz-software.com/topic/6140/interactive-animation-based-on-orientation-data-of-imu
http://omz-software.com/pythonista/docs/ios/motion.html
https://github.com/mikaelho/multipeer
"""

import motion, multipeer, platform

mc = multipeer.MultipeerConnectivity(display_name=platform.node(), service_type="chat")
motion.start_updates()
try:
    while True:
        mc.send(motion.get_attitude())
finally:
    mc.end_all()
    motion.stop_updates()
예제 #22
0
 def calibrate(self, sender):
     print "Old calib", self.calib
     self.calib = motion.get_attitude()
     print "New calib", self.calib
예제 #23
0
    def draw(self):
        #Box
        self.cx = self.size.w * 0.5
        self.cy = self.size.h * 0.5
        #pitch,roll,yaw
        self.cx2 = self.size.w * 0.5
        self.cy2 = self.size.h * 0.5 - scale * 3.5
        time.sleep(0.1)
        #motion
        ax, ay, az = motion.get_user_acceleration()
        gx, gy, gz = motion.get_gravity()
        gravity_vectors = motion.get_attitude()
        mx, my, mz, ma = motion.get_magnetic_field()
        pitch, roll, yaw = [x for x in gravity_vectors]
        pitch = -pitch * 180 / math.pi
        roll = roll * 180 / math.pi
        yaw = -yaw * 180 / math.pi
        #redraw screen
        background(1, 1, 1)
        fill(1, 1, 1)
        stroke_weight(1)
        #pitch,roll,yaw描画
        # ellipse(self.cx2-scale*3-self.R,self.cy2-self.R,self.R*2,self.R*2)
        # ellipse(self.cx2-0.0-self.R,self.cy2-self.R,self.R*2,self.R*2)
        ellipse(self.cx2 + scale * 3 - self.R, self.cy2 - self.R - 130,
                self.R * 2, self.R * 2)
        roll_sin = math.sin(math.radians(roll))
        roll_cos = math.cos(math.radians(roll))
        pitch_sin = math.sin(math.radians(pitch))
        pitch_cos = math.cos(math.radians(pitch))
        yaw_sin = math.sin(math.radians(yaw))
        yaw_cos = math.cos(math.radians(yaw))
        # line(self.cx2-roll_cos*self.R-scale*3,self.cy2-roll_sin*self.R,self.cx2+roll_cos*self.R-scale*3,self.cy2+roll_sin*self.R)
        # line(self.cx2-pitch_cos*self.R-0,self.cy2-pitch_sin*self.R,self.cx2+pitch_cos*self.R-0,self.cy2+pitch_sin*self.R)

        line(self.cx2 - yaw_cos * self.R + scale * 3,
             self.cy2 - yaw_sin * self.R - 130,
             self.cx2 + yaw_cos * self.R + scale * 3,
             self.cy2 + yaw_sin * self.R - 130)
        yawMatrix = np.matrix([[yaw_cos, -yaw_sin, 0], [yaw_sin, yaw_cos, 0],
                               [0, 0, 1]])
        pitchMatrix = np.matrix([[pitch_cos, 0, pitch_sin], [0, 1, 0],
                                 [-pitch_sin, 0, pitch_cos]])
        rollMatrix = np.matrix([[1, 0, 0], [0, roll_cos, -roll_sin],
                                [0, roll_sin, roll_cos]])

        R = yawMatrix * pitchMatrix * rollMatrix
        R = np.array(R)
        x_3d, y_3d, z_3d = np.transpose(np.dot(self.Box, R), (2, 0, 1))
        zmin = np.argmin(z_3d)

        #derive the direction (NSEW)
        def directionText(yaw):
            directionSym = ''
            #Direction
            if yaw > 60 and yaw <= 120:
                directionSym = 'N'
            elif yaw > 120 and yaw <= 150:
                directionSym = 'NE'
            elif (yaw > 150 and yaw <= 180) or (yaw >= -180 and yaw <= -150):
                directionSym = 'E'
            elif yaw > -150 and yaw <= -120:
                directionSym = 'SE'
            elif yaw > -120 and yaw <= -60:
                directionSym = 'S'
            elif yaw > -60 and yaw <= -30:
                directionSym = 'SW'
            elif yaw > -30 and yaw <= 30:
                directionSym = 'W'
            elif yaw > 30 and yaw <= 60:
                directionSym = 'NW'
            else:
                directionSym = ''

            return directionSym

        #text
        tint(0, 0, 0, 1)
        #text('Direction:', font_name='Helvetica', font_size=16.0, x=self.cx2+scale*3, y=self.cy2+self.R-80, alignment=5)
        text(directionText(yaw),
             font_name='Helvetica',
             font_size=10.0,
             x=self.cx2 + scale * 3,
             y=self.cy2 + self.R - 100,
             alignment=5)
예제 #24
0
 def calibrate(self, sender):
     print "Old calib", self.calib
     self.calib = motion.get_attitude()
     print "New calib", self.calib
예제 #25
0
파일: Main.py 프로젝트: papaspace/microPFD
    def update(self):
        if not self.isInit:
            print("Waiting for init")
            return

        GRAV = motion.get_gravity()
        #GRAV=numpy.add(motion.get_gravity(), motion.get_user_acceleration())

        GRAV = GRAV / numpy.linalg.norm(GRAV)
        FORCE = motion.get_user_acceleration()
        ATT = motion.get_attitude()
        LOC = location.get_location()
        MAG = motion.get_magnetic_field()

        [roll, pitch, yaw,
         hdg] = navutil.roll_pitch_yaw_hdg(ATT, MAG, GRAV, FORCE)

        # Pitch and roll pointer
        self.pitchMarks.rotation = roll
        offsetY = self.pxPerDeg * (numpy.rad2deg(pitch))
        #offsetX=-numpy.tan(roll)*offsetY
        offsetX = -numpy.sin(roll) * offsetY
        self.pitchMarks.position = (offsetX, offsetY * numpy.cos(roll))

        self.rollPointer.rotation = roll

        # Yaw pointer (ball) ...
        # smooth the signal a little
        self.yaw_history.append(yaw)
        if len(self.yaw_history) > 5:
            self.yaw_history.pop(0)
        self.yawPointer.rotation = roll - numpy.mean(self.yaw_history)

        #print("%d %d %d"%(numpy.rad2deg(ATT[0]), numpy.rad2deg(ATT[1]),numpy.rad2deg(ATT[2])))

        if LOC != None:
            self.lbl_lat.text = "LAT %2.6f deg" % LOC["latitude"]

            self.lbl_lon.text = "LON %2.6f deg" % LOC["longitude"]

            # Altitude display...
            # hundreds
            self.txt_alth.text = "%01d" % ((LOC["altitude"] / 0.3048) / 100.0)
            # decis
            self.txt_altd.text = "%02d" % ((LOC["altitude"] / 0.3048) % 100.0)

            # Ground speed display
            gs = LOC["speed"] * 3.6 / 1.852
            if gs < 0.0:
                self.txt_spd.text = "--"
            else:
                self.txt_spd.text = "%d" % gs

            self.pos_geo = [
                LOC["altitude"],
                numpy.deg2rad(LOC["longitude"]),
                numpy.deg2rad(LOC["latitude"])
            ]
            self.pos_cart = navutil.geo2cart(self.pos_geo)

        # HSI...
        self.txt_g.text = "%2.1f" % (numpy.linalg.norm(GRAV + FORCE))

        # HDG display
        if self.hdg_mode == False:
            hdg = LOC["course"]
            self.txt_hdg.color = "#ff00ff"
        else:
            self.txt_hdg.color = "#00ff00"
        if hdg < 0.0:
            self.txt_hdg.text = "TRK"
            self.txt_hdg.color = "#ff0000"
            hdg = 0.0

        else:
            self.txt_hdg.text = "%03d" % (hdg)
        self.rose.rotation = numpy.deg2rad(hdg)

        # Waypoint info, CDI
        if self.wpt != "":

            [dist, dtk] = navutil.great_circle(self.pos_cart, self.wpt_cart)

            fmt_dist = "%d"
            if (dist / 1852.0 < 10.0):
                fmt_dist = "%0.1f"
            self.wpt_dist.text = fmt_dist % (dist / 1852.0)
            self.wpt_dtk.text = "%03d" % numpy.rad2deg(dtk)

            self.cdi_needle.rotation = -self.dtk

            full_scale_defl = 12.0
            defl = numpy.amax([
                -full_scale_defl,
                numpy.amin([full_scale_defl,
                            numpy.rad2deg((dtk - self.dtk))])
            ])
            self.cdi_track.position = numpy.array(
                [0.5 / full_scale_defl * self.cdi_r * defl, 0.0, 0.0])
예제 #26
0
    def draw(self):
        #Box
        self.cx = self.size.w * 0.5
        self.cy = self.size.h * 0.5
        #pitch,roll,yaw
        self.cx2 = self.size.w * 0.5
        self.cy2 = self.size.h * 0.5 - scale * 3.5
        time.sleep(0.1)
        self.testCounter += 1

        #motion
        ax, ay, az = motion.get_user_acceleration()
        gx, gy, gz = motion.get_gravity()
        gravity_vectors = motion.get_attitude()
        mx, my, mz, ma = motion.get_magnetic_field()
        pitch, roll, yaw = [x for x in gravity_vectors]
        pitch = -pitch * 180 / math.pi
        roll = roll * 180 / math.pi
        yaw = -yaw * 180 / math.pi
        #redraw screen
        fill(0.9, 0.9, 0.9)
        stroke_weight(0)

        #pitch,roll,yaw
        ellipse(self.cx2 - scale * 3 - self.R, self.cy2 - self.R - 130,
                self.R * 2, self.R * 2)
        tint(0.4, 0.4, 0.4, 1)
        text('Reset',
             font_name='Verdana',
             font_size=12.0,
             x=self.cx2 - 112,
             y=self.cy2 + self.R - 167,
             alignment=5)

        # ellipse(self.cx2-0.0-self.R,self.cy2-self.R,self.R*2,self.R*2)
        stroke(0.4, 0.4, 0.4)
        stroke_weight(0)
        fill(0.9, 0.9, 0.9)
        #compass draw
        ellipse(self.cx2 + scale * 3 - self.R, self.cy2 - self.R - 130,
                self.R * 2, self.R * 2)
        #fill(0.7,0.7,0.7)
        stroke_weight(0)
        ellipse(self.cx2 + scale * 3 - self.R + 3, self.cy2 - self.R - 127,
                self.R * 1.85, self.R * 1.85)
        #fill(0.8,0.8,0.8)
        ellipse(self.cx2 + scale * 3 - self.R + 6, self.cy2 - self.R - 124,
                self.R * 1.7, self.R * 1.7)

        # roll_sin = math.sin(math.radians(roll))
        # roll_cos = math.cos(math.radians(roll))
        # pitch_sin = math.sin(math.radians(pitch))
        # pitch_cos = math.cos(math.radians(pitch))
        yaw_sin = math.sin(math.radians(yaw))
        yaw_cos = math.cos(math.radians(yaw))
        # line(self.cx2-roll_cos*self.R-scale*3,self.cy2-roll_sin*self.R,self.cx2+roll_cos*self.R-scale*3,self.cy2+roll_sin*self.R)
        # line(self.cx2-pitch_cos*self.R-0,self.cy2-pitch_sin*self.R,self.cx2+pitch_cos*self.R-0,self.cy2+pitch_sin*self.R)
        stroke(0.4, 0.4, 0.4)
        stroke_weight(2)
        line(self.cx2 - yaw_cos * self.R + scale * 3,
             self.cy2 - yaw_sin * self.R - 130,
             self.cx2 + yaw_cos * self.R + scale * 3,
             self.cy2 + yaw_sin * self.R - 130)
        stroke(1, 0.3, 0.3)
        line(300, 72.5, self.cx2 + yaw_cos * self.R + scale * 3,
             self.cy2 + yaw_sin * self.R - 130)

        #circle on top of compass
        stroke_weight(0)
        stroke(0.4, 0.4, 0.4)
        #fill(0.95,0.95,0.95)
        fill(1, 1, 1)

        ellipse(self.cx2 + scale * 3 - self.R + 9.5, self.cy2 - self.R - 120.5,
                self.R * 1.5, self.R * 1.5)

        # yawMatrix = numpy.matrix([[yaw_cos, -yaw_sin, 0],[yaw_sin, yaw_cos, 0],[0, 0, 1]])
        # pitchMatrix = numpy.matrix([[pitch_cos, 0, pitch_sin],[0, 1, 0],[-pitch_sin, 0, pitch_cos]])
        # rollMatrix = numpy.matrix([[1, 0, 0],[0, roll_cos, -roll_sin],[0, roll_sin, roll_cos]])
        #
        # R = yawMatrix * pitchMatrix * rollMatrix
        # R = numpy.array(R)
        #x_3d,y_3d,z_3d = numpy.transpose(numpy.dot(self.Box,R),(2,0,1))
        #zmin = numpy.argmin(z_3d)

        #derive the direction (NSEW)
        def directionText(yaw):
            directionSym = ''
            #Direction
            if yaw > 60 and yaw <= 120:
                directionSym = 'N'
            elif yaw > 120 and yaw <= 150:
                directionSym = 'NE'
            elif (yaw > 150 and yaw <= 180) or (yaw >= -180 and yaw <= -150):
                directionSym = 'E'
            elif yaw > -150 and yaw <= -120:
                directionSym = 'SE'
            elif yaw > -120 and yaw <= -60:
                directionSym = 'S'
            elif yaw > -60 and yaw <= -30:
                directionSym = 'SW'
            elif yaw > -30 and yaw <= 30:
                directionSym = 'W'
            elif yaw > 30 and yaw <= 60:
                directionSym = 'NW'
            else:
                directionSym = ''

            return directionSym

        #text
        tint(0, 0, 0, 1)
        text('Thread 1.0',
             font_name='Courier',
             font_size=16.0,
             x=self.cx2,
             y=self.cy2 + self.R + 400,
             alignment=5)

        tint(0.4, 0.4, 0.4, 1)
        if self.measuringOn == False and self.checkedOnce == 0:
            text('Tap to Start',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.cx2,
                 y=self.cy2 + self.R + 150,
                 alignment=5)
        elif self.measuringOn == True and self.checkedOnce == 1:
            if self.testCounter // 10 % 3 == 0:
                text('Measuring.',
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.cx2,
                     y=self.cy2 + self.R + 150,
                     alignment=5)
            elif self.testCounter // 10 % 3 == 1:
                text('Measuring..',
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.cx2,
                     y=self.cy2 + self.R + 150,
                     alignment=5)
            elif self.testCounter // 10 % 3 == 2:
                text('Measuring...',
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.cx2,
                     y=self.cy2 + self.R + 150,
                     alignment=5)
            text('Tap to Stop',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.cx2,
                 y=self.cy2 + self.R + 120,
                 alignment=5)

        elif self.measuringOn == False and self.checkedOnce == 2:
            text('Calculating',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.cx2,
                 y=self.cy2 + self.R + 120,
                 alignment=5)

        #compass text
        if self.compassStat == False:
            text(directionText(yaw),
                 font_name='Verdana',
                 font_size=10.0,
                 x=self.cx2 + scale * 3,
                 y=self.cy2 + self.R - 167,
                 alignment=5)
        else:
            tempYaw = yaw + 180 + 90
            if tempYaw > 360:
                tempYaw = tempYaw % 360
            yawString = str(round(tempYaw, 2)) + chr(186)
            text(yawString,
                 font_name='Verdana',
                 font_size=10.0,
                 x=self.cx2 + scale * 3,
                 y=self.cy2 + self.R - 167,
                 alignment=5)

        if self.measuringOn == True:
            if self.testCounter % 10:
                current = location.get_location()
                latLong = (current['latitude'], current['longitude'])
                self.locations += [latLong]

        elif self.checkedOnce == 2 and len(self.locations) > 2:
            self.locationsReversed = copy.deepcopy(self.locations)
            self.locationsReversed.reverse()

            #now use the locations and map it onto a map so you know the direciton between points (NWSE)
            #start saying stuff like "Point North and Move Forward"
            #Now it makes sense why we use the compass.

            #test texts
            self.checkedOnce += 1

        elif self.checkedOnce == 3:

            locationList = str(self.locations[0]) + ' ' + str(
                self.locations[-1])
            text(locationList,
                 font_name='Verdana',
                 font_size=5.0,
                 x=self.cx2,
                 y=self.cy2 + self.R + 80,
                 alignment=5)
            locationListReversed = str(self.locationsReversed[0]) + ' ' + str(
                self.locationsReversed[-1])
            text(locationListReversed,
                 font_name='Verdana',
                 font_size=5.0,
                 x=self.cx2,
                 y=self.cy2 + self.R + 60,
                 alignment=5)

        elif self.checkedOnce == 4:
            self.checkedOnce = 5
            x, y = self.locations[0]
            webbrowser.open(self.query % (x, y))
            text(str(x),
                 font_name='Verdana',
                 font_size=5.0,
                 x=self.cx2,
                 y=self.cy2 + self.R + 80,
                 alignment=5)
            text(str(y),
                 font_name='Verdana',
                 font_size=5.0,
                 x=self.cx2,
                 y=self.cy2 + self.R + 80,
                 alignment=5)
예제 #27
0
def read_data(sender):
	import motion, location
	import time, datetime
	import io
	import numpy as np
	import matplotlib.pyplot as plt
	
	val = view['switch1'].value
	if val==True:
		motion.start_updates()
			
		y=0
		nx = np.empty(1)
		ny = np.empty(1)
		nz = np.empty(1)
		view['mag'].text = ''
		view['accel'].text = ''
		view['gyro'].text = ''
		view['gravity'].text = ''
		
		while (y<=100):
			time.sleep(.05)
			x = motion.get_attitude()
			view['gyro'].text = str(x) + '\n' + view['gyro'].text
			x = motion.get_gravity()
			view['gravity'].text = str(x) + '\n' + view['gravity'].text
			x = motion.get_user_acceleration()
			nx = np.append(nx,x[0])
			ny = np.append(ny,x[1])
			nz = np.append(nz,x[2])
			view['accel'].text = str(x) + '\n' + view['accel'].text
			x = motion.get_magnetic_field()
			view['mag'].text = str(x) + '\n' + view['mag'].text
			y +=1
			view['y'].text = str(y) + 'measurements'
				
		motion.stop_updates()	
		plt.plot(nx)
		plt.show()
		plt.savefig('x.tif')
		plt.close()
		plt.plot(ny)
		plt.show()
		plt.savefig('y.tif')
		plt.close()
		plt.plot(nz)
		plt.show()
		plt.savefig('z.tif')
		plt.close()
		medianx = np.median(nz)
		stdx = np.std(nz)
		apex = np.amax(np.absolute(nz))
		print (apex)
		print (stdx)
		if apex >= stdx*2:
			if apex > stdx*5:
				view['fell'].text = 'Fall'
			else:
				view['fell'].text = 'Trip'
					
		fname = 'motion' + str(datetime.datetime.now()).split('.')[1] + '.txt'
		with open(fname, 'w') as fo:
			fo.write('gyro\n')
			fo.write(view['gyro'].text)
			fo.write('gravity\n')
			fo.write(view['gravity'].text)
			fo.write('accel\n')
			fo.write(view['accel'].text)
			fo.write('mag\n')
			fo.write(view['mag'].text)
	else:
		view['mag'].text = ''
		view['accel'].text = ''
		view['gyro'].text = ''
		view['gravity'].text = ''
		view['y'].text = str(0)
예제 #28
0
    def draw(self):
        self.centerX = self.size.w / 2
        self.centerY = self.size.h / 2
        self.centerX2 = self.size.w / 2
        self.centerY2 = self.size.h * (1 / 2) - scale * 3.5
        time.sleep(0.1)
        self.testCounter += 1

        #Title Text
        tint(0, 0, 0, 1)
        text('Thread 1.0',
             font_name='Courier',
             font_size=16.0,
             x=self.centerX2,
             y=self.centerY2 + self.radius + 400,
             alignment=5)

        tint(0.4, 0.4, 0.4, 1)
        if len(self.locations) > 2:
            locationCountText = "Locations: " + str(len(self.locations) - 2)
        else:
            locationCountText = "Locations: " + str(0)
        text(locationCountText,
             font_name='Verdana',
             font_size=10,
             x=50,
             y=self.centerY2 + self.radius + 400,
             alignment=5)

        #motion
        gravX, gravY, gravZ = motion.get_gravity()
        gravity_vectors = motion.get_attitude()
        yaw = gravity_vectors[2]

        #convert yaw to degrees
        yaw = -yaw * 180 / math.pi

        ############# redraw screen ############
        #Reset Button
        fill(0.9, 0.9, 0.9)
        stroke_weight(0)
        ellipse(self.centerX2 - scale * 3 - self.radius,
                self.centerY2 - self.radius - 130, self.radius * 2,
                self.radius * 2)
        tint(0.4, 0.4, 0.4, 1)
        text('Reset',
             font_name='Verdana',
             font_size=12.0,
             x=self.centerX2 - 112,
             y=self.centerY2 + self.radius - 167,
             alignment=5)

        #SOS Button and
        fill(0.95, 0.6, 0.6)
        tint(1, 1, 1, 1)
        if self.MoreState == True:

            #SOS Button
            fill(0.95, 0.6, 0.6)
            tint(1, 1, 1, 1)
            ellipse(self.centerX2 - 0.0 - self.radius,
                    self.centerY2 - self.radius - 130, self.radius * 2,
                    self.radius * 2)
            text('SOS',
                 font_name='Verdana',
                 font_size=12.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius - 167,
                 alignment=5)

            #MAP Button
            if len(self.locations) >= 2:
                fill(0.6, 0.6, 0.95)
                tint(1, 1, 1, 1)
                ellipse(self.centerX2 - scale * 3 - self.radius,
                        self.centerY2 - self.radius - 20, self.radius * 2,
                        self.radius * 2)
                text('Map View',
                     font_name='Verdana',
                     font_size=12.0,
                     x=self.centerX2 - 112,
                     y=self.centerY2 + self.radius - 57,
                     alignment=5)

            #SOS Button
            fill(0.95, 0.6, 0.6)
            tint(1, 1, 1, 1)
            ellipse(self.centerX2 - 0.0 - self.radius,
                    self.centerY2 - self.radius - 130, self.radius * 2,
                    self.radius * 2)
            text('SOS',
                 font_name='Verdana',
                 font_size=12.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius - 167,
                 alignment=5)

        elif self.MoreState == False:
            ellipse(self.size.x / 2 - self.radius / 2, 0 - self.radius / 2 - 5,
                    self.radius, self.radius)

        #compass draw
        tint(0.4, 0.4, 0.4, 1)
        stroke(0.4, 0.4, 0.4)
        stroke_weight(0)
        fill(0.9, 0.9, 0.9)
        ellipse(self.centerX2 + scale * 3 - self.radius,
                self.centerY2 - self.radius - 130, self.radius * 2,
                self.radius * 2)
        stroke_weight(0)
        ellipse(self.centerX2 + scale * 3 - self.radius + 3,
                self.centerY2 - self.radius - 127, self.radius * 1.85,
                self.radius * 1.85)
        ellipse(self.centerX2 + scale * 3 - self.radius + 6,
                self.centerY2 - self.radius - 124, self.radius * 1.7,
                self.radius * 1.7)
        yawSin = math.sin(math.radians(yaw))
        yawCos = math.cos(math.radians(yaw))
        stroke(0.4, 0.4, 0.4)
        stroke_weight(2)
        line(self.centerX2 - yawCos * self.radius + scale * 3,
             self.centerY2 - yawSin * self.radius - 130,
             self.centerX2 + yawCos * self.radius + scale * 3,
             self.centerY2 + yawSin * self.radius - 130)
        stroke(1, 0.3, 0.3)
        line(300, 72.5, self.centerX2 + yawCos * self.radius + scale * 3,
             self.centerY2 + yawSin * self.radius - 130)
        #circle on top of compass
        stroke_weight(0)
        stroke(0.4, 0.4, 0.4)
        fill(1, 1, 1)
        ellipse(self.centerX2 + scale * 3 - self.radius + 9.5,
                self.centerY2 - self.radius - 120.5, self.radius * 1.5,
                self.radius * 1.5)

        #derive the direction (NSEW)
        def directionText(yaw):
            directionSym = ''
            #Direction
            if yaw > 60 and yaw <= 120:
                directionSym = 'N'
            elif yaw > 120 and yaw <= 150:
                directionSym = 'NE'
            elif (yaw > 150 and yaw <= 180) or (yaw >= -180 and yaw <= -150):
                directionSym = 'E'
            elif yaw > -150 and yaw <= -120:
                directionSym = 'SE'
            elif yaw > -120 and yaw <= -60:
                directionSym = 'S'
            elif yaw > -60 and yaw <= -30:
                directionSym = 'SW'
            elif yaw > -30 and yaw <= 30:
                directionSym = 'W'
            elif yaw > 30 and yaw <= 60:
                directionSym = 'NW'
            else:
                directionSym = ''
            return directionSym

        tint(0.4, 0.4, 0.4, 1)
        if self.measuringOn == False and self.checkedOnce == 0:
            text('Tap to Start',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius + 150,
                 alignment=5)
        elif self.measuringOn == True and self.checkedOnce == 1:
            if self.testCounter // 10 % 3 == 0:
                text('Measuring.',
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.radius + 150,
                     alignment=5)
            elif self.testCounter // 10 % 3 == 1:
                text('Measuring..',
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.radius + 150,
                     alignment=5)
            elif self.testCounter // 10 % 3 == 2:
                text('Measuring...',
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.radius + 150,
                     alignment=5)
            text('Tap to Stop',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius + 120,
                 alignment=5)
        elif self.measuringOn == False and self.checkedOnce == 2:
            text('Calculating',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius + 150,
                 alignment=5)

        #compass text
        if self.compassStat == False:
            text(directionText(yaw),
                 font_name='Verdana',
                 font_size=10.0,
                 x=self.centerX2 + scale * 3,
                 y=self.centerY2 + self.radius - 167,
                 alignment=5)
        else:
            tempYaw = yaw + 180 + 90
            if tempYaw > 360:
                tempYaw = tempYaw % 360
            yawString = str(int(round(tempYaw, 0))) + chr(186)
            text(yawString,
                 font_name='Verdana',
                 font_size=10.0,
                 x=self.centerX2 + scale * 3,
                 y=self.centerY2 + self.radius - 167,
                 alignment=5)

        if self.measuringOn == True:
            if self.testCounter % 500:
                current = location.get_location()
                latLong = (current['latitude'], current['longitude'])
                if latLong not in self.locations:
                    self.locations += [latLong]

        elif self.checkedOnce == 2 and len(self.locations) > 2:
            self.locations.pop(0)
            self.locations.pop()
            self.locationsReversed = copy.deepcopy(self.locations)
            self.locationsReversed.reverse()

            #now use the locations and map it onto a map so you know the direciton between points (NWSE)
            #start saying stuff like "Point North and Move Forward"
            #Now it makes sense why we use the compass.

            #test texts
            self.checkedOnce += 1

        elif self.checkedOnce == 3:

            text('Tap to return to start',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius + 150,
                 alignment=5)

            # locationList = str(self.locations[0]) + ' ' + str(self.locations[-1])
            # text(locationList, font_name='Verdana', font_size=5.0, x=self.centerX2, y=self.centerY2+self.radius+80, alignment=5)
            # locationListReversed = str(self.locationsReversed[0]) + ' ' + str(self.locationsReversed[-1])
            # text(locationListReversed, font_name='Verdana', font_size=5.0, x=self.centerX2, y=self.centerY2+self.radius+60, alignment=5)

        elif self.checkedOnce == 4:
            x, y = self.locations[-1]
            x = round(x, 10)
            y = round(y, 10)
            loc = "[" + str(x) + ", " + str(y) + "]"
            fill(0.9, 0.9, 0.9)
            stroke(0, 0, 0)
            stroke_weight(0)
            rect(0, 525, self.size.w, 50)
            text('Destination:',
                 font_name='Verdana',
                 font_size=12.0,
                 x=70,
                 y=550,
                 alignment=5)
            text(loc,
                 font_name='Verdana',
                 font_size=12.0,
                 x=230,
                 y=550,
                 alignment=5)

            currPosX, currPosY = self.locations[-1]
            nextPosX, nextPosY = self.locations[0]

            differenceX = nextPosX - currPosX
            differenceY = nextPosY - currPosY

            directionAngle = math.atan(differenceY / differenceX)
            degreeAngle = math.degrees(directionAngle)

            textPosX = self.size.x / 2
            textPosY = self.size.y / 2

            if (currPosX <= nextPosX and currPosY <= nextPosY):
                text(str(round(degreeAngle, 4)),
                     font_name='Verdana',
                     font_size=16.0,
                     x=textPosX,
                     y=textPosY,
                     alignment=5)
            elif (currPosX <= nextPosX and currPosY >= nextPosY):
                text(str(round(degreeAngle, 4) + 180),
                     font_name='Verdana',
                     font_size=16.0,
                     x=textPosX,
                     y=textPosY,
                     alignment=5)
            elif (currPosX >= nextPosX and currPosY >= nextPosY):
                text(str(round(degreeAngle, 4) + 180),
                     font_name='Verdana',
                     font_size=16.0,
                     x=textPosX,
                     y=textPosY,
                     alignment=5)
            elif (currPosX >= nextPosX and currPosY <= nextPosY):
                text(str(round(degreeAngle, 4) + 360),
                     font_name='Verdana',
                     font_size=16.0,
                     x=textPosX,
                     y=textPosY,
                     alignment=5)
예제 #29
0
    def draw(self):
        #Boxの中心
        self.cx = self.size.w * 0.5
        self.cy = self.size.h * 0.5
        #pitch,roll,yawメータの中心
        self.cx2 = self.size.w * 0.5
        self.cy2 = self.size.h * 0.5 - scale * 3.5
        time.sleep(0.1)
        #motionセンサの値更新
        ax, ay, az = motion.get_user_acceleration()
        gx, gy, gz = motion.get_gravity()
        gravity_vectors = motion.get_attitude()
        mx, my, mz, ma = motion.get_magnetic_field()
        pitch, roll, yaw = [x for x in gravity_vectors]
        #ラジアン→度
        pitch = -pitch * 180 / 3.1415926
        roll = roll * 180 / 3.1415926
        yaw = -yaw * 180 / 3.1415926
        #redraw screen
        background(1, 1, 1)
        fill(1, 1, 1)
        stroke(0, 0, 0)
        stroke_weight(1)

        roll_sin = math.sin(math.radians(roll))
        roll_cos = math.cos(math.radians(roll))
        pitch_sin = math.sin(math.radians(pitch))
        pitch_cos = math.cos(math.radians(pitch))
        yaw_sin = -math.sin(math.radians(yaw))
        yaw_cos = -math.cos(math.radians(yaw))

        yawMatrix = np.matrix([[-yaw_cos, yaw_sin, 0], [yaw_sin, yaw_cos, 0],
                               [0, 0, 1]])
        pitchMatrix = np.matrix([[pitch_cos, 0, pitch_sin], [0, 1, 0],
                                 [-pitch_sin, 0, pitch_cos]])
        rollMatrix = np.matrix([[1, 0, 0], [0, roll_cos, -roll_sin],
                                [0, roll_sin, roll_cos]])
        R = yawMatrix * pitchMatrix * rollMatrix
        R = np.array(R)
        x_3d, y_3d, z_3d = np.transpose(np.dot(self.Box, R), (2, 0, 1))
        #陰線処理のため1番奥の頂点を特定
        zmin = np.argmin(z_3d)
        #奥の頂点を含んでいない辺を描画
        if zmin != 0 and zmin != 1:
            line(self.cx + x_3d[0] * scale, self.cy + y_3d[0] * scale,
                 self.cx + x_3d[1] * scale, self.cy + y_3d[1] * scale)
        if zmin != 1 and zmin != 2:
            line(self.cx + x_3d[1] * scale, self.cy + y_3d[1] * scale,
                 self.cx + x_3d[2] * scale, self.cy + y_3d[2] * scale)
        if zmin != 2 and zmin != 3:
            line(self.cx + x_3d[2] * scale, self.cy + y_3d[2] * scale,
                 self.cx + x_3d[3] * scale, self.cy + y_3d[3] * scale)
        if zmin != 3 and zmin != 0:
            line(self.cx + x_3d[3] * scale, self.cy + y_3d[3] * scale,
                 self.cx + x_3d[0] * scale, self.cy + y_3d[0] * scale)

        if zmin != 4 and zmin != 5:
            line(self.cx + x_3d[4] * scale, self.cy + y_3d[0] * scale,
                 self.cx + x_3d[1] * scale, self.cy + y_3d[1] * scale)
        if zmin != 5 and zmin != 6:
            line(self.cx + x_3d[5] * scale, self.cy + y_3d[1] * scale,
                 self.cx + x_3d[2] * scale, self.cy + y_3d[2] * scale)
        if zmin != 6 and zmin != 7:
            line(self.cx + x_3d[6] * scale, self.cy + y_3d[2] * scale,
                 self.cx + x_3d[3] * scale, self.cy + y_3d[3] * scale)
        if zmin != 7 and zmin != 4:
            line(self.cx + x_3d[7] * scale, self.cy + y_3d[3] * scale,
                 self.cx + x_3d[0] * scale, self.cy + y_3d[0] * scale)
예제 #30
0
    def draw(self):
        #Center scaling
        self.centerX = self.size.w / 2
        self.centerY = self.size.h / 2
        self.centerX2 = self.size.w / 2
        self.centerY2 = self.size.h * (1 / 2) - scale * 3.5

        time.sleep(0.1)  #time between each redraw
        self.timerCount += 1  #add to the timer to animate and do things

        #Title Text
        tint(0, 0, 0, 1)
        text('Thread 1.0',
             font_name='Courier',
             font_size=16.0,
             x=self.centerX2,
             y=self.centerY2 + self.radius + 400,
             alignment=5)

        #Locations recorded count
        tint(0.4, 0.4, 0.4, 1)

        locationCountText = "Locations: " + str(len(self.locations))
        text(locationCountText,
             font_name='Verdana',
             font_size=10,
             x=50,
             y=self.centerY2 + self.radius + 400,
             alignment=5)

        if self.checkedOnce == 4:
            locationLeftText = "Left: " + str(len(self.locationsLeft))
            text(locationLeftText,
                 font_name='Verdana',
                 font_size=10,
                 x=self.size.x - 60,
                 y=self.centerY2 + self.radius + 400,
                 alignment=5)

        #motion
        gravX, gravY, gravZ = motion.get_gravity()
        gravity_vectors = motion.get_attitude()
        pitch = gravity_vectors[0]
        roll = gravity_vectors[1]
        yaw = gravity_vectors[2]

        #convert yaw to degrees
        yaw = -yaw * 180 / math.pi
        pitch = -pitch * 180 / math.pi
        roll = -roll * 180 / math.pi

        ############# redraw screen ############
        #Reset Button
        fill(0.9, 0.9, 0.9)
        stroke_weight(0)
        ellipse(self.centerX2 - scale * 3 - self.radius,
                self.centerY2 - self.radius - 130, self.radius * 2,
                self.radius * 2)
        tint(0.4, 0.4, 0.4, 1)
        text('Reset',
             font_name='Verdana',
             font_size=12.0,
             x=self.centerX2 - 112,
             y=self.centerY2 + self.radius - 167,
             alignment=5)

        current = location.get_location()
        latLong = (round(current['latitude'],
                         4), round(current['longitude'], 4)
                   )  #solved the close points problem using rounding
        picTaken = latLong in self.photoLocations

        if self.measuringOn == True and picTaken == False:
            #camera mode
            stroke_weight(0)
            fill(0.9, 0.9, 0.9)
            tint(0.4, 0.4, 0.4, 1)
            ellipse(self.size.x / 2 - self.radius / 2,
                    0 - self.radius / 2 + 72, self.radius, self.radius)
            text('Snap',
                 font_name='Verdana',
                 font_size=8.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius - 167,
                 alignment=5)

        #compass draw
        tint(0.4, 0.4, 0.4, 1)
        stroke(0.4, 0.4, 0.4)
        stroke_weight(0)
        fill(0.9, 0.9, 0.9)
        ellipse(self.centerX2 + scale * 3 - self.radius,
                self.centerY2 - self.radius - 130, self.radius * 2,
                self.radius * 2)
        stroke_weight(0)
        ellipse(self.centerX2 + scale * 3 - self.radius + 3,
                self.centerY2 - self.radius - 127, self.radius * 1.85,
                self.radius * 1.85)
        ellipse(self.centerX2 + scale * 3 - self.radius + 6,
                self.centerY2 - self.radius - 124, self.radius * 1.7,
                self.radius * 1.7)
        yawSin = math.sin(math.radians(yaw))
        yawCos = math.cos(math.radians(yaw))
        rollSin = math.sin(math.radians(roll))
        rollCos = math.cos(math.radians(roll))
        pitchSin = math.sin(math.radians(pitch))
        pitchCos = math.cos(math.radians(pitch))
        stroke(0.4, 0.4, 0.4)
        stroke_weight(2)

        #line(self.centerX2-yawCos*self.radius+scale*3,self.centerY2-yawSin*self.radius-50,self.centerX2+yawCos*self.radius+scale*3,self.centerY2+yawSin*self.radius-50)
        #line(self.centerX2-pitchCos*self.radius-0,self.centerY2-pitchSin*self.radius,self.centerX2+pitchCos*self.radius-0,self.centerY2+pitchSin*self.radius)
        #line(self.centerX2-rollCos*self.radius-scale*3,self.centerY2-rollSin*self.radius,self.centerX2+rollCos*self.radius-scale*3,self.centerY2+rollSin*self.radius)

        stroke(0.4, 0.4, 0.4)
        line(self.centerX2 - yawCos * self.radius + scale * 3,
             self.centerY2 - yawSin * self.radius - 130,
             self.centerX2 + yawCos * self.radius + scale * 3,
             self.centerY2 + yawSin * self.radius - 130)
        stroke(1, 0.3, 0.3)
        line(300, 72.5, self.centerX2 + yawCos * self.radius + scale * 3,
             self.centerY2 + yawSin * self.radius - 130)

        #circle on top of compass
        stroke_weight(0)
        stroke(0.4, 0.4, 0.4)
        fill(1, 1, 1)
        ellipse(self.centerX2 + scale * 3 - self.radius + 9.5,
                self.centerY2 - self.radius - 120.5, self.radius * 1.5,
                self.radius * 1.5)

        #derive the direction (NSEW)
        def directionText(yaw):
            directionSym = ''
            #Direction
            if yaw > 60 and yaw <= 120:
                directionSym = 'N'
            elif yaw > 120 and yaw <= 150:
                directionSym = 'NE'
            elif (yaw > 150 and yaw <= 180) or (yaw >= -180 and yaw <= -150):
                directionSym = 'E'
            elif yaw > -150 and yaw <= -120:
                directionSym = 'SE'
            elif yaw > -120 and yaw <= -60:
                directionSym = 'S'
            elif yaw > -60 and yaw <= -30:
                directionSym = 'SW'
            elif yaw > -30 and yaw <= 30:
                directionSym = 'W'
            elif yaw > 30 and yaw <= 60:
                directionSym = 'NW'
            else:
                directionSym = ''
            return directionSym

        #compass text
        tint(0.4, 0.4, 0.4, 1)
        if self.compassStat == False:
            text(directionText(yaw),
                 font_name='Verdana',
                 font_size=10.0,
                 x=self.centerX2 + scale * 3,
                 y=self.centerY2 + self.radius - 167,
                 alignment=5)
        else:
            tempYaw = yaw + 180 + 90
            if tempYaw > 360:
                tempYaw = tempYaw % 360
            yawString = str(int(round(tempYaw, 0))) + chr(186)
            text(yawString,
                 font_name='Verdana',
                 font_size=10.0,
                 x=self.centerX2 + scale * 3,
                 y=self.centerY2 + self.radius - 167,
                 alignment=5)

        #Center Screen Text
        tint(0.4, 0.4, 0.4, 1)
        if self.measuringOn == False and self.checkedOnce == 0:
            text('Tap to Start',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius + 150,
                 alignment=5)
        elif self.measuringOn == True and self.checkedOnce == 1:
            if self.timerCount // 10 % 3 == 0:
                text('Measuring.',
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.radius + 150,
                     alignment=5)
            elif self.timerCount // 10 % 3 == 1:
                text('Measuring..',
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.radius + 150,
                     alignment=5)
            elif self.timerCount // 10 % 3 == 2:
                text('Measuring...',
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.radius + 150,
                     alignment=5)
            text('Tap to Stop',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius + 120,
                 alignment=5)
        elif self.measuringOn == False and self.checkedOnce == 2:
            text('Calculating',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius + 150,
                 alignment=5)

        #if not enough values are recorded
        tint(0.95, 0.6, 0.6, 1)
        if self.needMore == True:
            text("Need to record more locations.",
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.size.x / 2,
                 y=self.size.y / 2 - 20,
                 alignment=5)

        tint(0.4, 0.4, 0.4, 1)
        #When measuring is on record locations and put into array
        if self.measuringOn == True:
            current = location.get_location()
            latLong = (round(current['latitude'],
                             4), round(current['longitude'], 4)
                       )  #solved the close points problem using rounding
            if latLong not in self.locations:
                self.locations += [latLong]
                if self.activator == True:
                    self.activator = False
                self.loopPromptState = 0

            elif latLong in self.locations[0:-5] and self.activator == False:
                #sound.play_effect('arcade:Laser_1')
                self.loopPrompt = True
                self.activator = True

            if self.loopPromptState == 1:
                if self.currentLoc != latLong:
                    self.currentLoc = latLong
                    self.locations += [latLong]

            elif self.loopPromptState == 2:
                loc = self.locations.index(latLong)
                self.locations = self.locations[0:loc]
                self.loopPromptState = 0

        #after measuring is off, setup array to use (states Calculating)
        elif self.checkedOnce == 2 and len(self.locations) > 3:
            self.locationsLeft = copy.deepcopy(self.locations)

            #do this to avoid tapping too early
            self.checkedOnce += 1

        #after the array set up, tap to get back to where you were
        elif self.checkedOnce == 3:
            text('Tap to return to start',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius + 150,
                 alignment=5)

        #The return back..
        elif self.checkedOnce == 4:

            x, y = self.locations[-1]
            x = round(x, 10)
            y = round(y, 10)

            loc = "[" + str(x) + ", " + str(y) + "]"
            fill(0.9, 0.9, 0.9)
            stroke(0, 0, 0)
            stroke_weight(0)
            # rect(0,560,self.size.w,50)
            # # text('Destination:', font_name='Verdana', font_size=12.0, x=70, y=550, alignment=5)
            # # text(loc, font_name='Verdana', font_size=12.0, x=230, y=550, alignment=5)

            totalDistanceTraveled = 0
            for i in range(len(self.locations) - 1):
                firstPosX, firstPosY = self.locations[i]
                nextPosX, nextPosY = self.locations[i + 1]
                dist = ((nextPosX - firstPosX)**2 +
                        (nextPosY - firstPosY)**2)**0.5
                totalDistanceTraveled += dist

            text('Distance Traveled:',
                 font_name='Verdana',
                 font_size=12.0,
                 x=70,
                 y=585,
                 alignment=5)
            text(str(totalDistanceTraveled),
                 font_name='Verdana',
                 font_size=12.0,
                 x=230,
                 y=585,
                 alignment=5)

            textPosX = self.size.x / 2
            textPosY = self.size.y / 2

            if (len(self.locationsLeft) > 3):
                currPosX, currPosY = self.locationsLeft[-1]
                nextPosX, nextPosY = self.locationsLeft[-2]
                secondPosX, secondPosY = self.locationsLeft[-3]
                thirdPosX, thirdPosY = self.locationsLeft[-4]

                # currPosX, currPosY = [40.4465, 79.9427]
                # nextPosX, nextPosY = [40.4465, 79.9428]
                # secondPosX, secondPosY = [40.4466, 79.9428]
                # thirdPosX, thirdPosY = [40.4466, 79.9429]

                xVal = math.cos(math.radians(nextPosX)) * math.sin(
                    math.radians(abs(currPosY - nextPosY)))
                yVal = math.cos(math.radians(currPosX)) * math.sin(
                    math.radians(nextPosX)) - math.sin(
                        math.radians(currPosX)) * math.cos(
                            math.radians(nextPosX)) * math.cos(
                                math.radians(abs(currPosY - nextPosY)))
                radianAngle1 = (math.atan2(xVal, yVal))
                degreeAngle1 = math.degrees(radianAngle1)
                if nextPosY < currPosY:
                    degreeAngle1 = 180 + (180 - degreeAngle1)

                xVal2 = math.cos(math.radians(secondPosX)) * math.sin(
                    math.radians(abs(currPosY - secondPosY)))
                yVal2 = math.cos(math.radians(currPosX)) * math.sin(
                    math.radians(secondPosX)) - math.sin(
                        math.radians(currPosX)) * math.cos(
                            math.radians(secondPosX)) * math.cos(
                                math.radians(abs(currPosY - secondPosY)))
                radianAngle2 = (math.atan2(xVal2, yVal2))
                degreeAngle2 = math.degrees(radianAngle2)
                if secondPosY < currPosY:
                    degreeAngle2 = 180 + (180 - degreeAngle2)

                xVal3 = math.cos(math.radians(thirdPosX)) * math.sin(
                    math.radians(abs(currPosY - thirdPosY)))
                yVal3 = math.cos(math.radians(currPosX)) * math.sin(
                    math.radians(thirdPosX)) - math.sin(
                        math.radians(currPosX)) * math.cos(
                            math.radians(thirdPosX)) * math.cos(
                                math.radians(abs(currPosY - thirdPosY)))
                radianAngle3 = (math.atan2(xVal3, yVal3))
                degreeAngle3 = math.degrees(radianAngle3)
                if thirdPosY < currPosY:
                    degreeAngle3 = 180 + (180 - degreeAngle3)

                #take the average of the next 3 points to get a good direction.
                trueDegree = (degreeAngle1 + degreeAngle2 + degreeAngle3) / 3

                #draw directing arrow
                tempYaw1 = -(360 - yaw + trueDegree)
                trueDegreeSin = math.sin(math.radians(tempYaw1))
                trueDegreeCos = math.cos(math.radians(tempYaw1))

                text(str(trueDegree),
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.radius + 150,
                     alignment=5)
                text(str(degreeAngle1),
                     font_name='Verdana',
                     font_size=16.0,
                     x=textPosX,
                     y=textPosY - 20,
                     alignment=5)
                text(str(degreeAngle2),
                     font_name='Verdana',
                     font_size=16.0,
                     x=textPosX,
                     y=textPosY - 40,
                     alignment=5)
                text(str(degreeAngle3),
                     font_name='Verdana',
                     font_size=16.0,
                     x=textPosX,
                     y=textPosY - 60,
                     alignment=5)

                #experimental point on arrow. Works well! but code is ugly. Will implement for loop later
                def pointMaker(self, roll, pitch, yaw):
                    stroke_weight(20)
                    line(self.centerX2 - trueDegreeCos * 100 - pitch * 3,
                         self.centerY - trueDegreeSin * 100 + roll * 3,
                         self.centerX2 + trueDegreeCos * 100 - pitch * 3,
                         self.centerY + trueDegreeSin * 100 + roll * 3)
                    stroke(1, 0.3, 0.3)
                    line(self.centerX2 + trueDegreeCos * 100 - pitch * 3,
                         self.centerY + trueDegreeSin * 100 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(19)
                    line(self.centerX2 + trueDegreeCos * 102 - pitch * 3,
                         self.centerY + trueDegreeSin * 102 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(18)
                    line(self.centerX2 + trueDegreeCos * 104 - pitch * 3,
                         self.centerY + trueDegreeSin * 104 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(17)
                    line(self.centerX2 + trueDegreeCos * 106 - pitch * 3,
                         self.centerY + trueDegreeSin * 106 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(16)
                    line(self.centerX2 + trueDegreeCos * 108 - pitch * 3,
                         self.centerY + trueDegreeSin * 108 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(15)
                    line(self.centerX2 + trueDegreeCos * 110 - pitch * 3,
                         self.centerY + trueDegreeSin * 110 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(14)
                    line(self.centerX2 + trueDegreeCos * 112 - pitch * 3,
                         self.centerY + trueDegreeSin * 112 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(13)
                    line(self.centerX2 + trueDegreeCos * 114 - pitch * 3,
                         self.centerY + trueDegreeSin * 114 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(12)
                    line(self.centerX2 + trueDegreeCos * 116 - pitch * 3,
                         self.centerY + trueDegreeSin * 116 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(11)
                    line(self.centerX2 + trueDegreeCos * 118 - pitch * 3,
                         self.centerY + trueDegreeSin * 118 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(10)
                    line(self.centerX2 + trueDegreeCos * 120 - pitch * 3,
                         self.centerY + trueDegreeSin * 120 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(9)
                    line(self.centerX2 + trueDegreeCos * 122 - pitch * 3,
                         self.centerY + trueDegreeSin * 122 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(8)
                    line(self.centerX2 + trueDegreeCos * 124 - pitch * 3,
                         self.centerY + trueDegreeSin * 124 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(7)
                    line(self.centerX2 + trueDegreeCos * 126 - pitch * 3,
                         self.centerY + trueDegreeSin * 126 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(6)
                    line(self.centerX2 + trueDegreeCos * 128 - pitch * 3,
                         self.centerY + trueDegreeSin * 128 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(5)
                    line(self.centerX2 + trueDegreeCos * 130 - pitch * 3,
                         self.centerY + trueDegreeSin * 130 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(4)
                    line(self.centerX2 + trueDegreeCos * 132 - pitch * 3,
                         self.centerY + trueDegreeSin * 132 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(3)
                    line(self.centerX2 + trueDegreeCos * 134 - pitch * 3,
                         self.centerY + trueDegreeSin * 134 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)
                    stroke_weight(2)
                    line(self.centerX2 + trueDegreeCos * 136 - pitch * 3,
                         self.centerY + trueDegreeSin * 136 + roll * 3,
                         self.centerX2 - pitch * 3, self.centerY + roll * 3)

                pointMaker(self, roll, pitch, yaw)

                stroke_weight(0)

                #tracing back steps
                current = location.get_location()
                latLong = (round(current['latitude'],
                                 4), round(current['longitude'], 4)
                           )  #solved the close points problem using rounding
                if latLong in self.locationsLeft:
                    loc = self.locationsLeft.index(latLong)
                    # self.locationsLeft.remove(latLong)
                    self.locationsLeft = self.locationsLeft[0:loc]

                #images on the trip back
                if latLong in self.photoLocations:
                    loc = self.photoLocations.index(latLong)
                    self.imageMode = True

                tint(1, 1, 1)
                fill(0, 0, 0)
                stroke(0, 0, 0)
                if self.imageMode == True:
                    rect(0, 150, self.size.w, 50)
                    text("Landmark! Tap here to see!",
                         font_name='Courier',
                         font_size=16.0,
                         x=self.centerX2,
                         y=150 + 25,
                         alignment=5)
                    self.layer.image = "Dog_Face"
                    self.add_layer(self.layer)
                    self.root_layer.update(self.dt)
                    self.root_layer.draw()

            else:
                text("Welcome Back.",
                     font_name='Verdana',
                     font_size=16.0,
                     x=textPosX,
                     y=textPosY,
                     alignment=5)

        #SOS Button and
        fill(0.95, 0.6, 0.6)
        tint(1, 1, 1, 1)
        if self.MoreState == True:
            #to seperate the active buttons from the non active ones
            fill(0, 0, 0, 0.5)
            rect(0, 0, self.size.x, self.size.y)
            #SOS Button
            fill(0.95, 0.6, 0.6, 1)
            tint(1, 1, 1, 1)
            ellipse(self.centerX2 - 0.0 - self.radius,
                    self.centerY2 - self.radius - 130, self.radius * 2,
                    self.radius * 2)
            text('SOS',
                 font_name='Verdana',
                 font_size=12.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius - 167,
                 alignment=5)

            #MAP Button
            if len(self.locations) >= 2:
                fill(0.6, 0.6, 0.95)
                tint(1, 1, 1, 1)
                ellipse(self.centerX2 - scale * 3 - self.radius,
                        self.centerY2 - self.radius - 20, self.radius * 2,
                        self.radius * 2)
                text('Map View',
                     font_name='Verdana',
                     font_size=12.0,
                     x=self.centerX2 - 112,
                     y=self.centerY2 + self.radius - 57,
                     alignment=5)

                fill(247 / 255, 170 / 255, 103 / 255)
                tint(1, 1, 1, 1)
                ellipse(self.centerX2 - self.radius,
                        self.centerY2 - self.radius - 20, self.radius * 2,
                        self.radius * 2)
                text('Share',
                     font_name='Verdana',
                     font_size=12.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.radius - 57,
                     alignment=5)

                tint(0.7, 0.7, 0.7, 1)
                if self.clipState == True:
                    text('Copied to Clipboard',
                         font_name='Verdana',
                         font_size=16.0,
                         x=self.size.x / 2,
                         y=self.size.y / 2 - 65,
                         alignment=5)

            fill(118 / 255, 191 / 255, 247 / 255)
            tint(1, 1, 1, 1)
            ellipse(self.centerX2 + scale * 3 - self.radius,
                    self.centerY2 - self.radius - 20, self.radius * 2,
                    self.radius * 2)
            text('Trace',
                 font_name='Verdana',
                 font_size=12.0,
                 x=self.centerX2 + 112,
                 y=self.centerY2 + self.radius - 57,
                 alignment=5)

            #SOS Button
            fill(0.95, 0.6, 0.6)
            tint(1, 1, 1, 1)
            ellipse(self.centerX2 - 0.0 - self.radius,
                    self.centerY2 - self.radius - 130, self.radius * 2,
                    self.radius * 2)
            text('SOS',
                 font_name='Verdana',
                 font_size=12.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius - 167,
                 alignment=5)

        #More button at the bottom of screen
        elif self.MoreState == False:
            ellipse(self.size.x / 2 - self.radius / 2, 0 - self.radius / 2 - 5,
                    self.radius, self.radius)

#-----------PATHSTATE---------------------------------------------------
        if self.pathState == True and len(self.locations) > 0:
            fill(0.7, 0.7, 0.7)
            rect(20, self.size.y / 2 - 50, self.size.x - 40, self.size.y / 3)
            fill(1, 1, 1)
            rect(25, self.size.y / 2 - 45, self.size.x - 50,
                 self.size.y / 3 - 10)

            tint(1, 0, 0, 1)
            fill(1, 0, 0)
            stroke(1, 0, 0, 1)
            stroke_weight(2)
            #line(self.size.x/2, self.size.y/2, self.size.x/2 + 10, self.size.y/2 + 10)
            iPointX, iPointY = self.locations[0]
            newLocs = [(0, 0)]
            maxDiffX = 0
            maxDiffY = 0
            xSepVals = []
            ySepVals = []

            # for loc in self.locations:
            #     xSepVals += [loc[0]]
            #     ySepVals += [loc[1]]
            #
            # maxDiffX = (max(xSepVals) - min(xSepVals))* 100000
            # maxDiffY = (max(ySepVals) - min(ySepVals))* 100000

            for loc in self.locations[1:]:
                nPointX, nPointY = loc
                dataX = (iPointX - nPointX) * 100000
                dataY = (iPointY - nPointY) * 100000
                newLocs += [(dataX, dataY)]

            for loc in newLocs:
                xSepVals += [loc[0]]
                ySepVals += [loc[1]]

            maxDiffX = (max(xSepVals) - min(xSepVals))
            maxDiffY = (max(ySepVals) - min(ySepVals))

            generalMaxDiff = max(maxDiffX, maxDiffY)

            miniX = min(xSepVals)
            miniY = min(ySepVals)
            generalMini = min(miniX, miniY)
            jumpG = 0 - generalMini
            evenedLocsX = []
            evenedLocsY = []
            for i in range(len(xSepVals)):
                evenedLocsX += [xSepVals[i] + jumpG]
                evenedLocsY += [ySepVals[i] + jumpG]

            xCenter = self.size.x / 2
            yCenter = self.size.y / 2 - 50 + 2
            colorCount = len(newLocs)
            for i in range(len(newLocs) - 1):
                xLoc1, yLoc1 = evenedLocsX[i], evenedLocsY[i]
                xLoc2, yLoc2 = evenedLocsX[i + 1], evenedLocsY[i + 1]
                stroke(((255 / colorCount) * i) / 255, 0, 0)
                fill((255 - (i * 10)) / 255, 0, 0)
                text(str(i),
                     font_name='Verdana',
                     font_size=4.0,
                     x=xCenter + xLoc1,
                     y=yCenter + yLoc1 + 20,
                     alignment=5)
                line((335 / generalMaxDiff) * xLoc1 + 20,
                     (222 / generalMaxDiff) * yLoc1 + yCenter,
                     (335 / generalMaxDiff) * xLoc2 + 20,
                     (222 / generalMaxDiff) * yLoc2 + yCenter)
                ellipse(xCenter - 2 + xLoc1, yCenter - 2 + yLoc1, 4, 4)


#-----------END OF PATHSTATE---------------------------------------------------

        if self.loopPrompt == True:
            fill(0, 0, 0)
            stroke_weight(0)
            #prompt for the loop
            rect(50, self.size.y / 2 - 50, self.size.x - 100,
                 self.size.y / 6 + 40)
            tint(1, 1, 1, 1)
            text("Stop Moving!",
                 font_name='Verdana',
                 font_size=18.0,
                 x=self.size.x / 2,
                 y=self.size.y / 2 + 65,
                 alignment=5)
            text("Looks like you\'ve made a loop",
                 font_name='Verdana',
                 font_size=13.0,
                 x=self.size.x / 2,
                 y=self.size.y / 2 + 38,
                 alignment=5)
            stroke(1, 1, 1, 1)
            stroke_weight(3)
            line(50, self.size.y / 2, self.size.x - 50, self.size.y / 2)
            line(self.size.x / 2, self.size.y / 2 - 50, self.size.x / 2,
                 self.size.y / 2)
            text("Continue",
                 font_name='Verdana',
                 font_size=15.0,
                 x=self.size.x / 2 - 70,
                 y=self.size.y / 2 - 25,
                 alignment=5)
            text("Break",
                 font_name='Verdana',
                 font_size=15.0,
                 x=self.size.x / 2 + 70,
                 y=self.size.y / 2 - 25,
                 alignment=5)
예제 #31
0
 def draw(self):
     #motion update
     gravity_vectors = motion.get_attitude()
     pitch, roll, yaw = [x for x in gravity_vectors]
     self.box_node.runAction_(
         SCNAction.rotateToX_y_z_duration_(pitch, -roll, yaw, 0))
예제 #32
0
    def draw(self):
        #Center scaling
        self.centerX = self.size.w/2
        self.centerY = self.size.h/2
        self.centerX2 = self.size.w/2
        self.centerY2 = self.size.h * (1/2)-scale*3.5

        time.sleep(0.1) #time between each redraw
        self.timerCount += 1 #add to the timer to animate and do things

        #Title Text
        tint(0,0,0,1)
        text('Thread 1.0', font_name='Courier', font_size=16.0, x=self.centerX2, y=self.centerY2+self.radius+400, alignment=5)

        #Locations recorded count
        tint(0.4,0.4,0.4,1)

        locationCountText = "Locations: " + str(len(self.locations))
        text(locationCountText, font_name='Verdana', font_size=10, x=50, y=self.centerY2+self.radius+400, alignment=5)

        if self.checkedOnce == 4:
            locationLeftText = "Left: " + str(len(self.locationsLeft))
            text(locationLeftText, font_name='Verdana', font_size=10, x=self.size.x-60, y=self.centerY2+self.radius+400, alignment=5)


        #motion
        gravX,gravY,gravZ= motion.get_gravity()
        gravity_vectors=motion.get_attitude()
        pitch = gravity_vectors[0]
        roll = gravity_vectors[1]
        yaw = gravity_vectors[2]

        #convert yaw to degrees
        yaw = -yaw*180/math.pi
        pitch = -pitch*180/math.pi

        ############# redraw screen ############
        #Reset Button
        fill(0.9,0.9,0.9)
        stroke_weight(0)
        ellipse(self.centerX2-scale*3-self.radius,self.centerY2-self.radius-130,self.radius*2,self.radius*2)
        tint(0.4,0.4,0.4,1)
        text('Reset', font_name='Verdana', font_size=12.0, x=self.centerX2-112, y=self.centerY2+self.radius-167, alignment=5)




        #compass draw
        tint(0.4,0.4,0.4,1)
        stroke(0.4,0.4,0.4)
        stroke_weight(0)
        fill(0.9,0.9,0.9)
        ellipse(self.centerX2+scale*3-self.radius,self.centerY2-self.radius-130,self.radius*2,self.radius*2)
        stroke_weight(0)
        ellipse(self.centerX2+scale*3-self.radius+3,self.centerY2-self.radius-127,self.radius*1.85,self.radius*1.85)
        ellipse(self.centerX2+scale*3-self.radius+6,self.centerY2-self.radius-124,self.radius*1.7,self.radius*1.7)
        yawSin = math.sin(math.radians(yaw))
        yawCos = math.cos(math.radians(yaw))
        stroke(0.4,0.4,0.4)
        stroke_weight(2)






        line(self.centerX2-yawCos*self.radius+scale*3,self.centerY2-yawSin*self.radius-130,self.centerX2+yawCos*self.radius+scale*3,self.centerY2+yawSin*self.radius-130)
        stroke(1,0.3,0.3)
        line(300,72.5,self.centerX2+yawCos*self.radius+scale*3,self.centerY2+yawSin*self.radius-130)
        #circle on top of compass
        stroke_weight(0)
        stroke(0.4,0.4,0.4)
        fill(1,1,1)
        ellipse(self.centerX2+scale*3-self.radius+9.5,self.centerY2-self.radius-120.5,self.radius*1.5,self.radius*1.5)
        #derive the direction (NSEW)
        def directionText(yaw):
            directionSym = ''
            #Direction
            if yaw > 60 and yaw <= 120:
                directionSym = 'N'
            elif yaw > 120 and yaw <= 150:
                directionSym = 'NE'
            elif (yaw > 150 and yaw <= 180) or (yaw >= -180 and yaw <= -150):
                directionSym = 'E'
            elif yaw > -150 and yaw <= -120:
                directionSym = 'SE'
            elif yaw > -120 and yaw <= -60:
                directionSym = 'S'
            elif yaw > -60 and yaw <= -30:
                directionSym = 'SW'
            elif yaw > -30 and yaw <= 30:
                directionSym = 'W'
            elif yaw > 30 and yaw <= 60:
                directionSym = 'NW'
            else:
                directionSym = ''
            return directionSym

        #compass text
        tint(0.4,0.4,0.4,1)
        if self.compassStat == False:
            text(directionText(yaw), font_name='Verdana', font_size=10.0, x=self.centerX2+scale*3, y=self.centerY2+self.radius-167, alignment=5)
        else:
            tempYaw = yaw+180+90
            if tempYaw > 360:
                tempYaw = tempYaw % 360
            yawString = str(int(round(tempYaw,0))) + chr(186)
            text(yawString, font_name='Verdana', font_size=10.0, x=self.centerX2+scale*3, y=self.centerY2+self.radius-167, alignment=5)


        #Center Screen Text
        tint(0.4,0.4,0.4,1)
        if self.measuringOn == False and self.checkedOnce == 0:
            text('Tap to Start', font_name='Verdana', font_size=16.0, x=self.centerX2, y=self.centerY2+self.radius+150, alignment=5)
        elif self.measuringOn == True and self.checkedOnce == 1:
            if self.timerCount//10 % 3 == 0:
                text('Measuring.', font_name='Verdana', font_size=16.0, x=self.centerX2, y=self.centerY2+self.radius+150, alignment=5)
            elif self.timerCount//10 % 3 == 1:
                text('Measuring..', font_name='Verdana', font_size=16.0, x=self.centerX2, y=self.centerY2+self.radius+150, alignment=5)
            elif self.timerCount//10 % 3 == 2:
                text('Measuring...', font_name='Verdana', font_size=16.0, x=self.centerX2, y=self.centerY2+self.radius+150, alignment=5)
            text('Tap to Stop', font_name='Verdana', font_size=16.0, x=self.centerX2, y=self.centerY2+self.radius+120, alignment=5)
        elif self.measuringOn == False and self.checkedOnce == 2:
            text('Calculating', font_name='Verdana', font_size=16.0, x=self.centerX2, y=self.centerY2+self.radius+150, alignment=5)


        #if not enough values are recorded
        tint(0.95,0.6,0.6,1)
        if self.needMore == True:
            text("Need to record more locations.", font_name='Verdana', font_size=16.0, x=self.size.x/2, y=self.size.y/2-20, alignment=5)


        tint(0.4,0.4,0.4,1)
        #When measuring is on record locations and put into array
        if self.measuringOn == True:
            current = location.get_location()
            latLong = (round(current['latitude'],4), round(current['longitude'],4)) #solved the close points problem using rounding
            if latLong not in self.locations:
                self.locations += [latLong]
                if self.activator == True:
                    self.activator = False
                self.loopPromptState = 0

            elif latLong in self.locations[0:-5] and self.activator == False:
                #sound.play_effect('arcade:Laser_1')
                self.loopPrompt = True
                self.activator = True
            if self.loopPromptState == 1:
                if self.currentLoc != latLong:
                    self.currentLoc = latLong
                    self.locations += [latLong]
            elif self.loopPromptState == 2:
                loc = self.locations.index(latLong)
                self.locations = self.locations[0:loc]
                self.loopPromptState = 0
#---------------------------------------------------------
#---------------------------------------------------------
#-----Loop Prompt Works? Test it.----------
#---------------------------------------------------------
#---------------------------------------------------------
#---------------------------------------------------------
#---------------------------------------------------------
#---------------------------------------------------------
#---------------------------------------------------------
#---------------------------------------------------------
#---------------------------------------------------------


        #after measuring is off, setup array to use (states Calculating)
        elif self.checkedOnce == 2 and len(self.locations) > 0:
            self.locationsLeft = copy.deepcopy(self.locations)

            #do this to avoid tapping too early
            self.checkedOnce += 1

        #after the array set up, tap to get back to where you were
        elif self.checkedOnce == 3:
            text('Tap to return to start', font_name='Verdana', font_size=16.0, x=self.centerX2, y=self.centerY2+self.radius+150, alignment=5)

        #The return back..
        elif self.checkedOnce == 4:
            x,y = self.locations[-1]
            x = round(x,10)
            y = round(y,10)
            loc = "[" + str(x) + ", " + str(y) + "]"
            fill(0.9,0.9,0.9)
            stroke(0,0,0)
            stroke_weight(0)
            # rect(0,560,self.size.w,50)
            # # text('Destination:', font_name='Verdana', font_size=12.0, x=70, y=550, alignment=5)
            # # text(loc, font_name='Verdana', font_size=12.0, x=230, y=550, alignment=5)

            totalDistanceTraveled = 0
            for i in range(len(self.locations)-1):
                firstPosX, firstPosY = self.locations[i]
                nextPosX, nextPosY = self.locations[i+1]
                dist = ((nextPosX - firstPosX)**2 + (nextPosY - firstPosY)**2)**0.5
                totalDistanceTraveled += dist

            text('Distance Traveled:', font_name='Verdana', font_size=12.0, x=70, y=585, alignment=5)
            text(str(totalDistanceTraveled), font_name='Verdana', font_size=12.0, x=230, y=585, alignment=5)

            textPosX = self.size.x/2
            textPosY = self.size.y/2


            if (len(self.locationsLeft) > 0):
                # currPosX, currPosY = self.locationsLeft[-1]
                # nextPosX, nextPosY = self.locationsLeft[-2]
                # secondPosX, secondPosY = self.locationsLeft[-3]
                # thirdPosX, thirdPosY = self.locationsLeft[-4]

                currPosX, currPosY = [40.4465, 79.9427]
                nextPosX, nextPosY = [40.4465, 79.9428]
                secondPosX, secondPosY = [40.4466, 79.9428]
                thirdPosX, thirdPosY = [40.4466, 79.9429]


                differenceX1 = nextPosX - currPosX
                differenceY1 = nextPosY - currPosY
                differenceX2 = secondPosX - currPosX
                differenceY2 = secondPosY - currPosY
                differenceX3 = thirdPosX - currPosX
                differenceY3 = thirdPosY - currPosY
                degreeAngle1 = 0
                degreeAngle2 = 0
                degreeAngle3 = 0

                if differenceX1 == 0:
                    if currPosX > nextPosX:
                        degreeAngle1 = 180.0
                    else:
                        degreeAngle1 = 0.0
                else:
                    directionAngle1 = math.atan(differenceY1/differenceX1)
                    degreeAngle1 = math.degrees(directionAngle1)

                #point in right direction
                if (currPosX <= nextPosX and currPosY < nextPosY):
                    degreeAngle1 = 90 - round(degreeAngle1, 4)
                elif (currPosX <= nextPosX and currPosY >= nextPosY):
                    degreeAngle1 = 90 - round(degreeAngle1, 4)
                elif (currPosX >= nextPosX and currPosY >= nextPosY):
                    degreeAngle1 = round(degreeAngle1, 4) + 180
                elif (currPosX >= nextPosX and currPosY <= nextPosY):
                    degreeAngle1 = round(degreeAngle1, 4) + 180


                if differenceX2 == 0:
                    if currPosX > secondPosX:
                        degreeAngle2 = 180.0
                    else:
                        degreeAngle2 = 0.0
                else:
                    directionAngle2 = math.atan(differenceY2/differenceX2)
                    degreeAngle2 = math.degrees(directionAngle2)

                #point in right direction
                if (currPosX <= secondPosX and currPosY <= secondPosY):
                    degreeAngle2 = round(degreeAngle2, 4)
                elif (currPosX <= secondPosX and currPosY >= secondPosY):
                    degreeAngle2 = round(degreeAngle2, 4) + 180
                elif (currPosX >= secondPosX and currPosY >= secondPosY):
                    degreeAngle2 = round(degreeAngle2, 4) + 180
                elif (currPosX >= secondPosX and currPosY <= secondPosY):
                    degreeAngle2 = round(degreeAngle2, 4) + 360

                if differenceX3 == 0:
                    if currPosX > thirdPosX:
                        degreeAngle3 = 180.0
                    else:
                        degreeAngle3 = 0.0
                else:
                    directionAngle3 = math.atan(differenceY3/differenceX3)
                    degreeAngle3 = math.degrees(directionAngle3)

                #point in right direction
                if (currPosX <= thirdPosX and currPosY <= thirdPosY):
                    degreeAngle3 = round(degreeAngle3, 4)
                elif (currPosX <= thirdPosX and currPosY >= thirdPosY):
                    degreeAngle3 = round(degreeAngle3, 4) + 180
                elif (currPosX >= thirdPosX and currPosY >= thirdPosY):
                    degreeAngle3 = round(degreeAngle3, 4) + 180
                elif (currPosX >= thirdPosX and currPosY <= thirdPosY):
                    degreeAngle3 = round(degreeAngle3, 4) + 360

                trueDegree = (degreeAngle1 + degreeAngle2 + degreeAngle3)/3
                text(str(trueDegree), font_name='Verdana', font_size=16.0, x=textPosX, y=textPosY, alignment=5)
                text(str(degreeAngle1), font_name='Verdana', font_size=16.0, x=textPosX, y=textPosY-20, alignment=5)
                text(str(degreeAngle2), font_name='Verdana', font_size=16.0, x=textPosX, y=textPosY-40, alignment=5)
                text(str(degreeAngle3), font_name='Verdana', font_size=16.0, x=textPosX, y=textPosY-60, alignment=5)


                # #tracing back steps
                # current = location.get_location()
                # latLong = (round(current['latitude'],4), round(current['longitude'],4)) #solved the close points problem using rounding
                # if latLong in self.locationsLeft:
                #     loc = self.locationsLeft.index(latLong)
                #     # self.locationsLeft.remove(latLong)
                #     self.locationsLeft = self.locationsLeft[0:loc]
            else:
                text("Welcome Back.", font_name='Verdana', font_size=16.0, x=textPosX, y=textPosY, alignment=5)


        #SOS Button and
        fill(0.95,0.6,0.6)
        tint(1,1,1,1)
        if self.MoreState == True:
            #to seperate the active buttons from the non active ones
            fill(0,0,0,0.5)
            rect(0,0,self.size.x,self.size.y)
            #SOS Button
            fill(0.95,0.6,0.6,1)
            tint(1,1,1,1)
            ellipse(self.centerX2-0.0-self.radius,self.centerY2-self.radius-130,self.radius*2,self.radius*2)
            text('SOS', font_name='Verdana', font_size=12.0, x=self.centerX2, y=self.centerY2+self.radius-167, alignment=5)

            #MAP Button
            if len(self.locations) >= 2:
                fill(0.6,0.6,0.95)
                tint(1,1,1,1)
                ellipse(self.centerX2-scale*3-self.radius,self.centerY2-self.radius-20,self.radius*2,self.radius*2)
                text('Map View', font_name='Verdana', font_size=12.0, x=self.centerX2-112, y=self.centerY2+self.radius-57, alignment=5)

            #SOS Button
            fill(0.95,0.6,0.6)
            tint(1,1,1,1)
            ellipse(self.centerX2-0.0-self.radius,self.centerY2-self.radius-130,self.radius*2,self.radius*2)
            text('SOS', font_name='Verdana', font_size=12.0, x=self.centerX2, y=self.centerY2+self.radius-167, alignment=5)

        #More button at the bottom of screen
        elif self.MoreState == False:
            ellipse(self.size.x/2-self.radius/2,0-self.radius/2-5,self.radius,self.radius)



        if self.loopPrompt == True:
            fill(0,0,0)
            #prompt for the loop
            rect(50,self.size.y/2-50,self.size.x-100,self.size.y/6+40)
            tint(1,1,1,1)
            text("Stop Moving!", font_name='Verdana', font_size=18.0, x=self.size.x/2, y=self.size.y/2+65, alignment=5)
            text("Looks like you\'ve made a loop", font_name='Verdana', font_size=13.0, x=self.size.x/2, y=self.size.y/2+38, alignment=5)
            stroke(1,1,1,1)
            stroke_weight(3)
            line(50, self.size.y/2, self.size.x-50, self.size.y/2)
            line(self.size.x/2, self.size.y/2-50, self.size.x/2, self.size.y/2)
            text("Continue", font_name='Verdana', font_size=15.0, x=self.size.x/2-70, y=self.size.y/2-25, alignment=5)
            text("Break", font_name='Verdana', font_size=15.0, x=self.size.x/2+70, y=self.size.y/2-25, alignment=5)
예제 #33
0
    def draw(self):
        time.sleep(0.1)  #time between each redraw
        self.timerCount += 1  #add to the timer to animate and do things

        #Title Text
        tint(self.theme["titleColor"])
        text('Thread 1.0',
             font_name='Courier',
             font_size=16.0,
             x=self.centerX2,
             y=self.centerY2 + self.scale + 400,
             alignment=5)

        #Locations recorded count
        tint(self.theme["locationCount"])
        locationCountText = "Locations: " + str(len(self.locations))
        text(locationCountText,
             font_name='Verdana',
             font_size=10,
             x=50,
             y=self.centerY2 + self.scale + 400,
             alignment=5)

        if self.checkedOnce == 4:
            locationLeftText = "Left: " + str(len(self.locationsLeft))
            text(locationLeftText,
                 font_name='Verdana',
                 font_size=10,
                 x=self.size.x - 60,
                 y=self.centerY2 + self.scale + 400,
                 alignment=5)

        #motion
        gravX, gravY, gravZ = motion.get_gravity()
        gravity_vectors = motion.get_attitude()
        pitch = gravity_vectors[0]
        roll = gravity_vectors[1]
        yaw = gravity_vectors[2]

        #convert yaw to degrees
        yaw = -yaw * 180 / math.pi
        pitch = -pitch * 180 / math.pi
        roll = -roll * 180 / math.pi

        ############# redraw screen ############
        #Reset Button
        fill(self.theme["buttonFill"])
        stroke_weight(0)
        ellipse(self.centerX2 - self.scale * 3 - self.scale,
                self.centerY2 - self.scale - 130, self.scale * 2,
                self.scale * 2)
        tint(self.theme["buttonText"])
        text('Reset',
             font_name='Verdana',
             font_size=12.0,
             x=self.centerX2 - 112,
             y=self.centerY2 + self.scale - 167,
             alignment=5)

        #LOCATION GET
        current = location.get_location()
        latLong = (round(current['latitude'],
                         4), round(current['longitude'], 4)
                   )  #solved the close points problem using rounding
        picTaken = latLong in self.photoLocations

        #orientation calculation
        yawSin = math.sin(math.radians(yaw))
        yawCos = math.cos(math.radians(yaw))
        rollSin = math.sin(math.radians(roll))
        rollCos = math.cos(math.radians(roll))
        pitchSin = math.sin(math.radians(pitch))
        pitchCos = math.cos(math.radians(pitch))

        #compass draw
        tint(self.theme["compassTint"])
        stroke(self.theme["compassStroke"])
        stroke_weight(0)
        fill(self.theme["compassFill1"])
        ellipse(self.centerX2 + self.scale * 3 - self.scale,
                self.centerY2 - self.scale - 130, self.scale * 2,
                self.scale * 2)
        stroke_weight(0)
        ellipse(self.centerX2 + self.scale * 3 - self.scale + 3,
                self.centerY2 - self.scale - 127, self.scale * 1.85,
                self.scale * 1.85)
        ellipse(self.centerX2 + self.scale * 3 - self.scale + 6,
                self.centerY2 - self.scale - 124, self.scale * 1.7,
                self.scale * 1.7)

        stroke_weight(2)
        stroke(self.theme["compassStrokeSouth"])
        line(self.centerX2 - yawCos * self.scale + self.scale * 3,
             self.centerY2 - yawSin * self.scale - 130,
             self.centerX2 + yawCos * self.scale + self.scale * 3,
             self.centerY2 + yawSin * self.scale - 130)
        stroke(self.theme["compassStroke2"])
        line(300, 72.5, self.centerX2 + yawCos * self.scale + self.scale * 3,
             self.centerY2 + yawSin * self.scale - 130)

        #circle on top of compass
        stroke_weight(0)
        stroke(self.theme["compassStroke"])
        fill(self.theme["compassTopFill"])
        ellipse(self.centerX2 + self.scale * 3 - self.scale + 9.5,
                self.centerY2 - self.scale - 120.5, self.scale * 1.5,
                self.scale * 1.5)

        #derive the direction (NSEW)
        def directionText(yaw):
            directionSym = ''
            #Direction
            if yaw > 60 and yaw <= 120:
                directionSym = 'N'
            elif yaw > 120 and yaw <= 150:
                directionSym = 'NE'
            elif (yaw > 150 and yaw <= 180) or (yaw >= -180 and yaw <= -150):
                directionSym = 'E'
            elif yaw > -150 and yaw <= -120:
                directionSym = 'SE'
            elif yaw > -120 and yaw <= -60:
                directionSym = 'S'
            elif yaw > -60 and yaw <= -30:
                directionSym = 'SW'
            elif yaw > -30 and yaw <= 30:
                directionSym = 'W'
            elif yaw > 30 and yaw <= 60:
                directionSym = 'NW'
            else:
                directionSym = ''
            return directionSym

        #compass text
        tint(self.theme["buttonText"])
        if self.compassStat == False:
            text(directionText(yaw),
                 font_name='Verdana',
                 font_size=10.0,
                 x=self.centerX2 + self.scale * 3,
                 y=self.centerY2 + self.scale - 167,
                 alignment=5)
        else:
            tempYaw = yaw + 180 + 90
            if tempYaw > 360:
                tempYaw = tempYaw % 360
            yawString = str(int(round(tempYaw, 0))) + chr(186)
            text(yawString,
                 font_name='Verdana',
                 font_size=10.0,
                 x=self.centerX2 + self.scale * 3,
                 y=self.centerY2 + self.scale - 167,
                 alignment=5)

        #Center Screen Text
        tint(self.theme["buttonText"])
        if self.measuringOn == False and self.checkedOnce == 0:
            text('Tap to Start',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.scale + 150,
                 alignment=5)
        elif self.measuringOn == True and self.checkedOnce == 1:
            if self.timerCount // 10 % 3 == 0:
                text('Measuring.',
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.scale + 150,
                     alignment=5)
            elif self.timerCount // 10 % 3 == 1:
                text('Measuring..',
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.scale + 150,
                     alignment=5)
            elif self.timerCount // 10 % 3 == 2:
                text('Measuring...',
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.scale + 150,
                     alignment=5)
            text('Tap to Stop',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.scale + 120,
                 alignment=5)
        elif self.measuringOn == False and self.checkedOnce == 2:
            text('Calculating',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.scale + 150,
                 alignment=5)

        #if not enough values are recorded
        tint(self.theme["needMoreText"])
        if self.needMore == True:
            text("Need to record more locations.",
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.size.x / 2,
                 y=self.size.y / 2 - 20,
                 alignment=5)

        tint(self.theme["buttonText"])
        #When measuring is on record locations and put into array
        if self.measuringOn == True:

            if picTaken == False:
                #camera mode
                stroke_weight(0)
                fill(self.theme["buttonFill"])
                tint(self.theme["buttonText"])
                ellipse(self.size.x / 2 - self.scale / 2,
                        0 - self.scale / 2 + 72, self.scale, self.scale)
                text('Snap',
                     font_name='Verdana',
                     font_size=8.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.scale - 167,
                     alignment=5)

            if latLong not in self.locations:
                self.locations += [latLong]
                if self.activator == True:
                    self.activator = False
                self.loopPromptState = 0

            elif latLong in self.locations[0:-5] and self.activator == False:
                #sound.play_effect('arcade:Laser_1')
                self.loopPrompt = True
                self.activator = True

            if self.loopPromptState == 1:
                if self.currentLoc != latLong:
                    self.currentLoc = latLong
                    self.locations += [latLong]

            elif self.loopPromptState == 2:
                loc = self.locations.index(latLong)
                self.locations = self.locations[0:loc]
                self.loopPromptState = 0

        #after measuring is off, setup array to use (states Calculating)
        elif self.checkedOnce == 2 and len(self.locations) > 3:
            self.locationsLeft = copy.deepcopy(self.locations)

            #do this to avoid tapping too early
            self.checkedOnce += 1

        #after the array set up, tap to get back to where you were
        elif self.checkedOnce == 3:
            text('Tap to return to start',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.scale + 150,
                 alignment=5)

        #The return back..
        elif self.checkedOnce == 4:

            x, y = self.locations[-1]
            x = round(x, 10)
            y = round(y, 10)

            loc = "[" + str(x) + ", " + str(y) + "]"
            fill(self.theme["buttonFill"])
            stroke(self.theme["titleColor"])
            stroke_weight(0)
            # rect(0,560,self.size.w,50)
            # # text('Destination:', font_name='Verdana', font_size=12.0, x=70, y=550, alignment=5)
            # # text(loc, font_name='Verdana', font_size=12.0, x=230, y=550, alignment=5)

            totalDistanceTraveled = 0
            for i in range(len(self.locations) - 1):
                firstPosX, firstPosY = self.locations[i]
                nextPosX, nextPosY = self.locations[i + 1]
                dist = ((nextPosX - firstPosX)**2 +
                        (nextPosY - firstPosY)**2)**0.5
                totalDistanceTraveled += dist

            # text('Distance Traveled:', font_name='Verdana', font_size=12.0, x=70, y=585, alignment=5)
            # text(str(totalDistanceTraveled), font_name='Verdana', font_size=12.0, x=230, y=585, alignment=5)

            textPosX = self.size.x / 2
            textPosY = self.size.y / 2

            if (len(self.locationsLeft) > 1):

                if (len(self.locationsLeft) > 3):
                    currPosX, currPosY = self.locationsLeft[-1]
                    nextPosX, nextPosY = self.locationsLeft[-2]
                    secondPosX, secondPosY = self.locationsLeft[-3]
                    thirdPosX, thirdPosY = self.locationsLeft[-4]

                    xNextAverage = (nextPosX + secondPosX + thirdPosX) / 3
                    yNextAverage = (nextPosY + secondPosY + thirdPosY) / 3

                elif (len(self.locationsLeft) > 2):
                    currPosX, currPosY = self.locationsLeft[-1]
                    nextPosX, nextPosY = self.locationsLeft[-2]
                    secondPosX, secondPosY = self.locationsLeft[-3]

                    xNextAverage = (nextPosX + secondPosX) / 2
                    yNextAverage = (nextPosY + secondPosY) / 2

                elif (len(self.locationsLeft) > 1):
                    currPosX, currPosY = self.locationsLeft[-1]
                    nextPosX, nextPosY = self.locationsLeft[-2]

                    xNextAverage = (nextPosX) / 1
                    yNextAverage = (nextPosY) / 1

                xVal3 = math.cos(math.radians(xNextAverage)) * math.sin(
                    math.radians(currPosY - yNextAverage))
                yVal3 = math.cos(math.radians(currPosX)) * math.sin(
                    math.radians(xNextAverage)) - math.sin(
                        math.radians(currPosX)) * math.cos(
                            math.radians(xNextAverage)) * math.cos(
                                math.radians(currPosY - yNextAverage))
                radianAngle3 = (math.atan2(xVal3, yVal3))
                degreeAngle3 = math.degrees(radianAngle3)
                if degreeAngle3 < 0:
                    degreeAngle3 = 360 + degreeAngle3

                #take the average of the next 3 points to get a good direction.
                # trueDegree = (degreeAngle1 + degreeAngle2 + degreeAngle3)/3
                trueDegree = degreeAngle3

                #draw directing arrow
                tempYaw1 = -(360 - yaw + trueDegree)
                trueDegreeSin = math.sin(math.radians(tempYaw1))
                trueDegreeCos = math.cos(math.radians(tempYaw1))

                # text(str(trueDegree), font_name='Verdana', font_size=16.0, x=self.centerX2, y=self.centerY2+self.scale+150, alignment=5)

                #experimental point on arrow. Works well! but code is ugly. Will implement for loop later
                def pointMaker(self, roll, pitch, yaw):
                    stroke_weight(20)
                    stroke(self.theme["titleColor"])
                    line(self.centerX2 - trueDegreeCos * 100,
                         self.centerY - trueDegreeSin * 100,
                         self.centerX2 + trueDegreeCos * 100,
                         self.centerY + trueDegreeSin * 100)
                    stroke(self.theme["compassStroke2"])
                    line(self.centerX2 + trueDegreeCos * 100,
                         self.centerY + trueDegreeSin * 100, self.centerX2,
                         self.centerY)
                    stroke_weight(19)
                    line(self.centerX2 + trueDegreeCos * 102,
                         self.centerY + trueDegreeSin * 102, self.centerX2,
                         self.centerY)
                    stroke_weight(18)
                    line(self.centerX2 + trueDegreeCos * 104,
                         self.centerY + trueDegreeSin * 104, self.centerX2,
                         self.centerY)
                    stroke_weight(17)
                    line(self.centerX2 + trueDegreeCos * 106,
                         self.centerY + trueDegreeSin * 106, self.centerX2,
                         self.centerY)
                    stroke_weight(16)
                    line(self.centerX2 + trueDegreeCos * 108,
                         self.centerY + trueDegreeSin * 108, self.centerX2,
                         self.centerY)
                    stroke_weight(15)
                    line(self.centerX2 + trueDegreeCos * 110,
                         self.centerY + trueDegreeSin * 110, self.centerX2,
                         self.centerY)
                    stroke_weight(14)
                    line(self.centerX2 + trueDegreeCos * 112,
                         self.centerY + trueDegreeSin * 112, self.centerX2,
                         self.centerY)
                    stroke_weight(13)
                    line(self.centerX2 + trueDegreeCos * 114,
                         self.centerY + trueDegreeSin * 114, self.centerX2,
                         self.centerY)
                    stroke_weight(12)
                    line(self.centerX2 + trueDegreeCos * 116,
                         self.centerY + trueDegreeSin * 116, self.centerX2,
                         self.centerY)
                    stroke_weight(11)
                    line(self.centerX2 + trueDegreeCos * 118,
                         self.centerY + trueDegreeSin * 118, self.centerX2,
                         self.centerY)
                    stroke_weight(10)
                    line(self.centerX2 + trueDegreeCos * 120,
                         self.centerY + trueDegreeSin * 120, self.centerX2,
                         self.centerY)
                    stroke_weight(9)
                    line(self.centerX2 + trueDegreeCos * 122,
                         self.centerY + trueDegreeSin * 122, self.centerX2,
                         self.centerY)
                    stroke_weight(8)
                    line(self.centerX2 + trueDegreeCos * 124,
                         self.centerY + trueDegreeSin * 124, self.centerX2,
                         self.centerY)
                    stroke_weight(7)
                    line(self.centerX2 + trueDegreeCos * 126,
                         self.centerY + trueDegreeSin * 126, self.centerX2,
                         self.centerY)
                    stroke_weight(6)
                    line(self.centerX2 + trueDegreeCos * 128,
                         self.centerY + trueDegreeSin * 128, self.centerX2,
                         self.centerY)
                    stroke_weight(5)
                    line(self.centerX2 + trueDegreeCos * 130,
                         self.centerY + trueDegreeSin * 130, self.centerX2,
                         self.centerY)
                    stroke_weight(4)
                    line(self.centerX2 + trueDegreeCos * 132,
                         self.centerY + trueDegreeSin * 132, self.centerX2,
                         self.centerY)
                    stroke_weight(3)
                    line(self.centerX2 + trueDegreeCos * 134,
                         self.centerY + trueDegreeSin * 134, self.centerX2,
                         self.centerY)
                    stroke_weight(2)
                    line(self.centerX2 + trueDegreeCos * 136,
                         self.centerY + trueDegreeSin * 136, self.centerX2,
                         self.centerY)

                pointMaker(self, roll, pitch, yaw)

                stroke_weight(0)

                #tracing back steps
                if latLong in self.locationsLeft:
                    loc = self.locationsLeft.index(latLong)
                    # self.locationsLeft.remove(latLong)
                    self.locationsLeft = self.locationsLeft[0:loc]

                #images on the trip back
                if latLong in self.photoLocations:
                    photoLoc = len(self.photoLocations
                                   ) - self.photoLocations.index(latLong)
                    self.imageMode = True

                    tint(self.theme["textColor2"])
                    fill(self.theme["notificationColor"])
                    stroke(self.theme["notificationColor"])

                    rect(0, 150, self.size.w, 50)
                    text("Landmark! Tap here to see!",
                         font_name='Courier',
                         font_size=16.0,
                         x=self.centerX2,
                         y=150 + 25,
                         alignment=5)
                    self.currentImage = self.photoLibrary.assets[-photoLoc]
                    self.photoWidth = self.currentImage.pixel_width
                    self.photoHeight = self.currentImage.pixel_height

                    self.ui_image = self.currentImage.get_ui_image()

            else:
                text("Welcome Back.",
                     font_name='Verdana',
                     font_size=16.0,
                     x=textPosX,
                     y=textPosY,
                     alignment=5)

        #SOS Button and
        fill(self.theme["needMoreText"])
        tint(self.theme["textColor2"])
        if self.MoreState == True:
            #to seperate the active buttons from the non active ones
            fill(self.theme["transparentFill"])
            rect(0, 0, self.size.x, self.size.y)
            #SOS Button
            fill(self.theme["needMoreText"])
            tint(self.theme["textColor2"])
            ellipse(self.centerX2 - 0.0 - self.scale,
                    self.centerY2 - self.scale - 130, self.scale * 2,
                    self.scale * 2)
            text('SOS',
                 font_name='Verdana',
                 font_size=12.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.scale - 167,
                 alignment=5)

            #MAP Button
            if len(self.locations) >= 2:
                fill(0.6, 0.6, 0.95)
                tint(1, 1, 1, 1)
                ellipse(self.centerX2 - self.scale * 3 - self.scale,
                        self.centerY2 - self.scale - 20, self.scale * 2,
                        self.scale * 2)
                text('Map View',
                     font_name='Verdana',
                     font_size=12.0,
                     x=self.centerX2 - 112,
                     y=self.centerY2 + self.scale - 57,
                     alignment=5)

                fill(247 / 255, 170 / 255, 103 / 255)
                tint(1, 1, 1, 1)
                ellipse(self.centerX2 - self.scale,
                        self.centerY2 - self.scale - 20, self.scale * 2,
                        self.scale * 2)
                text('Share',
                     font_name='Verdana',
                     font_size=12.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.scale - 57,
                     alignment=5)

                tint(0.7, 0.7, 0.7, 1)
                if self.clipState == True:
                    text('Copied to Clipboard',
                         font_name='Verdana',
                         font_size=16.0,
                         x=self.size.x / 2,
                         y=self.size.y / 2 - 65,
                         alignment=5)

            fill(118 / 255, 191 / 255, 247 / 255)
            tint(1, 1, 1, 1)
            ellipse(self.centerX2 + self.scale * 3 - self.scale,
                    self.centerY2 - self.scale - 20, self.scale * 2,
                    self.scale * 2)
            text('Trace',
                 font_name='Verdana',
                 font_size=12.0,
                 x=self.centerX2 + 112,
                 y=self.centerY2 + self.scale - 57,
                 alignment=5)

            #SOS Button
            fill(0.95, 0.6, 0.6)
            tint(1, 1, 1, 1)
            ellipse(self.centerX2 - 0.0 - self.scale,
                    self.centerY2 - self.scale - 130, self.scale * 2,
                    self.scale * 2)
            text('SOS',
                 font_name='Verdana',
                 font_size=12.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.scale - 167,
                 alignment=5)

        #More button at the bottom of screen
        elif self.MoreState == False:
            ellipse(self.size.x / 2 - self.scale / 2, 0 - self.scale / 2 - 5,
                    self.scale, self.scale)

        if self.imageModeOpen == True:
            fill(0, 0, 0, 0.5)
            rect(0, 0, self.size.x, self.size.y)
            fill(0.2, 0.2, 0.2)
            rect(0, self.halfScreenFrame, self.widthFrame, self.heightFrame)

#-----------Draw Path State---------------------------------------------------
        if self.pathState == True and len(self.locations) > 0:
            fill(0.7, 0.7, 0.7)
            rect(14, self.size.y / 2 - 55, self.size.x - 28,
                 self.size.y / 3 + 12)
            fill(1, 1, 1)
            rect(19, self.size.y / 2 - 50, self.size.x - 38,
                 self.size.y / 3 + 2)

            tint(1, 0, 0, 1)
            fill(1, 0, 0)
            stroke(1, 0, 0, 1)
            stroke_weight(2)
            iPointX, iPointY = self.locations[0]
            newLocs = [(0, 0)]
            maxDiffX = 0
            maxDiffY = 0
            xSepVals = []
            ySepVals = []

            for loc in self.locations[1:]:
                nPointX, nPointY = loc
                dataX = (iPointX - nPointX) * 100000
                dataY = (iPointY - nPointY) * 100000
                newLocs += [(dataX, dataY)]

            for loc in newLocs:
                xSepVals += [loc[0]]
                ySepVals += [loc[1]]

            maxDiffX = (max(xSepVals) - min(xSepVals))
            maxDiffY = (max(ySepVals) - min(ySepVals))

            generalMaxDiff = max(maxDiffX, maxDiffY)

            miniX = min(xSepVals)
            jumpX = 0 - miniX
            evenedLocsX = []
            for val in xSepVals:
                evenedLocsX += [val + jumpX]

            miniY = min(ySepVals)
            jumpY = 0 - miniY
            evenedLocsY = []
            for val in ySepVals:
                evenedLocsY += [val + jumpY]

            xCenter = self.size.x / 2
            yCenter = self.size.y / 2 - 50 + 2
            colorCount = len(newLocs)
            for i in range(len(newLocs) - 1):
                xLoc1, yLoc1 = evenedLocsX[i], evenedLocsY[i]
                xLoc2, yLoc2 = evenedLocsX[i + 1], evenedLocsY[i + 1]
                stroke(((255 / colorCount) * i) / 255, 0, 0)
                fill(((255 / colorCount) * i) / 255, 0, 0)
                #text(str(i),font_name='Verdana', font_size=4.0, x=(335/generalMaxDiff)*xLoc1+20, y=(222/generalMaxDiff)*yLoc1+yCenter+5, alignment=5)
                #line(xCenter + xLoc1, yCenter + yLoc1, xCenter + xLoc2, yCenter + yLoc2)
                line((335 / generalMaxDiff) * xLoc1 + 20,
                     (222 / generalMaxDiff) * yLoc1 + yCenter,
                     (335 / generalMaxDiff) * xLoc2 + 20,
                     (222 / generalMaxDiff) * yLoc2 + yCenter)
                ellipse((335 / generalMaxDiff) * xLoc1 + 20 - 2,
                        (222 / generalMaxDiff) * yLoc1 + yCenter - 2, 4, 4)
            ellipse((335 / generalMaxDiff) * evenedLocsX[-1] + 20 - 2,
                    (222 / generalMaxDiff) * evenedLocsY[-1] + yCenter - 2, 4,
                    4)


#-----------END OF PATHSTATE---------------------------------------------------

#prompt when the user goes in a loop or crosses paths with the recorded path
        if self.loopPrompt == True:
            fill(0, 0, 0)
            stroke_weight(0)
            #prompt for the loop
            rect(50, self.size.y / 2 - 50, self.size.x - 100,
                 self.size.y / 6 + 40)
            tint(1, 1, 1, 1)
            text("Stop Moving!",
                 font_name='Verdana',
                 font_size=18.0,
                 x=self.size.x / 2,
                 y=self.size.y / 2 + 65,
                 alignment=5)
            text("Looks like you\'ve made a loop",
                 font_name='Verdana',
                 font_size=13.0,
                 x=self.size.x / 2,
                 y=self.size.y / 2 + 38,
                 alignment=5)
            stroke(1, 1, 1, 1)
            stroke_weight(3)
            line(50, self.size.y / 2, self.size.x - 50, self.size.y / 2)
            line(self.size.x / 2, self.size.y / 2 - 50, self.size.x / 2,
                 self.size.y / 2)
            text("Continue",
                 font_name='Verdana',
                 font_size=15.0,
                 x=self.size.x / 2 - 70,
                 y=self.size.y / 2 - 25,
                 alignment=5)
            text("Break",
                 font_name='Verdana',
                 font_size=15.0,
                 x=self.size.x / 2 + 70,
                 y=self.size.y / 2 - 25,
                 alignment=5)
예제 #34
0
    def draw(self):
        #Center scaling
        self.centerX = self.size.w / 2
        self.centerY = self.size.h / 2
        self.centerX2 = self.size.w / 2
        self.centerY2 = self.size.h * (1 / 2) - scale * 3.5

        time.sleep(0.1)  #time between each redraw
        self.timerCount += 1  #add to the timer to animate and do things

        #Title Text
        tint(0, 0, 0, 1)
        text('Thread 1.0',
             font_name='Courier',
             font_size=16.0,
             x=self.centerX2,
             y=self.centerY2 + self.radius + 400,
             alignment=5)

        #Locations recorded count
        tint(0.4, 0.4, 0.4, 1)

        locationCountText = "Locations: " + str(len(self.locations))
        text(locationCountText,
             font_name='Verdana',
             font_size=10,
             x=50,
             y=self.centerY2 + self.radius + 400,
             alignment=5)

        if self.checkedOnce == 4:
            locationLeftText = "Left: " + str(len(self.locationsLeft))
            text(locationLeftText,
                 font_name='Verdana',
                 font_size=10,
                 x=self.size.x - 60,
                 y=self.centerY2 + self.radius + 400,
                 alignment=5)

        #motion
        gravX, gravY, gravZ = motion.get_gravity()
        gravity_vectors = motion.get_attitude()
        yaw = gravity_vectors[2]

        #convert yaw to degrees
        yaw = -yaw * 180 / math.pi

        ############# redraw screen ############
        #Reset Button
        fill(0.9, 0.9, 0.9)
        stroke_weight(0)
        ellipse(self.centerX2 - scale * 3 - self.radius,
                self.centerY2 - self.radius - 130, self.radius * 2,
                self.radius * 2)
        tint(0.4, 0.4, 0.4, 1)
        text('Reset',
             font_name='Verdana',
             font_size=12.0,
             x=self.centerX2 - 112,
             y=self.centerY2 + self.radius - 167,
             alignment=5)

        #SOS Button and
        fill(0.95, 0.6, 0.6)
        tint(1, 1, 1, 1)
        if self.MoreState == True:

            #SOS Button
            fill(0.95, 0.6, 0.6)
            tint(1, 1, 1, 1)
            ellipse(self.centerX2 - 0.0 - self.radius,
                    self.centerY2 - self.radius - 130, self.radius * 2,
                    self.radius * 2)
            text('SOS',
                 font_name='Verdana',
                 font_size=12.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius - 167,
                 alignment=5)

            #MAP Button
            if len(self.locations) >= 2:
                fill(0.6, 0.6, 0.95)
                tint(1, 1, 1, 1)
                ellipse(self.centerX2 - scale * 3 - self.radius,
                        self.centerY2 - self.radius - 20, self.radius * 2,
                        self.radius * 2)
                text('Map View',
                     font_name='Verdana',
                     font_size=12.0,
                     x=self.centerX2 - 112,
                     y=self.centerY2 + self.radius - 57,
                     alignment=5)

            #SOS Button
            fill(0.95, 0.6, 0.6)
            tint(1, 1, 1, 1)
            ellipse(self.centerX2 - 0.0 - self.radius,
                    self.centerY2 - self.radius - 130, self.radius * 2,
                    self.radius * 2)
            text('SOS',
                 font_name='Verdana',
                 font_size=12.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius - 167,
                 alignment=5)

        #More button at the bottom of screen
        elif self.MoreState == False:
            ellipse(self.size.x / 2 - self.radius / 2, 0 - self.radius / 2 - 5,
                    self.radius, self.radius)

        #compass draw
        tint(0.4, 0.4, 0.4, 1)
        stroke(0.4, 0.4, 0.4)
        stroke_weight(0)
        fill(0.9, 0.9, 0.9)
        ellipse(self.centerX2 + scale * 3 - self.radius,
                self.centerY2 - self.radius - 130, self.radius * 2,
                self.radius * 2)
        stroke_weight(0)
        ellipse(self.centerX2 + scale * 3 - self.radius + 3,
                self.centerY2 - self.radius - 127, self.radius * 1.85,
                self.radius * 1.85)
        ellipse(self.centerX2 + scale * 3 - self.radius + 6,
                self.centerY2 - self.radius - 124, self.radius * 1.7,
                self.radius * 1.7)
        yawSin = math.sin(math.radians(yaw))
        yawCos = math.cos(math.radians(yaw))
        stroke(0.4, 0.4, 0.4)
        stroke_weight(2)
        line(self.centerX2 - yawCos * self.radius + scale * 3,
             self.centerY2 - yawSin * self.radius - 130,
             self.centerX2 + yawCos * self.radius + scale * 3,
             self.centerY2 + yawSin * self.radius - 130)
        stroke(1, 0.3, 0.3)
        line(300, 72.5, self.centerX2 + yawCos * self.radius + scale * 3,
             self.centerY2 + yawSin * self.radius - 130)
        #circle on top of compass
        stroke_weight(0)
        stroke(0.4, 0.4, 0.4)
        fill(1, 1, 1)
        ellipse(self.centerX2 + scale * 3 - self.radius + 9.5,
                self.centerY2 - self.radius - 120.5, self.radius * 1.5,
                self.radius * 1.5)

        #derive the direction (NSEW)
        def directionText(yaw):
            directionSym = ''
            #Direction
            if yaw > 60 and yaw <= 120:
                directionSym = 'N'
            elif yaw > 120 and yaw <= 150:
                directionSym = 'NE'
            elif (yaw > 150 and yaw <= 180) or (yaw >= -180 and yaw <= -150):
                directionSym = 'E'
            elif yaw > -150 and yaw <= -120:
                directionSym = 'SE'
            elif yaw > -120 and yaw <= -60:
                directionSym = 'S'
            elif yaw > -60 and yaw <= -30:
                directionSym = 'SW'
            elif yaw > -30 and yaw <= 30:
                directionSym = 'W'
            elif yaw > 30 and yaw <= 60:
                directionSym = 'NW'
            else:
                directionSym = ''
            return directionSym

        #compass text
        tint(0.4, 0.4, 0.4, 1)
        if self.compassStat == False:
            text(directionText(yaw),
                 font_name='Verdana',
                 font_size=10.0,
                 x=self.centerX2 + scale * 3,
                 y=self.centerY2 + self.radius - 167,
                 alignment=5)
        else:
            tempYaw = yaw + 180 + 90
            if tempYaw > 360:
                tempYaw = tempYaw % 360
            yawString = str(int(round(tempYaw, 0))) + chr(186)
            text(yawString,
                 font_name='Verdana',
                 font_size=10.0,
                 x=self.centerX2 + scale * 3,
                 y=self.centerY2 + self.radius - 167,
                 alignment=5)

        #Center Screen Text
        tint(0.4, 0.4, 0.4, 1)
        if self.measuringOn == False and self.checkedOnce == 0:
            text('Tap to Start',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius + 150,
                 alignment=5)
        elif self.measuringOn == True and self.checkedOnce == 1:
            if self.timerCount // 10 % 3 == 0:
                text('Measuring.',
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.radius + 150,
                     alignment=5)
            elif self.timerCount // 10 % 3 == 1:
                text('Measuring..',
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.radius + 150,
                     alignment=5)
            elif self.timerCount // 10 % 3 == 2:
                text('Measuring...',
                     font_name='Verdana',
                     font_size=16.0,
                     x=self.centerX2,
                     y=self.centerY2 + self.radius + 150,
                     alignment=5)
            text('Tap to Stop',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius + 120,
                 alignment=5)
        elif self.measuringOn == False and self.checkedOnce == 2:
            text('Calculating',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius + 150,
                 alignment=5)

        #When measuring is on record locations and put into array
        if self.measuringOn == True:
            current = location.get_location()
            latLong = (round(current['latitude'],
                             4), round(current['longitude'], 4)
                       )  #solved the close points problem using rounding
            if latLong not in self.locations:
                self.locations += [latLong]

        #after measuring is off, setup array to use (states Calculating)
        elif self.checkedOnce == 2 and len(self.locations) > 2:
            #the first and last locations are usually off so pop them off
            # self.locations.pop(0)
            # self.locations.pop()
            self.locationsReversed = copy.deepcopy(self.locations)
            self.locationsReversed.reverse()
            self.locationsLeft = copy.deepcopy(self.locations)

            #do this to avoid tapping too early
            self.checkedOnce += 1

        #after the array set up, tap to get back to where you were
        elif self.checkedOnce == 3:
            text('Tap to return to start',
                 font_name='Verdana',
                 font_size=16.0,
                 x=self.centerX2,
                 y=self.centerY2 + self.radius + 150,
                 alignment=5)

            # locationList = str(self.locations[0]) + ' ' + str(self.locations[-1])
            # text(locationList, font_name='Verdana', font_size=5.0, x=self.centerX2, y=self.centerY2+self.radius+80, alignment=5)
            # locationListReversed = str(self.locationsReversed[0]) + ' ' + str(self.locationsReversed[-1])
            # text(locationListReversed, font_name='Verdana', font_size=5.0, x=self.centerX2, y=self.centerY2+self.radius+60, alignment=5)

        #The return back..
        elif self.checkedOnce == 4:
            x, y = self.locations[-1]
            x = round(x, 10)
            y = round(y, 10)
            loc = "[" + str(x) + ", " + str(y) + "]"
            fill(0.9, 0.9, 0.9)
            stroke(0, 0, 0)
            stroke_weight(0)
            rect(0, 560, self.size.w, 50)
            # text('Destination:', font_name='Verdana', font_size=12.0, x=70, y=550, alignment=5)
            # text(loc, font_name='Verdana', font_size=12.0, x=230, y=550, alignment=5)

            totalDistanceTraveled = 0
            for i in range(len(self.locations) - 1):
                firstPosX, firstPosY = self.locations[i]
                nextPosX, nextPosY = self.locations[i + 1]
                dist = ((nextPosX - firstPosX)**2 +
                        (nextPosY - firstPosY)**2)**0.5
                totalDistanceTraveled += dist

            text('Distance Traveled:',
                 font_name='Verdana',
                 font_size=12.0,
                 x=70,
                 y=585,
                 alignment=5)
            text(str(totalDistanceTraveled),
                 font_name='Verdana',
                 font_size=12.0,
                 x=230,
                 y=585,
                 alignment=5)

            textPosX = self.size.x / 2
            textPosY = self.size.y / 2

            if (len(self.locationsLeft) > 1):
                currPosX, currPosY = self.locations[-1]
                nextPosX, nextPosY = self.locations[-2]

                #differenceX = nextPosX - currPosX
                #differenceY = nextPosY - currPosY

                differenceX = 1
                differenceY = 1

                directionAngle = math.atan(differenceY / differenceX)
                degreeAngle = math.degrees(directionAngle)

                #point in right direction
                if (currPosX <= nextPosX and currPosY <= nextPosY):
                    text(str(round(degreeAngle, 4)),
                         font_name='Verdana',
                         font_size=16.0,
                         x=textPosX,
                         y=textPosY,
                         alignment=5)
                elif (currPosX <= nextPosX and currPosY >= nextPosY):
                    text(str(round(degreeAngle, 4) + 180),
                         font_name='Verdana',
                         font_size=16.0,
                         x=textPosX,
                         y=textPosY,
                         alignment=5)
                elif (currPosX >= nextPosX and currPosY >= nextPosY):
                    text(str(round(degreeAngle, 4) + 180),
                         font_name='Verdana',
                         font_size=16.0,
                         x=textPosX,
                         y=textPosY,
                         alignment=5)
                elif (currPosX >= nextPosX and currPosY <= nextPosY):
                    text(str(round(degreeAngle, 4) + 360),
                         font_name='Verdana',
                         font_size=16.0,
                         x=textPosX,
                         y=textPosY,
                         alignment=5)

                #tracing back steps
                current = location.get_location()
                latLong = (round(current['latitude'],
                                 4), round(current['longitude'], 4)
                           )  #solved the close points problem using rounding
                if latLong in self.locationsLeft:
                    loc = self.locationsLeft.index(latLong)
                    # self.locationsLeft.remove(latLong)
                    self.locationsLeft = self.locationsLeft[0:loc]
            else:
                text("Welcome Back.",
                     font_name='Verdana',
                     font_size=16.0,
                     x=textPosX,
                     y=textPosY,
                     alignment=5)
r = BasicAuthRequest(config)

location.start_updates()
motion.start_updates()

try:

    while True:
        gravity_x, gravity_y, gravity_z = motion.get_gravity()
        # gravity_data = {'x': gravity_x, 'y': gravity_y, 'z': gravity_z}

        acceleration_x, acceleration_y, acceleration_z = motion.get_user_acceleration(
        )
        # acceleration_data = {'x': acceleration_x, 'y': acceleration_y, 'z': acceleration_z}

        attitude_roll, attitude_pitch, attitude_yaw = motion.get_attitude()
        # attitude_data = {'roll': attitude_roll, 'pitch': attitude_pitch, 'yaw': attitude_yaw}

        magnetic_x, magnetic_y, magnetic_z, magnetic_accuracy = motion.get_magnetic_field(
        )
        # magnetic_data = {'x': magnetic_x, 'y': magnetic_y, 'z': magnetic_z, 'accuracy': magnetic_accuracy}

        location_data = location.get_location()

        ios_sensor_data = {
            'gravity_x': gravity_x,
            'gravity_y': gravity_y,
            'gravity_z': gravity_z,
            'acceleration_x': acceleration_x,
            'acceleration_y': acceleration_y,
            'acceleration_z': acceleration_z,
    def draw(self):
        #Box
        self.cx = self.size.w * 0.5
        self.cy = self.size.h * 0.5
        #pitch,roll,yaw
        self.cx2 = self.size.w * 0.5
        self.cy2 = self.size.h * 0.5 - scale * 3.5
        time.sleep(0.1)
        #motion
        ax, ay, az = motion.get_user_acceleration()
        gx, gy, gz = motion.get_gravity()
        gravity_vectors = motion.get_attitude()
        mx, my, mz, ma = motion.get_magnetic_field()
        pitch, roll, yaw = [x for x in gravity_vectors]
        pitch = -pitch * 180 / math.pi
        roll = roll * 180 / math.pi
        yaw = -yaw * 180 / math.pi
        #redraw screen
        fill(0.5, 0.5, 0.5)
        stroke_weight(2)
        #pitch,roll,yaw
        # ellipse(self.cx2-scale*3-self.R,self.cy2-self.R,self.R*2,self.R*2)
        # ellipse(self.cx2-0.0-self.R,self.cy2-self.R,self.R*2,self.R*2)
        ellipse(self.cx2 + scale * 3 - self.R, self.cy2 - self.R - 130,
                self.R * 2, self.R * 2)
        fill(0.7, 0.7, 0.7)
        no_stroke()
        ellipse(self.cx2 + scale * 3 - self.R + 3, self.cy2 - self.R - 127,
                self.R * 1.85, self.R * 1.85)
        fill(0.8, 0.8, 0.8)
        ellipse(self.cx2 + scale * 3 - self.R + 6, self.cy2 - self.R - 124,
                self.R * 1.7, self.R * 1.7)
        fill(0.9, 0.9, 0.9)
        ellipse(self.cx2 + scale * 3 - self.R + 9.5, self.cy2 - self.R - 120.5,
                self.R * 1.5, self.R * 1.5)

        roll_sin = math.sin(math.radians(roll))
        roll_cos = math.cos(math.radians(roll))
        pitch_sin = math.sin(math.radians(pitch))
        pitch_cos = math.cos(math.radians(pitch))
        yaw_sin = math.sin(math.radians(yaw))
        yaw_cos = math.cos(math.radians(yaw))
        # line(self.cx2-roll_cos*self.R-scale*3,self.cy2-roll_sin*self.R,self.cx2+roll_cos*self.R-scale*3,self.cy2+roll_sin*self.R)
        # line(self.cx2-pitch_cos*self.R-0,self.cy2-pitch_sin*self.R,self.cx2+pitch_cos*self.R-0,self.cy2+pitch_sin*self.R)
        stroke(0, 0, 0)
        stroke_weight(2)
        line(self.cx2 - yaw_cos * self.R + scale * 3,
             self.cy2 - yaw_sin * self.R - 130,
             self.cx2 + yaw_cos * self.R + scale * 3,
             self.cy2 + yaw_sin * self.R - 130)
        stroke(1, 0, 0)
        line(300, 72.5, self.cx2 + yaw_cos * self.R + scale * 3,
             self.cy2 + yaw_sin * self.R - 130)

        yawMatrix = np.matrix([[yaw_cos, -yaw_sin, 0], [yaw_sin, yaw_cos, 0],
                               [0, 0, 1]])
        pitchMatrix = np.matrix([[pitch_cos, 0, pitch_sin], [0, 1, 0],
                                 [-pitch_sin, 0, pitch_cos]])
        rollMatrix = np.matrix([[1, 0, 0], [0, roll_cos, -roll_sin],
                                [0, roll_sin, roll_cos]])

        R = yawMatrix * pitchMatrix * rollMatrix
        R = np.array(R)

        #x_3d,y_3d,z_3d = np.transpose(np.dot(self.Box,R),(2,0,1))
        #zmin = np.argmin(z_3d)

        #derive the direction (NSEW)
        def directionText(yaw):
            directionSym = ''
            #Direction
            if yaw > 60 and yaw <= 120:
                directionSym = 'N'
            elif yaw > 120 and yaw <= 150:
                directionSym = 'NE'
            elif (yaw > 150 and yaw <= 180) or (yaw >= -180 and yaw <= -150):
                directionSym = 'E'
            elif yaw > -150 and yaw <= -120:
                directionSym = 'SE'
            elif yaw > -120 and yaw <= -60:
                directionSym = 'S'
            elif yaw > -60 and yaw <= -30:
                directionSym = 'SW'
            elif yaw > -30 and yaw <= 30:
                directionSym = 'W'
            elif yaw > 30 and yaw <= 60:
                directionSym = 'NW'
            else:
                directionSym = ''

            return directionSym

        #text
        tint(0, 0, 0, 1)
        text('Thread 1.0',
             font_name='Courier',
             font_size=16.0,
             x=self.cx2,
             y=self.cy2 + self.R + 400,
             alignment=5)
        if self.measuringOn == False and self.checkedOnce == 0:
            text('Tap to Start',
                 font_name='Helvetica',
                 font_size=16.0,
                 x=self.cx2,
                 y=self.cy2 + self.R + 150,
                 alignment=5)
        elif self.measuringOn == True and self.checkedOnce == 1:
            if self.testCounter % 3 == 0:
                text('Measuring.',
                     font_name='Helvetica',
                     font_size=16.0,
                     x=self.cx2,
                     y=self.cy2 + self.R + 150,
                     alignment=5)
            elif self.testCounter % 3 == 1:
                text('Measuring..',
                     font_name='Helvetica',
                     font_size=16.0,
                     x=self.cx2,
                     y=self.cy2 + self.R + 150,
                     alignment=5)
            elif self.testCounter % 3 == 2:
                text('Measuring...',
                     font_name='Helvetica',
                     font_size=16.0,
                     x=self.cx2,
                     y=self.cy2 + self.R + 150,
                     alignment=5)
            text('Tap to Stop',
                 font_name='Helvetica',
                 font_size=16.0,
                 x=self.cx2,
                 y=self.cy2 + self.R + 120,
                 alignment=5)

        elif self.measuringOn == False and self.checkedOnce == 2:
            text('Calculating',
                 font_name='Helvetica',
                 font_size=16.0,
                 x=self.cx2,
                 y=self.cy2 + self.R + 120,
                 alignment=5)

        #compass text
        text(directionText(yaw),
             font_name='Helvetica',
             font_size=10.0,
             x=self.cx2 + scale * 3,
             y=self.cy2 + self.R - 100,
             alignment=5)

        if self.measuringOn == True:
            time.sleep(0.2)
            current = location.get_location()
            latLong = (current['latitude'], current['longitude'])
            self.locations += [latLong]
            self.testCounter += 1
            #sound.play_effect('arcade:Laser_2')
        elif self.checkedOnce == 2:
            self.locationsReversed = copy.deepcopy(self.locations)
            self.locationsReversed.reverse()

            #now use the locations and map it onto a map so you know the direciton between points (NWSE)
            #start saying stuff like "Point North and Move Forward"
            #Now it makes sense why we use the compass.

            #test texts
            self.checkedOnce += 1

        elif self.checkedOnce == 3 or self.checkedOnce == 4:

            locationList = str(self.locations[0]) + ' ' + str(
                self.locations[-1])
            text(locationList,
                 font_name='Helvetica',
                 font_size=5.0,
                 x=self.cx2,
                 y=self.cy2 + self.R + 80,
                 alignment=5)
            locationListReversed = str(self.locationsReversed[0]) + ' ' + str(
                self.locationsReversed[-1])
            text(locationListReversed,
                 font_name='Helvetica',
                 font_size=5.0,
                 x=self.cx2,
                 y=self.cy2 + self.R + 60,
                 alignment=5)
예제 #37
0
파일: Pacer.py 프로젝트: michaeluhl/Pacer
 def __collect(self):
     uacc = np.zeros(4)
     uacc[1:] = motion.get_user_acceleration()
     qp = quat_from_euler(*motion.get_attitude())
     q = quat_conj(qp)
     return quat_product(quat_product(q,3.28*9.81*uacc),qp)[1:]