Skip to content
This repository has been archived by the owner on May 3, 2021. It is now read-only.

ControllerManager Programmer Notes

Guido Sanchez edited this page Apr 29, 2017 · 1 revision

Controller Manager

ControllerManager
    Members
        std::deque<eCommonTrackingColorID> m_available_controller_color_ids;
        std::string m_bluetooth_host_address;
        
    Functions
        /// Call hid_init()
        bool startup() override;
       
        void updateStateAndPredict(TrackerManager* tracker_manager);
        void publish() override;
        void setControllerRumble(int controller_id, float rumble_amount, CommonControllerState::RumbleChannel channel);

        eCommonTrackingColorID allocateTrackingColorID();
        void claimTrackingColorID(const ServerControllerView *controller_view, eCommonTrackingColorID color_id);
        void freeTrackingColorID(eCommonTrackingColorID color_id);

ServerControllerView
    Functions
        bool open(const class DeviceEnumerator *enumerator) override;
        void close() override;
        // Tell the pose filter that the controller is aligned with global forward 
        // with the given pose relative to it's identity pose.
        // Recenter the pose filter state accordingly.
        bool recenterOrientation(const CommonDeviceQuaternion& q_pose_relative_to_identity_pose);
        // Recreate and initialize the pose filter for the controller
        void resetPoseFilter();
        // Compute pose/prediction of tracking blob+IMU state
        void updateOpticalPoseEstimation(TrackerManager* tracker_manager);
        void updateStateAndPredict();
        // Registers the address of the bluetooth adapter on the host PC with the controller
        bool setHostBluetoothAddress(const std::string &address);        
        IDeviceInterface* getDevice() const override {return m_device;}
        inline class IPoseFilter * getPoseFilterMutable() { return m_pose_filter; }
        inline const class IPoseFilter * getPoseFilter() const { return m_pose_filter; }
        // Estimate the given pose if the controller at some point into the future
        CommonDevicePose getFilteredPose(float time= 0.f) const;
        // Get the current physics from the filter position and orientation
        CommonDevicePhysics getFilteredPhysics() const;
        // Returns true if the device is connected via Bluetooth, false if by USB
        bool getIsBluetooth() const;
        // Returns true if the device can stream controller data over it's current connection type (Bluetooth/USB)
        bool getIsStreamable() const;
        // Returns the full usb device path for the controller
        std::string getUSBDevicePath() const;
        // Returns the vendor ID of the controller
        int getVendorID() const;
        // Returns the product ID of the controller
        int getProductID() const;
        // Returns the serial number for the controller
        std::string getSerial() const;
        // Gets the host bluetooth address registered with the 
        std::string getAssignedHostBluetoothAddress() const;
        // Returns what type of controller this controller view represents
        CommonDeviceState::eDeviceType getControllerDeviceType() const;
        // Fetch the controller state at the given sample index.
        // A lookBack of 0 corresponds to the most recent data.
        const CommonControllerState * getState(int lookBack = 0) const;
        // Returns true if the system button was pressed this frame on this controller
        bool getWasSystemButtonPressed() const;
        // Sets the bulb LED color to some new override color
        // If tracking was active this likely will affect controller tracking
        void setLEDOverride(unsigned char r, unsigned char g, unsigned char b);
        // Removes the over led color and restores the tracking color
        // of the controller is currently being tracked
        void clearLEDOverride();
        // Returns true 
        inline bool getIsLEDOverrideActive() const { return m_LED_override_active; }
        // Get the currently assigned tracking color ID for the controller
        eCommonTrackingColorID getTrackingColorID() const;
        // Set the assigned tracking color ID for the controller
        void setTrackingColorID(eCommonTrackingColorID colorID);
        // Get the tracking is enabled on this controller
        inline bool getIsTrackingEnabled() const { return m_tracking_enabled && m_multicam_pose_estimation != nullptr; }
        // Increment the position tracking listener count
        // Starts position tracking this controller if the count was zero
        void startTracking();
        // Decrements the position tracking listener count
        // Stop tracking this controller if this count becomes zero
        void stopTracking();
        // Get the tracking shape for the controller
        bool getTrackingShape(CommonDeviceTrackingShape &outTrackingShape) const;
        // Get the prediction time used for ROI tracking
        float getROIPredictionTime() const;
        // Get the pose estimate relative to the given tracker id
        inline const ControllerOpticalPoseEstimation *getTrackerPoseEstimate(int trackerId) const {
        // Get the pose estimate derived from multicam pose tracking
        inline const ControllerOpticalPoseEstimation *getMulticamPoseEstimate() const { 
        // return true if one or more cameras saw this controller last update
        inline bool getIsCurrentlyTracking() const
        // Set the rumble value between 0.f-1.f on a channel
        bool setControllerRumble(float rumble_amount, CommonControllerState::RumbleChannel channel);
        
    Members
        // Tracking color state
        std::tuple<unsigned char, unsigned char, unsigned char> m_tracking_color;
        int m_tracking_listener_count;
        bool m_tracking_enabled;
        
        // Region-of-Interest state
        int m_roi_disable_count;
        
        // Override color state
        std::tuple<unsigned char, unsigned char, unsigned char> m_LED_override_color;
        bool m_LED_override_active;

        // Device state
        IControllerInterface *m_device;
        
        // Filter state
        ControllerOpticalPoseEstimation *m_tracker_pose_estimations; // array of size TrackerManager::k_max_devices
        ControllerOpticalPoseEstimation *m_multicam_pose_estimation;
        class IPoseFilter *m_pose_filter;
        class PoseFilterSpace *m_pose_filter_space;
        int m_lastPollSeqNumProcessed;
        std::chrono::time_point<std::chrono::high_resolution_clock> m_last_filter_update_timestamp;
        bool m_last_filter_update_timestamp_valid;

IControllerInterface

PSNaviController
PSMoveController
PSDualShock4Controller

Pose Filter Programmer Notes