Skip to content

Commit

Permalink
Push dependent clock code up to the top #117
Browse files Browse the repository at this point in the history
  • Loading branch information
fnoop committed Mar 12, 2020
1 parent 080cd6e commit b7fc1e3
Showing 1 changed file with 47 additions and 45 deletions.
92 changes: 47 additions & 45 deletions vision_landing
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

# vision_landing
Expand All @@ -25,6 +25,51 @@ import signal
import logging
import ctypes


### ================================
### Define Functions
### ================================

# Return correctly typed config parser option
def get_config_value(parser, section, option):
"""Parses config value as python type"""
try:
return parser.getint(section, option)
except ValueError:
pass
try:
return parser.getfloat(section, option)
except ValueError:
pass
try:
return parser.getboolean(section, option)
except ValueError:
pass
return parser.get(section, option)

# Setup monotonic clock
CLOCK_MONOTONIC_RAW = 4
class timespec(ctypes.Structure):
_fields_ = [
('tv_sec', ctypes.c_long),
('tv_nsec', ctypes.c_long)
]
librt = ctypes.CDLL('librt.so.1', use_errno=True)
clock_gettime = librt.clock_gettime
clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]

def monotonic_time():
t = timespec()
if clock_gettime(CLOCK_MONOTONIC_RAW , ctypes.pointer(t)) != 0:
errno_ = ctypes.get_errno()
raise OSError(errno_, os.strerror(errno_))
return (t.tv_sec * 1e+9) + t.tv_nsec

### ================================
### End Define Functions
### ================================


### ================================
### Define Classes
### ================================
Expand Down Expand Up @@ -397,30 +442,6 @@ class SigTrack:
### End Define Classes
### ================================

### ================================
### Define Functions
### ================================

# Return correctly typed config parser option
def get_config_value(parser, section, option):
"""Parses config value as python type"""
try:
return parser.getint(section, option)
except ValueError:
pass
try:
return parser.getfloat(section, option)
except ValueError:
pass
try:
return parser.getboolean(section, option)
except ValueError:
pass
return parser.get(section, option)

### ================================
### End Define Functions
### ================================

### --------------------------------
### Parse arguments, setup logging
Expand Down Expand Up @@ -532,7 +553,7 @@ except Exception as error:
exit(1)
track_targets.process.poll()
if track_targets.process.returncode != None:
log.critical("Error starting track_targets")
log.critical("Error starting track_targets: ".format(track_targets.process.returncode))
exit(1)

# Define a function that stops and clears up cv process
Expand All @@ -558,25 +579,6 @@ sigtracker = SigTrack()
signal.signal(signal.SIGINT, sigtracker.handle_sig)
signal.signal(signal.SIGTERM, sigtracker.handle_sig)

# Setup monotonic clock
CLOCK_MONOTONIC_RAW = 4
class timespec(ctypes.Structure):
_fields_ = [
('tv_sec', ctypes.c_long),
('tv_nsec', ctypes.c_long)
]
librt = ctypes.CDLL('librt.so.1', use_errno=True)
clock_gettime = librt.clock_gettime
clock_gettime.argtypes = [ctypes.c_int, ctypes.POINTER(timespec)]

def monotonic_time():
t = timespec()
if clock_gettime(CLOCK_MONOTONIC_RAW , ctypes.pointer(t)) != 0:
errno_ = ctypes.get_errno()
raise OSError(errno_, os.strerror(errno_))
return (t.tv_sec * 1e+9) + t.tv_nsec


# Connect to the Vehicle
log.info("Connecting to drone on: %s" % args.connect)
craft = Craft(args.connect)
Expand Down

0 comments on commit b7fc1e3

Please sign in to comment.