00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00036
00037 #include <cstdio>
00038 #include <ros/ros.h>
00039 #include <joint_states_settler/joint_states_settler.h>
00040
00041 using namespace joint_states_settler;
00042
00048 joint_states_settler::ConfigGoal getParamConfig(ros::NodeHandle& n)
00049 {
00050 joint_states_settler::ConfigGoal config;
00051 config.joint_names.clear() ;
00052 bool found_joint = true ;
00053 int joint_count = 0 ;
00054
00055 char param_buf[1024] ;
00056 while(found_joint)
00057 {
00058 sprintf(param_buf, "~joint_name_%02u", joint_count) ;
00059 std::string param_name = param_buf ;
00060 std::string cur_joint_name ;
00061 found_joint = n.getParam(param_name, cur_joint_name) ;
00062 if (found_joint)
00063 {
00064 ROS_INFO("[%s] -> %s", param_name.c_str(), cur_joint_name.c_str()) ;
00065 config.joint_names.push_back(cur_joint_name) ;
00066
00067
00068 sprintf(param_buf, "~joint_tol_%02u", joint_count) ;
00069 double cur_tol;
00070 bool found_tol;
00071 found_tol = n.getParam(std::string(param_buf), cur_tol) ;
00072 if (!found_tol)
00073 ROS_FATAL("Could not find parameter [%s]", param_buf);
00074 ROS_INFO("[%s] -> %.3f", param_buf, cur_tol) ;
00075 config.tolerances.push_back(cur_tol);
00076 }
00077 else
00078 ROS_DEBUG("Did not find param [%s]", param_name.c_str()) ;
00079
00080 joint_count++ ;
00081 }
00082
00083 double max_step;
00084 n.param("~max_step", max_step, 1000.0);
00085 config.max_step = ros::Duration(max_step);
00086 ROS_INFO("max step: [%.3fs]", config.max_step.toSec());
00087
00088 int cache_size;
00089 n.param("~cache_size", cache_size, 1000);
00090 if (cache_size < 0)
00091 ROS_FATAL("cache_size < 0. (cache_size==%i)", cache_size);
00092 config.cache_size = (unsigned int) cache_size;
00093 ROS_INFO("cache_size: [%u]", config.cache_size);
00094
00095 return config;
00096 }
00097
00098 void jointStatesCallback(ros::Publisher* pub, JointStatesSettler* settler, const sensor_msgs::JointStateConstPtr& msg)
00099 {
00100 pub->publish(settler->add(msg));
00101 }
00102
00103 int main(int argc, char** argv)
00104 {
00105 ros::init(argc, argv, "joint_states_settler");
00106
00107 ros::NodeHandle n;
00108
00109
00110 joint_states_settler::ConfigGoal config = getParamConfig(n);
00111 JointStatesSettler settler;
00112 settler.configure(config);
00113
00114
00115 ros::Publisher pub = n.advertise<calibration_msgs::Interval>("settled", 1);
00116
00117
00118
00119 boost::function<void (const sensor_msgs::JointStateConstPtr&)> cb = boost::bind(&jointStatesCallback, &pub, &settler, _1);
00120 ros::Subscriber sub = n.subscribe(std::string("joint_states"), 1, cb);
00121
00122 ros::spin();
00123 }