Beispiel #1
0
 def test_bearing(self):
     C = Compass(43.682213, -70.450696, 0)
     self.assertEqual(round(C.get_bearing(43.682194, -70.450769), 2),
                      250.21)
     C = Compass(0, 0, 0)
     self.assertEqual(round(C.get_bearing(90, 0), 2), 0)
     self.assertEqual(round(C.get_bearing(0, 90), 2), 90)
     self.assertEqual(round(C.get_bearing(-90, 0), 2), 180)
     self.assertEqual(round(C.get_bearing(0, -90), 2), 270)
     C = Compass(33.77487, -84.39904, 0)
     self.assertEqual(round(C.get_bearing(34.44768, -84.39367), 3),
                      0.377)  #N - 74.633 km, 46.375 mi,
     self.assertEqual(round(C.get_bearing(34.28672, -83.75097), 3),
                      46.197)  #NE - 82.495 km, 51.26 mi
     self.assertEqual(round(C.get_bearing(33.77001, -83.69604), 3),
                      90.281)  #E - 65.121 km, 40.464 mi
     self.assertEqual(round(C.get_bearing(33.46581, -83.98718), 3),
                      131.909)  #SE - 51.339 km, 31.901 mi
     self.assertEqual(round(C.get_bearing(33.4933, -84.43487), 3),
                      186.058)  #S - 31.407 km, 19.515 mi
     self.assertEqual(round(C.get_bearing(33.54368, -84.62301), 3),
                      218.943)  #SW - 33.001 km, 20.506 mi
     self.assertEqual(round(C.get_bearing(33.76829, -84.71982), 3),
                      268.676)  #W - 29.723 km, 18.469 mi
     self.assertEqual(round(C.get_bearing(34.03842, -84.68068), 3),
                      318.508)  #NW - 39.154 km, 24.329 mi
Beispiel #2
0
class antenna_tracker():
    def __init__(self, servo_COM, antenna_Lat, antenna_Lon, antenna_altitude):
        self.compass = Compass(antenna_Lat, antenna_Lon, antenna_altitude)
        print(self.compass)
        self.servo_COM = servo_COM

    def panBothServos(self):  #Moves servos through range of motion tests
        #global s
        print "Starting serial communication with", servoCOM
        if servoAttached:
            for i in range(127, 0, -2):
                self.moveTiltServo(i)
                self.movePanServo(i)
                time.sleep(0.05)
            time.sleep(1)

            for i in range(0, 254, 2):
                self.moveTiltServo(i)
                self.movePanServo(i)
                time.sleep(0.05)
            time.sleep(1)
            print "Motion Test Finished"
        else:
            print "Error: Settings set to no Servo Connection"

    def moveToCenterPos(
        self
    ):  #Send servos to their center pos (should be horizontal and straight ahead if zeroed)
        #global s
        print "Starting serial communication with", servoCOM
        if servoAttached:
            self.moveTiltServo(127)
            self.movePanServo(127)
            print "Move to Center Command Sent via", servoCOM
        else:
            print "Error: Settings set to no Servo Connection"

    def moveToTarget(
            self, bearing,
            elevation):  #moves servos based on a bearing and elevation angle

        centerBear = 0

        temp = 0
        if ((bearing > 180) and (centerBear == 0)):
            centerBear = 360
        elif (((centerBear - bearing) > 180) and (centerBear >= 270)):
            bearing = bearing + 360
        elif (((centerBear - bearing) > 180) and (centerBear <= 180)):
            temp = centerBear
            centerBear = 360 + temp
        #print ("\tBearing: %.0f" %bearing)
        #print ("\tElevation Angle: %.0f"%elevation)
        #panTo = (((offsetDegrees-bearing+panOffset)*255)/panRange)+127.5
        # With new digital servos, can use map method as described here: http://arduino.cc/en/reference/map
        panTo = ((bearing - (centerBear - 168)) * (servo_max - servo_min) /
                 ((centerBear + 168) -
                  (centerBear - 168)) + servo_min) + (255 * panOffset / 360)
        if panTo > 254: panTo = 254
        if panTo < 0: panTo = 0
        #print "\tServo Degrees:"
        if servoAttached:
            self.movePanServo(math.trunc(panTo))
        #tiltTo = (255*(96-elevation))/90
        #tiltTo = (255*(tiltRange-elevation+tiltOffset))/90
        #If Error in Antenna Mount i.e. put antenna on backwards fix with changing 0-elevation to elevation (must change tilt stops too
        tiltTo = (((0 - elevation) - tilt_angle_min) *
                  (servo_max - servo_min) /
                  (tilt_angle_max - tilt_angle_min) + servo_min) + tiltOffset
        if tiltTo > 254: tiltTo = 254
        if tiltTo < 0: tiltTo = 0
        if servoAttached:
            self.moveTiltServo(math.trunc(tiltTo))
        if (temp != 0):
            centerBear = temp
        #if servoAttached:
        #    s.close()

    def moveTiltServo(self, position):
        s = serial.Serial(self.servo_COM,
                          baudrate=servoBaud,
                          timeout=servoTimeout)
        #move tilt
        if (position < 70):  #80 degrees upper limit
            moveTilt = [moveCommand, tiltChannel, chr(70)]
        elif (position > 123):  #5 degrees lower limit
            moveTilt = [moveCommand, tiltChannel, chr(123)]
        else:
            moveTilt = [moveCommand, tiltChannel, chr(position)]
        s.write(moveTilt)
        #print "\t\tTilt Pan: ", float(position)
        #RFD (for use with a second antenna tracker)
        #            moveTilt = [moveCommand,rfd_tiltChannel,chr(position)]
        s.close()
        #print("Tilting")

    def movePanServo(self, position):
        s = serial.Serial(self.servo_COM,
                          baudrate=servoBaud,
                          timeout=servoTimeout)
        '''
                if previousPan > position:
                    position += 1
                previousPan = position
                '''
        #move Ubiquity
        movePan = [moveCommand, panChannel, chr(255 - position)]
        s.write(movePan)
        #move RFD
        #           movePan = [moveCommand,rfd_panChannel,chr(255-position)]
        #            s.write(movePan)
        #print "\t\tMove Pan: ", float(position)
        s.close()
        #print("Paning")

    def pointToTarget(self, latitude, longitude, altitude):

        distance = self.compass.get_distance(latitude, longitude)
        bearing = self.compass.get_bearing(latitude, longitude)
        angle = self.compass.get_elevation(latitude, longitude, altitude)
        feet_to_miles = (1 / 5280)
        print("Dist={0:.2f}, Bearing={1:.2f}, Angle={2:.2f}".format(
            distance * feet_to_miles, bearing, angle))
        self.moveToTarget(bearing, angle)