Skip to content
Snippets Groups Projects
Select Git revision
  • 09ca847ad575c1f5f9e717ed46f6df16ad35da47
  • master default protected
  • noetic/main
  • feature/chem-feature-integration
  • feature/tests
5 results

grasp_util.h

Blame
  • base-model.ts 2.23 KiB
       
    export interface PositionUpdate {
        objects: Agent[]
        type: NotificationType
    }
    
    export interface Agent {
        id: string
        sensorId: string
        type: ObjectType
        sensorType: SensorType
        position: Position
        orientation?: Quaternion
        lastPosUpdate: string
        zoneDescriptors: ZoneDesc[]
        extractedAttributes?: ExtAttribute
    }
    
    export interface Position {
        refSystemId: string
        point: WGS84 | RelativePos
        accuracy?: number
    }
    
    export interface WGS84 {
        latitude: number
        longitude: number
        altitude?: number
    }
    
    export interface RelativePos {
        x: number
        y: number
        z?: number
    }
    
    export interface ZoneDesc {
        zoneId: string
        notificationType: NotificationType
    }
    
    export interface Quaternion {
        x: number
        y: number
        z: number
        w: number
    }
    
    export enum NotificationType {
        "EntryNotification",
        "ExitNotification", 
        "Unknown"
    }
    
    enum ObjectType {
        "HUMAN",
        "BOX",
        "ROBOT"
    }
    
    enum SensorType {
        "UWB",
        "Bluetooth",
        "WiFi"
    }
    interface ExtAttribute {
        batteryChargeLevel: number
        loadedItems: number[]
        errors: number[]
        theta: number
    } 
    
    
    export function validateTypePosition(obj: any) {
        if (!isPosition(obj)) {
            throw new TypeError("Unvalid Position")  
        }
    }
      
    export function validateTypeAgent(obj: any) {
        if (!isAgent(obj)) {
            throw new TypeError("Unvalid Agent: " + Object.keys(obj))  
        }
    }
    
    
    // --- Type Guards
    
    function isWGS84(obj: any): obj is WGS84 {
        return Object.prototype.hasOwnProperty.call(obj, "latitude")
            && Object.prototype.hasOwnProperty.call(obj, "longitude")
    } 
    
    function isRelativePos(obj: any): obj is RelativePos {
        return Object.prototype.hasOwnProperty.call(obj, "x")
            && Object.prototype.hasOwnProperty.call(obj, "y")
    } 
    
    export function isPosition(obj: any): obj is Position {
        return isWGS84(obj.point) || isRelativePos(obj.point)
        && Object.prototype.hasOwnProperty.call(obj, "refSystemId")
    } 
    
    export function isAgent(obj: any): obj is Agent {
        return "id" in obj
            && "type" in obj
            && "sensorId" in obj
            && "sensorType" in obj
            && "position" in obj
            && isPosition(obj.position)
            && "lastPosUpdate" in obj
            && "zoneDescriptors" in obj
    }