orocos / rtt_ros_integration

Orocos-ROS integration libraries and tools
BSD 3-Clause "New" or "Revised" License
85 stars 56 forks source link

rtt_dynamic_reconfigure example? #160

Open dustingooding opened 4 years ago

dustingooding commented 4 years ago

Is there a "hello world" level example of how to actually use rtt_dynamic_reconfigure?

Specifically, I'm trying to call advertise from within my component's configureHook and I'm struggling at getting the proper type.

This is as close as I've gotten:

# outside of the component
deployer.loadService("my_component", "my_pkg_reconfigure");

# inside my_component
boost::shared_ptr<rtt_dynamic_reconfigure::Server<my_namespace::MyPkgConfig>> reconfigure =
        this->getProvider<rtt_dynamic_reconfigure::Server<my_namespace::MyPkgConfig>>("reconfigure");
if (reconfigure)
{
    reconfigure->advertise();
}

But I get this error:

In file included from /opt/orocos/melodic/include/rtt/RTT.hpp:53:0,
                 from /root/my_ws/src/my_pkg/include/my_pkg/my_component.hpp:20,
                 from /root/my_ws/src/my_pkg/src/my_component.cpp:8:
/opt/orocos/melodic/include/rtt/TaskContext.hpp: In instantiation of ‘boost::shared_ptr<X> RTT::TaskContext::getProvider(const string&) [with ServiceType = rtt_dynamic_reconfigure::Server<my_namespace::MyPkgConfig>; std::__cxx11::string = std::__cxx11::basic_string<char>]’:
/root/my_ws/src/my_pkg/src/my_component.cpp:115:111:   required from here
/opt/orocos/melodic/include/rtt/TaskContext.hpp:306:17: error: ‘class rtt_dynamic_reconfigure::Server<my_namespace::MyPkgConfig>’ has no member named ‘connectTo’
             st->connectTo( provides(name) );

I've also tried with rtt_dynamic_reconfigure::Server<rtt_dynamic_reconfigure::AutoConfig> to no avail. Same error.

Can I get some help?

dustingooding commented 4 years ago

Turns out I was holding it wrong...

I was doing the right thing outside of the component. But this is what should be happening inside.

    RTT::Service::shared_ptr reconfigure = this->provides("my_pkg_reconfigure");

    if (reconfigure)
    {
        if (reconfigure->hasOperation("advertise"))
        {
            RTT::OperationCaller<void(std::string)> op_advertise = reconfigure->getOperation("advertise");

            op_advertise("~");
        }
    }

I guess this ticket is more about "can some form of this snippet be added to the README".