Created
August 20, 2013 07:44
-
-
Save chadrockey/6278266 to your computer and use it in GitHub Desktop.
Dynamic Reconfigure Timed Latch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cfg: | |
#! /usr/bin/env python | |
from dynamic_reconfigure.parameter_generator_catkin import * | |
PACKAGE='my_package' | |
gen = ParameterGenerator() | |
gen.add("a", double_t, 0, "A", -100, 0, 100) | |
gen.add("b", double_t, 0, "B", -100, 0, 100) | |
gen.add("add_a_and_b", bool_t, 2, "Triggers the latched add.", False) | |
gen.add("c", double_t, 0, "Sum of A and B", -200, 0, 200) | |
exit(gen.generate(PACKAGE, "my_package", "Sum")) | |
------------------- | |
------------------ | |
------------------ | |
C++: | |
#include <ros/ros.h> | |
#include <dynamic_reconfigure/server.h> | |
#include <my_package/SumConfig.h> | |
void callback(my_package::SumConfig& config, uint32_t level) | |
{ | |
if(config.add_a_and_b){ | |
ROS_INFO("Adding numbers"); | |
config.c = config.a + config.b; | |
config.a = 0; | |
config.b = 0; | |
ros::Duration(0.5).sleep(); // Sleep for 0.5 second so that user gets proper feedback from GUI | |
// Always set the "apply buttons" back to false | |
config.add_a_and_b = false; | |
return; | |
} | |
} | |
int main(int argc, char **argv) | |
{ | |
ros::init(argc, argv, "sum_test"); | |
ros::NodeHandle n; | |
ros::NodeHandle pnh("~"); | |
// Setup dynamic reconfigure | |
dynamic_reconfigure::Server<my_package::SumConfig> srv; | |
dynamic_reconfigure::Server<my_package::SumConfig>::CallbackType f; | |
f = boost::bind(&callback, _1, _2); | |
srv.setCallback(f); | |
ros::spin(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment