コード例 #1
0
class FlyARData(object):
    def __init__(self):
        self._haveSharedMemKeys = False
        self._rollMem = None
        self._roll = 0
        self._pitchMem = None
        self._pitch = 0
        self._yawMem = None
        self._yaw = 0

    def update(self):
        '''
        Updates the object with the latest from shared memory. Then call the 
        respective properties to get updated values
        '''
        if not self._haveSharedMemKeys:
            # Get the shared memory keys from the file
            with open('/var/tmpflyar/raw_shared_memory_keys.flyar', 'r') as f:
                for line in f:
                    self._haveSharedMemKeys = True
                    values = line.strip().split(',')
                    self._rollMem = SharedMemory(int(values[0]))
                    self._pitchMem = SharedMemory(int(values[1]))
                    self._yawMem = SharedMemory(int(values[2]))

        # Get the latest data from shared memory
        self._roll = float(self._rollMem.read())
        self._pitch = float(self._pitchMem.read())
        self._yaw = float(self._yawMem.read())

    @property
    def roll(self):
        return self._roll

    @roll.setter
    def roll(self, value):
        self._roll = value

    @property
    def pitch(self):
        return self._pitch

    @pitch.setter
    def pitch(self, value):
        self._pitch = value

    @property
    def yaw(self):
        return self._yaw

    @yaw.setter
    def yaw(self, value):
        self._yaw = value
コード例 #2
0
def zpixmap_shm_to_image(shm: sysv_ipc.SharedMemory, size: int, width: int,
                         height: int) -> np.ndarray:
    out = np.frombuffer(shm.read(size), "<B").copy()
    out.shape = (height, width, 4)
    out[:, :, 3] = 0xFF  # Convert BGRX to BGRA

    return out
コード例 #3
0
class Bitmap():

    def __init__(self):
        self.shm = SharedMemory(None, flags = IPC_EXCL|IPC_CREAT, 
                mode= 0o600, size = bitmap_size, init_character = b'\x00')
        # to show we are alive
        self.shm.write('\x01')
        # print(self.bytes())
        # self.shm.attach()
    
    def get_key(self):
        return self.shm.key 
    
    def get_id(self):
        return self.shm.id
    
    def get_size(self):
        return bitmap_size

    def bytes(self):
        buffer = self.shm.read(bitmap_size)
        n = 0
        for i in range(bitmap_size):
            if buffer[i] != 0:
                n += 1
        return n

    def has_new_bits(self):
        ret = 0
        buffer = self.shm.read(bitmap_size)
        for i in range(bitmap_size):
            if buffer[i] and buffer[i] & virgin_bits[i]:
                virgin_bits[i] &= ~buffer[i]
                if virgin_bits[i] == 0xff:
                    ret = 2
                elif ret < 1:
                    ret = 1
        return ret

    def release(self):
        self.shm.remove()
コード例 #4
0
    def run(self):
        time.sleep(3)

        shared_mem = SharedMemory(6789,
                                  flags=sysv_ipc.IPC_CREAT,
                                  size=sysv_ipc.PAGE_SIZE,
                                  init_character='\0')

        try:
            while self.work:
                for i in range(
                        len(stations)
                ):  # convert position to integer then string and fill with 4 zero to align values
                    shared_mem.write(
                        ' '.join(
                            str(pos).split(".")[0].zfill(4)
                            for pos in stations[i].params["position"]) + ' ',
                        i * 15)
            else:
                print(shared_mem.read(45))
                shared_mem.remove()
        except:
            shared_mem.remove()
コード例 #5
0
ファイル: positionreader.py プロジェクト: shihyu/FlyAR
from sysv_ipc import SharedMemory
from os import system

roll = None
pitch = None
yaw = None
with open('/var/tmpflyar/raw_shared_memory_keys.flyar', 'r') as f:
    for line in f:
        values = line.strip().split(',')
        roll = SharedMemory(int(values[2]))
        pitch = SharedMemory(int(values[1]))
        yaw = SharedMemory(int(values[0]))

print("Roll:       {}".format(roll.read().strip()))
print("Pitch:      {}".format(pitch.read().strip()))
print("Yaw:        {}".format(yaw.read().strip()))
コード例 #6
0
ファイル: datacalculator.py プロジェクト: shihyu/FlyAR
zPosition = 0
calibrationNumber = 0
NUMBER_OF_CALIBRATION_POINTS = 5000
CALIBRATED_ACCEL_X = 0
CALIBRATED_ACCEL_Y = 0
CALIBRATED_ACCEL_Z = 0

previousRollRad = 0
previousRollDeg = 0
previousPitchRad = 0
previousPitchDeg = 0
previousYawRad = 0
previousYawDeg = 0
while True:
    # Get the latest data from shared memory
    xAccel = float(xAccelMem.read())
    yAccel = float(yAccelMem.read())
    zAccel = float(zAccelMem.read())
    rollRad = float(rollMem.read())
    pitchRad = float(pitchMem.read())
    yawRad = float(yawMem.read())
    rollDeg = float(rollDegMemFrom.read())
    pitchDeg = float(pitchDegMemFrom.read())
    yawDeg = float(yawDegMemFrom.read())

    # If we haven't exceeded the calibration period, keep a running average to use
    if calibrationNumber < NUMBER_OF_CALIBRATION_POINTS:
        calibrationNumber += 1

        CALIBRATED_ACCEL_X = (CALIBRATED_ACCEL_X + xAccel) / calibrationNumber
        CALIBRATED_ACCEL_Y = (CALIBRATED_ACCEL_Y + yAccel) / calibrationNumber
コード例 #7
0
#!usr/bin/env python
# encoding: utf-8
# Archivo de lectura de la memoria compartida.

from sysv_ipc import SharedMemory
from numpy import frombuffer, float32
from subprocess import call

shm_key = 0x1234;

# Vinvculamos la memoria compartida a una instancia.
mem = SharedMemory(shm_key)

# Leemos la memoria compartida.
memory_value = mem.read()

# Convertimos la lectura de bytes a numpy array.
y = frombuffer(memory_value, dtype=float32)
print(y)

# Desvinculamos la instancia.
mem.detach()

# Removemos la memoria.
mem.remove()