Exemple #1
0
def helper():
    # Setting initial terms so we can run scans
    try:
        counter = 0
        initial_terms = 0
        returning = {}
        print('Initiating GPS scan...')
        m_gps = gps.GPS()
        while counter < int(os.getenv("GPS_SCANS", 3)):
            print('Waiting for fix...')
            counter += 1
            gps_data = m_gps.gather()
            if gps_data:
                ts = bool(gps_data["time"])
                lat = bool(gps_data["lat"])
                lon = bool(gps_data["lon"])
                alt = bool(gps_data["alt"])
            else:
                ts = lat = lon = alt = False
                time.sleep(1)

            count = ts + lat + lon + alt
            if count > initial_terms:
                returning = gps_data
                initial_terms = count

        return returning
    except Exception as e:
        print(e)
        return None
Exemple #2
0
 def __init__(self):
     self.gps = gps.GPS()
     self.radio = radio.radio()
     
     #開始時間の記録
     self.startTime = time.time()
     self.timer = 0
Exemple #3
0
    def __init__(self):
        #オブジェクトの生成
        self.rightmotor = motor.motor(ct.const.RIGHT_MOTOR_IN1_PIN,
                                      ct.const.RIGHT_MOTOR_IN2_PIN,
                                      ct.const.RIGHT_MOTOR_VREF_PIN)
        self.leftmotor = motor.motor(ct.const.LEFT_MOTOR_IN1_PIN,
                                     ct.const.LEFT_MOTOR_IN2_PIN,
                                     ct.const.LEFT_MOTOR_VREF_PIN)
        self.gps = gps.GPS()
        self.bno055 = bno055.BNO055()
        self.radio = radio.radio()
        self.RED_LED = led.led(ct.const.RED_LED_PIN)
        self.BLUE_LED = led.led(ct.const.BLUE_LED_PIN)
        self.GREEN_LED = led.led(ct.const.GREEN_LED_PIN)

        #開始時間の記録
        self.startTime = time.time()
        self.timer = 0
        self.landstate = 0  #landing stateの中でモータを一定時間回すためにlandのなかでもステート管理するため
        self.v_right = 100
        self.v_left = 100

        #変数
        self.state = 0
        self.laststate = 0
        self.landstate = 0

        #stateに入っている時刻の初期化
        self.preparingTime = 0
        self.flyingTime = 0
        self.droppingTime = 0
        self.landingTime = 0
        self.pre_motorTime = 0
        self.waitingTime = 0
        self.runningTime = 0
        self.goalTime = 0

        #state管理用変数初期化
        self.countPreLoop = 0
        self.countFlyLoop = 0
        self.countDropLoop = 0
        self.countGoal = 0
        self.countAreaLoopEnd = 0  # 終了判定用
        self.countAreaLoopStart = 0  # 開始判定用
        self.countAreaLoopLose = 0  # 見失い判定用
        self.countgrass = 0

        #GPIO設定
        GPIO.setmode(GPIO.BCM)  #GPIOの設定
        GPIO.setup(ct.const.FLIGHTPIN_PIN, GPIO.IN)  #フライトピン用

        date = datetime.datetime.now()
        self.filename = '{0:%Y%m%d}'.format(date)
        self.filename_hm = '{0:%Y%m%d%H%M}'.format(date)

        if not os.path.isdir(
                '/home/pi/Desktop/wolvez2021/Testcode/EtoEtest/%s/' %
            (self.filename)):
            os.mkdir('/home/pi/Desktop/wolvez2021/Testcode/EtoEtest/%s/' %
                     (self.filename))
Exemple #4
0
    def __init__(self, config):
        self.config = config
        self.use_gps = config["use_gps"]
        self.detector_sensibility = config["detector_sensibility"]
        self.min_decision_frames = config["min_decision_frames"]
        self.DB = db.DB("tst", config["save_dir"])
        self.DB.connect()
        self.session = self.DB.get_session()
        self.person_id = 0
        self.frame_id = 0
        self.detecting_id_cam1 = 0
        self.detecting_id_cam2 = 0
        self.identity_dict = {}
        self.identity_list = []
        self.verify_dict = {}
        self.vidsource = videofeed.VideoFeed(config)
        self.cam1 = 0
        self.cam2 = 1
        self.cam1_rotate_deg = config.get('cam1_rotate_deg', 0)
        self.cam2_rotate_deg = config.get('cam2_rotate_deg', 0)
        self.stats = DetectorStats(
            cam_stats=[CameraStats(fps=self.vidsource.fps[0]),
                       CameraStats(fps=self.vidsource.fps[1])])

        if config.get('switch_cameras_on_start', False):
            self._switch_cams()

        self.GPS = None
        if self.use_gps:
            self.GPS = gps.GPS()
            self.GPS.start()
Exemple #5
0
    def __init__(self, gps_rate=None):
        # initialize objects
        self._gui = gui.GUI()
        self._buttons = buttons.Buttons(on_green=self.green_callback,
                                        on_blue=self.blue_callback,
                                        on_red=self.red_callback)
        self.rs = RobotState()
        print("The first state in the state machine is: %s" % rs.state)

        self._gps = gps.GPS()
Exemple #6
0
 def __init__(self, mode='real'):
     if mode == 'test':
         print("Robot is in test mode")
     self.ok_status = False
     self.logger = logger.Logger()
     self.gps = gps.GPS(self.logger, mode=mode)
     self.powersteering = powersteering.Powersteering(self.logger,
                                                      self.gps,
                                                      mode=mode)
     if self.gps._running == False or self.powersteering._running == False:
         self.logger.write("One or more robot components failed to start")
         return
     self.ok_status = True
Exemple #7
0
    def __init__(self):
        #オブジェクトの生成
        #self.rightmotor = motor.motor(ct.const.RIGHT_MOTOR_VREF_PIN,ct.const.RIGHT_MOTOR_IN1_PIN,ct.const.RIGHT_MOTOR_IN2_PIN)
        #self.leftmotor = motor.motor(ct.const.LEFT_MOTOR_VREF_PIN,ct.const.LEFT_MOTOR_IN1_PIN,ct.const.LEFT_MOTOR_IN2_PIN)
        self.gps = gps.GPS()
        #self.bno055 = bno055.BNO()
        self.radio = radio.radio()
        #self.ultrasonic = ultrasonic.Ultrasonic()
        #self.RED_LED = led.led(ct.const.RED_LED_PIN)
        #self.BLUE_LED = led.led(ct.const.BLUE_LED_PIN)
        #self.GREEN_LED = led.led(ct.const.GREEN_LED_PIN)

        #開始時間の記録
        self.startTime = time.time()
        self.timer = 0
        """
Exemple #8
0
 def __init__(self):
     ADC.setup()
     # setup i2c to motorshield
     self.pwm = Adafruit_PCA9685.PCA9685(address=0x60, busnum=1)
     self.pwm.set_pwm_freq(60)
     self.mag = MAG.Magnetometer()
     self.gps = GPS.GPS()
     self.pot_pid = PID.PID(-1, 0, 0)
     # Potentiometer pin:
     self.POT_PIN = "AIN2"
     self.POT_LEFT = 0.771
     self.POT_MIDDLE = 0.553
     self.POT_RIGHT = 0.346
     self.POT_TOL = 0.01
     # autopilot
     self.auto = True
     # list of GPS coords to travel to
     self.destinations = []
Exemple #9
0
def init():
    global uart
    # Initialising UART6 (Y1, Y2)
    uart = UART(6, baudrate=38400, timeout=10, read_buf_len=200)
    pyb.repl_uart(uart)
    print('RPi UART setup')

    global uart_gps
    global gps_device
    global gps_planner
    uart_gps = UART(4, baudrate=9600, timeout=10, read_buf_len=600)
    gps_device = gps.GPS(uart_gps)
    gps_planner = planner.PLANNER(gps_device)
    print("GPS set up")

    global pid_test
    pid_test = pid.PID(0.3, 0, 0.1, gps_planner.dist_bearing, 1)

    # If True, uart messages are sent back normally,
    # if false, only log messages are sent back.
    global UART_comms_master
    UART_comms_master = False

    global imu, fuse, i2c
    global imu_acc, imu_gyr, imu_mag

    i2c = I2C(scl=Pin('Y9'), sda=Pin('Y10'))
    try:
        imu = MPU9250(i2c, scaling=(-1, -1, -1))
        imu._mag.cal = (20.915039062, 11.880468750, 23.293359375)
        imu.gyro_filter_range = 4
        imu.accel_filter_range = 4
        print(imu.mag.cal)
        print(imu.accel.cal)
        print(imu.gyro.cal)
        mpu_addr = "MPU9250 id: {:X}".format(imu.mpu_addr)
        cmd.send_uart(mpu_addr, True)
        fuse = Fusion()
    except:
        cmd.send_uart("No imu detected", True)

    sensors.ina_init(i2c)
Exemple #10
0
        for line in f2:
            l = line.split(' ')
            rec = record.Record(l[0], l[1], l[2])
            oldRecords2.append(rec)
    with open(file3) as f3:
        for line in f3:
            l = line.split(' ')
            rec = record.Record(l[0], l[1], l[2])
            oldRecords3.append(rec)
    with open(file4) as f4:
        for line in f4:
            l = line.split(' ')
            rec = record.Record(l[0], l[1], l[2])
            oldRecords4.append(rec)

gps1 = gp.GPS(oldRecords1, inRealTime, "COM9", 115200)
gps2 = gp.GPS(oldRecords2, inRealTime, "COM7", 115200)
gps3 = gp.GPS(oldRecords3, inRealTime, "COM10", 115200)
gps4 = gp.GPS(oldRecords4, inRealTime, "COM8", 115200)

#shouldInterpolate = None

prevheading = 0

recordStorage1, recordStorage2, recordStorage3, recordStorage4 = [], [], [], []

with open(f, 'r') as f1:
    with open(file2, 'r') as f2:
        with open(file3, 'r') as f3:
            with open(file4, 'r') as f4:
                ifFirst = True
Exemple #11
0
 def __init__(self):
     self.gps = gps.GPS()
Exemple #12
0
#!/usr/bin/python

import gps
position = gps.GPS("gps")
position.monitor("/dev/ttyUSB0")
Exemple #13
0
import gps as gp
#we started from the end of teh road to a lamp post

fileName = "DGPSTest7.csv"
ifReal = True
data = []
COM = "COM8"
baud = 115200
gps = gp.GPS(data, ifReal, COM, baud)

print("The file you are writing to is: " + fileName)
input("Press the quit button if this is not correct")

count = 0

with open(fileName, 'w') as f1:
    while True:
        try:
            if (gps.is_fixed()):
                gps.refresh()
                f1.write("%s,%s,%s\n" %
                         (gps.get_lat(), gps.get_lon(), gps.get_time()))
                print("recording..." + str(count))
                count += 1
        except KeyboardInterrupt:
            print("quit by keyboard")
            break
                y += acccen
            x += acccen
        return bestsim


# testCo = Coordinate(41.78770667, -88.35622)
# testCo2 = Coordinate(41.78770667, -88.35624167)
# Vec = Vector(Coordinate(41.78770667, -88.35624167), Coordinate(41.78770667, -88.35622))
# vec2 = Vector(testCo, testCo2)
# poly = Polygon(Coordinate(41.78770667, -88.35624167), .5, 2)
# shifts = [0, 1, 2, 3, 4, 5]
# print(poly.shift(shifts))
# GPS = Polygon()
f = open("Bearing_4GPS_test1", "w")
distanceRadius = 1.25
gps13 = gp.GPS("COM4", 115200)
gps24 = gp.GPS("COM3", 115200)
# f1 = open("GPS1_4GPS_test3.txt", "r+")
# f2 = open("GPS2_4GPS_test3.txt", "r+")
# f3 = open("GPS3_4GPS_test3.txt", "r+")
# f4 = open("GPS4_4GPS_test3.txt", "r+")
#
# thread1 = myThread()
#
# thread1.start()

with open("GPS1_4GPS_test4.txt", "r+") as f1:
    with open("GPS2_4GPS_test4.txt", "r+") as f2:
        with open("GPS3_4GPS_test4.txt", "r+") as f3:
            with open("GPS4_4GPS_test4.txt", "r+") as f4:
                while True:
Exemple #15
0
#
# gps_test.py - quick test of the GPS class
#
import logger
import gps
import time

my_log = logger.Logger()
my_gps = gps.GPS(my_log)

my_gps.start()
time.sleep(3)

while True:
    print(my_gps.get_values())
    time.sleep(1)

 def startup(self):
     self.session = gps.GPS("localhost", "2947")
     self.session.stream(gps.WATCH_ENABLE | gps.WATCH_NEWSTYLE)
     return True
Exemple #17
0
from sht31 import sht31
from influxdb import InfluxDBClient
import gps
import socket
import time
import sys

if len(sys.argv) < 3:
    print("I2C & Serial devices as argument expected")
    sys.exit(1)

# Set the I2C device and device address
mysht31 = sht31.SHT31(sys.argv[1], 0x44)
mygps = gps.GPS(sys.argv[2], 9600, 1)

hostname = socket.gethostname()

client = InfluxDBClient(host='influxdb', port=8086)
client.create_database('sht31')
client.switch_database('sht31')

data = [{
    "measurement": "conditions",
    "tags": {
        "host": "",
    },
    "fields": {
        "cTemp": "",
        "fTemp": "",
        "humidity": "",
        "lat": "",
Exemple #18
0
 def connect_to_gps(self):
     self.gps = gps.GPS()
     print(">>>Connecting to GPS")
     gpsRead = threading.Thread(target=self.gps.startRead, args=(0,))
     gpsRead.start()
Exemple #19
0
import gps
import time

FPS = 4
last_frame_time = 0
gps = gps.GPS()

init_longitude = None
init_latitude = None

key = input('Do you want to start the episode? (y/n)')

if key == 'y':
    while True:
        current_time = time.time()
        last_frame_time = current_time

        sleep_time = 1./FPS - (current_time - last_frame_time)
        if sleep_time > 0:
            time.sleep(sleep_time)
        if gps.is_ready:
            if not init_longitude or not init_longitude:
                init_longitude = gps.longitude
                init_latitude = gps.latitude
            else:
                print(float(gps.longitude) - float(init_longitude), float(gps.latitude) - float(init_latitude))


else:
    print('Episode is not started!')
Exemple #20
0
if gps1.is_fixed():
    lat = gps1.get_lat()
    lon = gps1.get_lon()
    print (lat, lon)
    file_.write("%s %s\n" % (lat, lon))
else:
    print("Can't get fixed")"""
import time
import math
import gps as gp
def findHeading(lat, lon, lat2, lon2):
    y = lon2 - lon
    x = lat2 - lat
    return 90 - math.degrees(math.atan2(y, x))

g = gp.GPS("COM5", 115200)
f1 = open("GPS1_output", "w+")
f2 = open("GPS2_output", "w+")
f3 = open("Bearing", "w+")
while True:
    g.refresh()
    checkGPS = str(g.info[len(g.info)-1])
    lat = g.get_lat()
    lon = g.get_lon()
    time = g.get_time()
    if checkGPS[0:4] == "GPS1":
        f1.write("%s %s %s\n" % (lat, lon, time))
    elif checkGPS[0:4] == "GPS2":
        f2.write("%s %s %s\n" % (lat, lon, time))
    g.refresh()
    lat2 = g.get_lat()
#!/usr/bin/python
import sys
from track import Track
import gps,compass
import config

c= config.Config()
track = Track(c.position_log_name)
gps.GPS("gps")
compass.Compass("compass",c.compass_deviation)
track.replay(float(c.position_log_rate))
Exemple #22
0
def gps_loop():
    g = gps.GPS('/dev/ttyUSB0', 9600, 10)
    while True:
        g.parse()
        socketio.emit('gps', g.get_json())