class NRPJSONCommunicationController

Overview

Manages communication with the NRP. Uses a REST server to send/receive data. Singleton class. More…

#include <nrp_communication_controller.h>

class NRPJSONCommunicationController: public EngineJSONServer {
public:
    // construction

    NRPJSONCommunicationController(const NRPJSONCommunicationController& other);
    NRPJSONCommunicationController(NRPJSONCommunicationController&& other);

    // methods

    NRPJSONCommunicationController& operator = (const NRPJSONCommunicationController& other);
    NRPJSONCommunicationController&& operator = (NRPJSONCommunicationController&& other);
    void registerStepController(GazeboStepController* stepController);
    void registerSensorPlugin(gazebo::SensorPlugin* sensorPlugin);
    void registerModelPlugin(gazebo::ModelPlugin* modelPlugin);
    static NRPJSONCommunicationController& getInstance();

    static NRPJSONCommunicationController& resetInstance(
        const std::string& serverURL,
        const std::string& engineName,
        const std::string& registrationURL
    );

    static std::string createDataPackName(
        const std::string& modelName,
        const std::string& objectName
    );
};

Inherited Members

public:
    // typedefs

    typedef std::timed_mutex mutex_t;
    typedef std::unique_lock<EngineJSONServer::mutex_t> lock_t;

    // methods

    EngineJSONServer& operator = (const EngineJSONServer&);
    bool isServerRunning() const;
    void startServerAsync();
    void startServer();
    void shutdownServer();
    uint16_t serverPort() const;
    std::string serverAddress() const;

    void registerDataPack(
        const std::string& datapackName,
        JsonDataPackController* interface
    );

    void registerDataPackNoLock(
        const std::string& datapackName,
        JsonDataPackController* interface
    );

    virtual SimulationTime runLoopStep(SimulationTime timeStep) = 0;

    virtual nlohmann::json initialize(
        const nlohmann::json& data,
        EngineJSONServer::lock_t& datapackLock
    ) = 0;

    virtual nlohmann::json reset(EngineJSONServer::lock_t& datapackLock) = 0;
    virtual nlohmann::json shutdown(const nlohmann::json& data) = 0;
    bool shutdownFlag();

Detailed Documentation

Manages communication with the NRP. Uses a REST server to send/receive data. Singleton class.

Construction

NRPJSONCommunicationController(const NRPJSONCommunicationController& other)

Delete for singleton.

NRPJSONCommunicationController(NRPJSONCommunicationController&& other)

Delete for singleton.

Methods

NRPJSONCommunicationController& operator = (const NRPJSONCommunicationController& other)

Delete for singleton.

NRPJSONCommunicationController&& operator = (NRPJSONCommunicationController&& other)

Delete for singleton.

void registerStepController(GazeboStepController* stepController)

Register a step controller.

Parameters:

stepController

Pointer to step controller

void registerSensorPlugin(gazebo::SensorPlugin* sensorPlugin)

Register a sensor plugin.

Parameters:

sensorPlugin

Pointer to sensor plugin

void registerModelPlugin(gazebo::ModelPlugin* modelPlugin)

Register a model plugin.

Parameters:

sensorPlugin

Pointer to model plugin

static NRPJSONCommunicationController& getInstance()

Get singleton instance.

Returns:

Gets instance of NRPJSONCommunicationController

static NRPJSONCommunicationController& resetInstance(
    const std::string& serverURL,
    const std::string& engineName,
    const std::string& registrationURL
)

Reset server with the given server URL.

Parameters:

serverURL

URL used by server

engineName

Name of this engine

registrationURL

URL used to register this engine server’s URL

Returns:

Returns reference to server instance

static std::string createDataPackName(
    const std::string& modelName,
    const std::string& objectName
)

Create datapack name from the given model and sensor/joint/link.

Parameters:

modelName

Name of the parent model of the controlled object

objectName

Name of the controlled object (sensor, joint, link, …)

Returns:

Returns datapack name