Dynamic parameters update from the code (cpp)
Hello, folks!
I am having trouble to update the dynamic parameters from c++ code. My first attempt was to follow hokuyo_node tutorial. So I put this line in my code:
system("rosrun dynamic_reconfigure dynparam set My_node My_param Value &");
The & sign in the end was due to the information I print in my code. Without it the code stops. But when I started to test the code in Gazebo and invoked the command much often, processor load went to around 100% (without the line it worked on 40-50%). Maybe I need to invoke the command in another way?
Another solutions I found regarding my problem:
- dynamic reconfigure: How explicity fetch data from parameter server?
- Bi-directional dynamic_reconfigure
- Notify changes to dynamic_reconfigure
the solution presented in first two links didn't work for me (maybe because of my wrong initialization of dynamic_reconfigure::Server inside the class, I will put my code below). If I initialize dynamic_reconfigure::Server giving my node as an argument, nothing shows up in rqt_reconfigure.
The code from the last "Notify changes ... " was more similar to mine - it also based on classes, so It showed some work ability. But when I started rqt_reconfigure the parameter's values in my node were completely random and didn't change with my inputs.
Here is how my code look like:
main
int main(int argc, char * *argv)
{
ros::init(argc, argv, "flight_controller");
ros::NodeHandle my_node;
static My_class *class = new My_class(my_node);
}
My_class
class My_class
{
private:
ros::NodeHandle node;
dynamic_reconfigure::Server<Config> param_server;
dynamic_reconfigure::Server<Config>::CallbackType call_type;
public:
My_class(ros::NodeHandle &node_)
//,param_server(node) if this line uncomment, rqt_reconfigure doesn't see the node
{
node = node_;
call_type = boost::bind(&My_class::parametersCallback, this, _1, _2);
param_server.setCallback(call_type);
}
}
Thank you in advance for help!
Edit: @ahendrix
So I am not changing the parameters often. But there is one parameter being changed inside the program, but not rqt_reconfigure. I want those parameters to be synchronized.
Lets say I have parameters A=1 and B=2 (I can see it in rqt_reconfigure). Program changes value A=3, rqt_reconfigure continue to display A=1. When I after change through rqt B=4, it changes B=4 and A=1!, since it was the last value displayed in rqt_reconfigure and rqt call_back looks like that:
parametersCallback(prodrone::ProdroneConfig &config, uint32_t level)
{
A = config.a;
B = config.b;
}
I want to change only B, without touching A, so that A has to be updated in rqt as soon as it changes inside the program.
Did you look at this question/answer?
Thank you Thomas! I did try but I'm having the same problem that was mentioned by lucasw (Jul 8 '15) in comments.