Go to the documentation of this file.00001
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00040
00041 #include "sr_tactile_sensor_controller/sr_tactile_sensor_controller.hpp"
00042 #include <pluginlib/class_list_macros.h>
00043 #include <sr_tactile_sensor_controller/sr_pst_tactile_sensor_publisher.hpp>
00044 #include <sr_tactile_sensor_controller/sr_biotac_tactile_sensor_publisher.hpp>
00045 #include <sr_tactile_sensor_controller/sr_ubi_tactile_sensor_publisher.hpp>
00046 #include <string>
00047
00048
00049 namespace controller
00050 {
00051 SrTactileSensorController::SrTactileSensorController()
00052 : initialized_(false), sensors_(NULL)
00053 {}
00054
00055 bool SrTactileSensorController::init(ros_ethercat_model::RobotStateInterface* hw,
00056 ros::NodeHandle &root_nh, ros::NodeHandle& controller_nh)
00057 {
00058 ROS_ASSERT(hw);
00059
00060 ros_ethercat_model::RobotState* robot_state;
00061 std::string robot_state_name;
00062 controller_nh.param<std::string>("robot_state_name", robot_state_name, "unique_robot_hw");
00063
00064 bool use_ns = true;
00065 ros::NodeHandle nh_priv("~");
00066
00067 try
00068 {
00069 robot_state = hw->getHandle(robot_state_name).getState();
00070 }
00071 catch(const hardware_interface::HardwareInterfaceException& e)
00072 {
00073 ROS_ERROR_STREAM("Could not find robot state: " << robot_state_name << " Not loading the controller. " << e.what());
00074 return false;
00075 }
00076
00077 if (!nh_priv.getParam("use_ns", use_ns))
00078 {
00079 ROS_INFO("Private parameter 'use_ns' not set, default is using namespace");
00080 }
00081
00082 if (!controller_nh.getParam("prefix", prefix_))
00083 {
00084 ROS_ERROR("Parameter 'prefix' not set");
00085 return false;
00086 }
00087
00088
00089 if (!prefix_.empty())
00090 {
00091 if (use_ns)
00092 nh_prefix_ = ros::NodeHandle(root_nh, prefix_);
00093 else
00094 nh_prefix_ = ros::NodeHandle(root_nh);
00095
00096 prefix_+="_";
00097 }
00098 else
00099 {
00100 nh_prefix_ = ros::NodeHandle(root_nh);
00101 }
00102
00103
00104
00105 sr_actuator::SrMotorActuator* motor_actuator = static_cast<sr_actuator::SrMotorActuator*>(
00106 robot_state->getActuator(prefix_+"FFJ0"));
00107 if (motor_actuator)
00108 {
00109 sensors_ = motor_actuator->motor_state_.tactiles_;
00110
00111
00112 if (!controller_nh.getParam("publish_rate", publish_rate_))
00113 {
00114 ROS_ERROR("Parameter 'publish_rate' not set");
00115 return false;
00116 }
00117
00118 return true;
00119 }
00120 else
00121 {
00122 ROS_ERROR_STREAM("Could not find the " << prefix_ << "FFJ0 actuator");
00123 return false;
00124 }
00125 }
00126
00127 void SrTactileSensorController::update(const ros::Time& time, const ros::Duration& period)
00128 {
00129 if (!initialized_)
00130 {
00131 if (sensors_)
00132 {
00133 if (!sensors_->empty())
00134 {
00135 if (!sensors_->at(0).type.empty())
00136 {
00137 if (sensors_->at(0).type == "pst")
00138 {
00139 sensor_publisher_.reset(new SrPSTTactileSensorPublisher(sensors_, publish_rate_, nh_prefix_, prefix_));
00140 }
00141 else if (sensors_->at(0).type == "biotac")
00142 {
00143 sensor_publisher_.reset(new SrBiotacTactileSensorPublisher(sensors_, publish_rate_, nh_prefix_, prefix_));
00144 }
00145 else if (sensors_->at(0).type == "ubi")
00146 {
00147 sensor_publisher_.reset(new SrUbiTactileSensorPublisher(sensors_, publish_rate_, nh_prefix_, prefix_));
00148 }
00149 else
00150 {
00151 ROS_FATAL_STREAM("Unknown tactile sensor type: " << sensors_->at(0).type);
00152 }
00153
00154
00155 sensor_publisher_->init(time);
00156 initialized_ = true;
00157 }
00158 }
00159 }
00160 }
00161 else
00162 {
00163 sensor_publisher_->update(time, period);
00164 }
00165 }
00166
00167 void SrTactileSensorController::starting(const ros::Time& time)
00168 {
00169 }
00170
00171 void SrTactileSensorController::stopping(const ros::Time& time)
00172 {
00173
00174 initialized_ = false;
00175 }
00176 }
00177
00178
00179 PLUGINLIB_EXPORT_CLASS(controller::SrTactileSensorController, controller_interface::ControllerBase)
00180
00181
00182
00183
00184
00185