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/general_io_passthrough_controller.hpp"
00026 #include "pluginlib/class_list_macros.h"
00027
00028 PLUGINLIB_EXPORT_CLASS( ronex::GeneralIOPassthroughController, controller_interface::ControllerBase)
00029
00030 namespace ronex
00031 {
00032 GeneralIOPassthroughController::GeneralIOPassthroughController()
00033 : loop_count_(0)
00034 {}
00035
00036 bool GeneralIOPassthroughController::init(ros_ethercat_model::RobotState* robot, ros::NodeHandle &n)
00037 {
00038 assert(robot);
00039 node_ = n;
00040
00041 std::string ronex_id;
00042 if (!node_.getParam("ronex_id", ronex_id)) {
00043 ROS_ERROR("No RoNeX ID given (namespace: %s)", node_.getNamespace().c_str());
00044 return false;
00045 }
00046
00047
00048 std::string path;
00049 int parameter_id = get_ronex_param_id(ronex_id);
00050 {
00051 if( parameter_id == -1 )
00052 {
00053 ROS_ERROR_STREAM("Could not find the RoNeX id in the parameter server: " << ronex_id << " not loading the controller.");
00054 return false;
00055 }
00056 else
00057 {
00058 std::stringstream ss;
00059 ss << "/ronex/devices/" << parameter_id << "/path";
00060 if( !ros::param::get(ss.str(), path) )
00061 {
00062 ROS_ERROR_STREAM("Couldn't read the parameter " << ss.str() << " from the parameter server. Not loading the controller.");
00063 return false;
00064 }
00065 }
00066 }
00067
00068 general_io_ = static_cast<ronex::GeneralIO*>( robot->getCustomHW(path) );
00069 if( general_io_ == NULL)
00070 {
00071 ROS_ERROR_STREAM("Could not find RoNeX module: " << ronex_id << " not loading the controller");
00072 return false;
00073 }
00074
00075
00076 std::stringstream sub_topic;
00077 for( size_t i=0; i < general_io_->command_.digital_.size(); ++i)
00078 {
00079 sub_topic.str("");
00080 sub_topic << path << "/command/digital/" << i;
00081 digital_subscribers_.push_back(node_.subscribe<std_msgs::Bool>(sub_topic.str(), 1, boost::bind(&GeneralIOPassthroughController::digital_commands_cb, this, _1, i )));
00082 }
00083
00084 for( size_t i=0; i < general_io_->command_.pwm_.size(); ++i)
00085 {
00086 sub_topic.str("");
00087 sub_topic << path << "/command/pwm/" << i;
00088 pwm_subscribers_.push_back(node_.subscribe<sr_ronex_msgs::PWM>(sub_topic.str(), 1, boost::bind(&GeneralIOPassthroughController::pwm_commands_cb, this, _1, i)));
00089 }
00090
00091 return true;
00092 }
00093
00094 void GeneralIOPassthroughController::digital_commands_cb(const std_msgs::BoolConstPtr& msg, int index)
00095 {
00096 general_io_->command_.digital_[index] = msg->data;
00097 }
00098
00099 void GeneralIOPassthroughController::pwm_commands_cb(const sr_ronex_msgs::PWMConstPtr& msg, int index)
00100 {
00101
00102 general_io_->command_.pwm_[index].period = msg->pwm_period;
00103 general_io_->command_.pwm_[index].on_time_0 = msg->pwm_on_time_0;
00104 general_io_->command_.pwm_[index].on_time_1 = msg->pwm_on_time_1;
00105 }
00106
00107 }
00108
00109
00110
00111
00112
00113