Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00025 #include "sr_ronex_controllers/fake_calibration_controller.hpp"
00026 #include "pluginlib/class_list_macros.h"
00027
00028 PLUGINLIB_EXPORT_CLASS( ronex::FakeCalibrationController, controller_interface::ControllerBase)
00029
00030 namespace ronex
00031 {
00032 FakeCalibrationController::FakeCalibrationController()
00033 : robot_(NULL), last_publish_time_(0), state_(INITIALIZED),
00034 joint_(NULL)
00035 {
00036 }
00037
00038 bool FakeCalibrationController::init(ros_ethercat_model::RobotState* robot, ros::NodeHandle &n)
00039 {
00040 robot_ = robot;
00041 node_ = n;
00042
00043
00044 std::string joint_name;
00045 if (!node_.getParam("joint", joint_name))
00046 {
00047 ROS_ERROR("No joint given (namespace: %s)", node_.getNamespace().c_str());
00048 return false;
00049 }
00050 if (!(joint_ = robot->getJointState(joint_name)))
00051 {
00052 ROS_ERROR("Could not find joint %s (namespace: %s)",
00053 joint_name.c_str(), node_.getNamespace().c_str());
00054 return false;
00055 }
00056 joint_name_ = joint_name;
00057
00058
00059 pub_calibrated_.reset(
00060 new realtime_tools::RealtimePublisher<std_msgs::Bool>(node_, "/calibrated", 1));
00061
00062 return true;
00063 }
00064
00068 void FakeCalibrationController::update(const ros::Time&, const ros::Duration&)
00069 {
00070 assert(joint_);
00071
00072 switch(state_)
00073 {
00074 case INITIALIZED:
00075 state_ = BEGINNING;
00076 break;
00077 case BEGINNING:
00078 joint_->calibrated_ = true;
00079 calib_msg_.data = true;
00080 state_ = CALIBRATED;
00081
00082 last_publish_time_ = robot_->getTime();
00083 break;
00084 case CALIBRATED:
00085 if (pub_calibrated_)
00086 {
00087 if (last_publish_time_ + ros::Duration(0.5) < robot_->getTime())
00088 {
00089 assert(pub_calibrated_);
00090 if (pub_calibrated_->trylock())
00091 {
00092 last_publish_time_ = robot_->getTime();
00093 pub_calibrated_->msg_ = calib_msg_;
00094 pub_calibrated_->unlockAndPublish();
00095 }
00096 }
00097 }
00098 break;
00099 }
00100 }
00101 }
00102
00103
00104
00105
00106
00107