Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
78 views
in Technique[技术] by (71.8m points)

python - Importing at different times

I have a GPS sensor that is hardwired to take reading every 15 seconds. I need to run calculations using the readings given after the intervals. So, after the first run, store the latitude as x, and after its 15 seconds, pull that new latitude and save it as x1. How would I go about doing that in Python?

Sample of what I need to be done:

def ExpectedLocation():
    LatitudeChange = x1 - x
    LongitudeChange = y1 - y
    ExpectedLatitude = x1 + LatitudeChange
    ExpectedLongitude = y1 + LongitudeChange
question from:https://stackoverflow.com/questions/65909000/importing-at-different-times

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can just swap x1 with x when you complete your operations.

Def ExpectedLocation(x1):
    x1 = getDataFromSensor()
    # sleep for 15 secs
    while True:
        x = getDataFromSensor()
        # doSomething()
        x1 = x
        # sleep for 15 secs



与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...