class NRPGazeboCommunicationController

Overview

Manages communication with the NRP. More…

#include <nrp_communication_controller.h>

class NRPGazeboCommunicationController: public EngineProtoWrapper {
public:
    // typedefs

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

    // construction

    NRPGazeboCommunicationController(
        const std::string& engineName,
        const std::string& protobufPluginsPath,
        const nlohmann::json& protobufPlugins
    );

    // methods

    void registerDataPackWithLock(
        const std::string& datapackName,
        ProtoDataPackController* interface
    );

    void registerStepController(GazeboStepController* stepController);
    void registerSensorPlugin(gazebo::SensorPlugin* sensorPlugin);
    void registerModelPlugin(gazebo::ModelPlugin* modelPlugin);
    virtual SimulationTime runLoopStep(SimulationTime timeStep);
    virtual void initialize(const nlohmann::json& data);
    virtual void reset();
    virtual void shutdown();
    virtual bool initRunFlag() const;
    virtual bool shutdownFlag() const;

    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<EngineProtoWrapper::mutex_t> lock_t;

    // methods

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

    unsigned getNumRegisteredDataPacks();
    std::vector<std::string> getNamesRegisteredDataPacks();
    const std::string& getEngineName();
    virtual bool initRunFlag() const = 0;
    virtual bool shutdownFlag() const = 0;
    virtual void initialize(const nlohmann::json& data) = 0;
    virtual void reset() = 0;
    virtual void shutdown() = 0;
    virtual SimulationTime runLoopStep(const SimulationTime timeStep) = 0;
    void setDataPacks(const EngineGrpc::SetDataPacksRequest& data);
    void setDataPack(const EngineGrpc::DataPackMessage& dataPack);
    std::unique_ptr<gpb::Message> unpackFromAny(const gpb::Any& data);

    virtual void getDataPacks(
        const EngineGrpc::GetDataPacksRequest& request,
        EngineGrpc::GetDataPacksReply* reply
    );

    bool getDataPack(const std::string& name, EngineGrpc::DataPackMessage* dpMsg);

    void setDataPackMessageData(
        gpb::Message* data,
        EngineGrpc::DataPackMessage* dpMsg
    );

Detailed Documentation

Manages communication with the NRP.

Implementation of EngineProtoWrapper to manage a Gazebo Engine

Methods

void registerDataPackWithLock(
    const std::string& datapackName,
    ProtoDataPackController* interface
)

Registers a datapack controller locking the datapack mutex.

Parameters:

datapackName

Name of the datapack to be registered

datapackController

Pointer to the datapack controller object that’s supposed to be registered in the engine

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

virtual SimulationTime runLoopStep(SimulationTime timeStep)

Runs a single simulation loop step.

Parameters:

timeStep

Time step by which the simulation should be advanced

Returns:

Engine time after running the step

virtual void initialize(const nlohmann::json& data)

Initializes the simulation.

Parameters:

data

Simulation configuration data

datapackLock

???

virtual void reset()

Resets the simulation.

virtual void shutdown()

Shutdowns the simulation.

virtual bool initRunFlag() const

Indicates if the simulation was initialized and is running.

virtual bool shutdownFlag() const

Indicates if shutdown was requested by the client.

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

Create datapack name from the given plugin 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