Skip to content

Conversation

@artivis
Copy link
Collaborator

@artivis artivis commented Oct 29, 2017

This pull request adds an abstract base to generated parameter classes enabling their use through a parameter base pointer.

Please consider the following example :

struct DummyBase
{
  DummyBase() = default;
  virtual ~DummyBase() = default;

  // A helper function to instantiate the params_ptr_
  template <typename T>
  void init()
  {
    params_ptr_ = boost::make_shared<T>(ros::NodeHandle("~"));
  }

  void fromParamServer()
  {
    params_ptr_->fromParamServer();
  }

  void toParamServer()
  {
    params_ptr_->toParamServer();
  }

  // Pointer to the xParameters object
  rosparam_handler::ParametersPtr params_ptr_;
};

struct Foo : public DummyBase
{
    Foo()
    {
       // Instantiate the params_ptr_ as a FooParameters object
       init<FooParameters>();

       params_ptr_->fromParamServer();
    }

    void doThingsWithParams()
    {
       auto foo_param_ptr = boost::dynamic_pointer_cast<FooParameters>(params_ptr_);

       // Assuming FooParameters has an int parameter called my_int_param
       foo_param_ptr->my_int_param = 42;

       params_ptr_->toParamServer();
    }
};

struct Bar : public DummyBase
{
  Bar()
  {
     // Instantiate the params_ptr_ as a BarParameters object
     init<BarParameters>();

     params_ptr_->fromParamServer();

     dynamic_reconfigure::Server<BarConfig>::CallbackType cb;
     cb = boost::bind(&Bar::configCallback, this, _1, _2);
     dr_srv_.setCallback(cb);
  }

  void configCallback(BarConfig &config, uint32_t level)
  {
     params_ptr_->fromConfig(config);
  }

  dynamic_reconfigure::Server<BarConfig> dr_srv_;
};

This PR does not change the default behavior while allowing one to use a unique rosparam_handler::ParameterPtr in a base class and instantiate it to a different parameter type. All functions remain available through the base pointer.

The main drawback here is that to access the actual members of the instantiated object one has to cast the pointer to the appropriate type (either statically or dynamically). We could assume that if someone uses this scheme is surely knows what he is doing.

All former tests are passing and a I added one for this new scheme.
Their is also a test-case demonstrating how to test dynamic_reconfigure callback with rosparam_handler.

Please consider this PR as Work In Progress until I add some documentation and a test for dynamic_reconfigure with a plain parameter object (not passing by a base pointer).

Looking forward to feedback .

@artivis
Copy link
Collaborator Author

artivis commented Oct 29, 2017

Travis complains about permission...
rosparam_handler/test/cfg/Foo.params: Permission denied

@artivis
Copy link
Collaborator Author

artivis commented Nov 2, 2017

Added doc & tutorial (cbandera/rosparam_handler_tutorial#3), fixed some warnings. ParameterPtr is now declared in a separate header for cheaper include cost.

@artivis
Copy link
Collaborator Author

artivis commented Jan 10, 2018

Closing in favor of #37

@artivis artivis closed this Jan 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant