Skip to content

Commit 11957ea

Browse files
rtt_rosparam: implement updated() and other PR comments
The patch moves the part of the set( new_value) implementation to updated() such that when using ref_t set() the user can call updated() and make the ROS parameter actually be updated with the new value.
1 parent 54b8516 commit 11957ea

File tree

5 files changed

+25
-107
lines changed

5 files changed

+25
-107
lines changed

rtt_rosparam/CMakeLists.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,14 @@ pkg_search_module(EIGEN3 REQUIRED eigen3)
1010
include_directories(
1111
include
1212
${catkin_INCLUDE_DIRS}
13-
${EIGEN3_INCLUDE_DIRS})
14-
15-
# Add the data source header
16-
orocos_library(ros_param_data_source src/ros_param_data_source.cpp)
17-
target_link_libraries(ros_param_data_source
18-
${catkin_LIBRARIES}
13+
${EIGEN3_INCLUDE_DIRS}
1914
)
2015

21-
# build ROS param as a separate service
16+
# build ROS param as a separate service
2217
orocos_service(rtt_rosparam src/rtt_rosparam_service.cpp)
2318
target_link_libraries(rtt_rosparam
2419
# ${OROCOS-RTT_RTT-MARSHALLING_LIBRARY}
2520
${catkin_LIBRARIES}
26-
ros_param_data_source
2721
)
2822

2923
# Generate install targets and pkg-config files

rtt_rosparam/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ policy (see below).
4242
##### Operations for setting all properties
4343
* `setAll()` or `setAllComponentPrivate()` Stores all properties of this component (and its sub-services)
4444
on the ROS parameter server from the similarly-named property in the **COMPONENT**'s private namespace.
45-
* `setAllRelative()`` Stores all properties of this component (and its sub-services)
45+
* `setAllRelative()` Stores all properties of this component (and its sub-services)
4646
on the ROS parameter server from the similarly-named property in the relative namespace.
4747
* `setAllAbsolute()` Stores all properties of this component (and its sub-services)
4848
on the ROS parameter server from the similarly-named property in the absolute namespace.
@@ -72,13 +72,13 @@ policy (see below).
7272

7373
##### Operations to create properties linked to a ROS param
7474

75-
The following operations of the `rosparam` service can be used to create Properties
75+
The following operations of the `rosparam` service can be used to create properties
7676
in the owner component that link to ROS parameters. When the properties are
7777
`evaluate()`-d through `get()` or `set()`, the ROS parameter server is queried.
7878

7979
**IMPORTANT** Setting or getting the value of a ROS parameter through a
80-
Property is a non real-time safe operation and therefore it shouldn't be used
81-
in the `updateHook()` of a real-time periodic component.
80+
property is a non real-time safe operation and therefore it shouldn't be used
81+
from within a real-time component.
8282

8383
* `addRosParamProperty_type_(name)` Adds a property of type `_type_` with name `name` to the owning task context which is linked to the ROS parameter with the same name in a `Relative` namespace resolution context.
8484
* `addRosParamProperty_type_Relative(name)` Adds a property of type `_type_` with name `name` to the owning task context which is linked to the ROS parameter with the same name in a `Relative` namespace resolution context.

rtt_rosparam/include/rtt_rosparam/ros_param_data_source.hpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "rtt/internal/DataSource.hpp"
3535
#include "rtt/internal/DataSourceTypeInfo.hpp"
3636
#include "rtt/internal/Reference.hpp"
37+
#include "rtt/Logger.hpp"
3738

3839
#include "ros/ros.h"
3940
#include "ros/param.h"
@@ -68,9 +69,7 @@ class RosParamDataSource
6869
mutable typename internal::DataSource<T>::value_t mcached_data_;
6970

7071
public:
71-
/**
72-
* Use shared_ptr.
73-
*/
72+
7473
typedef boost::intrusive_ptr< RosParamDataSource<T> > shared_ptr;
7574

7675
~RosParamDataSource()
@@ -90,12 +89,10 @@ class RosParamDataSource
9089

9190
bool evaluate() const
9291
{
93-
T return_value;
94-
if (!ros::param::getCached(mparam_name_, return_value)) {
95-
throw std::out_of_range("The parameter " + mparam_name_ + " cannot be fetched.");
92+
if (!ros::param::getCached(mparam_name_, mcached_data_)) {
93+
RTT::log(RTT::Error) << "The value of parameter " + mparam_name_ + " could not be fetched." << RTT::endlog();
9694
return false;
9795
}
98-
mcached_data_ = return_value;
9996
return true;
10097
}
10198

@@ -115,15 +112,22 @@ class RosParamDataSource
115112
void set( typename internal::AssignableDataSource<T>::param_t t )
116113
{
117114
set() = t;
118-
ros::param::set(mparam_name_, t);
115+
updated();
119116
}
120117

121-
// There is not referred element, no allocation exists for this data source and it is not an alias.
118+
// There is not referred element, no allocation exists for this data source
119+
// and it is not an alias.
120+
// After working with the reference, if something was assigned, the data
121+
// source may need a call to updated() after set()
122122
typename internal::AssignableDataSource<T>::reference_t set()
123123
{
124124
return mcached_data_;
125125
}
126126

127+
void updated() {
128+
ros::param::set(mparam_name_, mcached_data_);
129+
}
130+
127131
virtual RosParamDataSource<T>* clone() const
128132
{
129133
return new RosParamDataSource<T>(this->mparam_name_);

rtt_rosparam/src/ros_param_data_source.cpp

Lines changed: 0 additions & 80 deletions
This file was deleted.

rtt_rosparam/src/rtt_rosparam_service.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,18 +251,18 @@ class ROSParamService: public RTT::Service
251251
/**
252252
* Adds a ROS parameter of supported types by ROS param as a property to this
253253
* bag.
254-
* A Property is created which causes contents of the
255-
* property always to be in sync
256-
* with the contents of the ROS parameter.
257-
* @param name The name of this property
254+
* The new property mirror the value of the respective ROS parameter of the
255+
* name.
256+
* Setting the value of the property sets the ROS parameter, and evaluating it
257+
* loads the current value from the ROS parameter server.
258+
* @param name The name of the ROS parameter and the property to be added.
258259
* @return the Property object by reference, which you can further query or document.
259260
*/
260261
template<typename T, ResolutionPolicy P>
261262
Property<T>& addRosParamProperty( const std::string& name) {
262263
const std::string resolved_name = resolvedName(name,P);
263264
typename internal::AssignableDataSource<T>::shared_ptr datasource( new rtt_rosparam::RosParamDataSource<T>(resolved_name) );
264-
Property<T>* p = new Property<T>(name,"", datasource);
265-
p->doc("Property generated by rosparam attached to parameter: " + resolved_name);
265+
Property<T>* p = new Property<T>(name, "Property generated by rosparam attached to parameter: " + resolved_name, datasource);
266266
this->getOwner()->properties()->ownProperty( p );
267267
return *p;
268268
}

0 commit comments

Comments
 (0)