adc16_passthrough_controller.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2013, Shadow Robot Company, All rights reserved.
00003  * 
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 3.0 of the License, or (at your option) any later version.
00008  * 
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00012  * Lesser General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library.
00016  */
00017 
00025 #include "sr_ronex_controllers/adc16_passthrough_controller.hpp"
00026 #include "pluginlib/class_list_macros.h"
00027 #include <string>
00028 
00029 PLUGINLIB_EXPORT_CLASS(ronex::ADC16PassthroughController, controller_interface::ControllerBase)
00030 
00031 namespace ronex
00032 {
00033 ADC16PassthroughController::ADC16PassthroughController()
00034   : loop_count_(0)
00035 {}
00036 
00037 bool ADC16PassthroughController::init(ros_ethercat_model::RobotStateInterface* robot, ros::NodeHandle &n)
00038 {
00039   assert(robot);
00040   node_ = n;
00041 
00042   std::string ronex_id;
00043   if (!node_.getParam("ronex_id", ronex_id))
00044   {
00045     ROS_ERROR("No RoNeX ID given (namespace: %s)", node_.getNamespace().c_str());
00046     return false;
00047   }
00048 
00049   // get the path from the parameters
00050   std::string path;
00051   int parameter_id = get_ronex_param_id(ronex_id);
00052   {
00053     if (parameter_id == -1)
00054     {
00055       ROS_ERROR_STREAM("Could not find the RoNeX id in the parameter server: " << ronex_id <<
00056                                " not loading the controller.");
00057       return false;
00058     }
00059     else
00060     {
00061       std::stringstream ss;
00062       ss << "/ronex/devices/" << parameter_id << "/path";
00063       if (!ros::param::get(ss.str(), path))
00064       {
00065         ROS_ERROR_STREAM("Couldn't read the parameter " << ss.str() <<
00066                                  " from the parameter server. Not loading the controller.");
00067         return false;
00068       }
00069     }
00070   }
00071 
00072   std::string robot_state_name;
00073   node_.param<std::string>("robot_state_name", robot_state_name, "unique_robot_hw");
00074 
00075   try
00076   {
00077     adc16_ = static_cast<ronex::ADC16*>(robot->getHandle(robot_state_name).getState()->getCustomHW(path));
00078   }
00079   catch(const hardware_interface::HardwareInterfaceException& e)
00080   {
00081     ROS_ERROR_STREAM("Could not find robot state: " << robot_state_name << " Not loading the controller. " << e.what());
00082     return false;
00083   }
00084 
00085   if ( adc16_ == NULL)
00086   {
00087     ROS_ERROR_STREAM("Could not find RoNeX module: " << ronex_id << " not loading the controller");
00088     return false;
00089   }
00090 
00091   // init the subscribers
00092   std::stringstream sub_topic;
00093   for (size_t i = 0; i < adc16_->command_.digital_.size(); ++i)
00094   {
00095     sub_topic.str("");
00096     sub_topic << path << "/command/digital/" << i;
00097     digital_subscribers_.push_back(
00098             node_.subscribe<std_msgs::Bool>(sub_topic.str(), 1,
00099                                             boost::bind(&ADC16PassthroughController::digital_commands_cb,
00100                                                         this, _1, i)));
00101   }
00102 
00103   return true;
00104 }
00105 
00106 void ADC16PassthroughController::digital_commands_cb(const std_msgs::BoolConstPtr& msg, int index)
00107 {
00108   adc16_->command_.digital_[index] = msg->data;
00109 }
00110 
00111 }  // namespace ronex
00112 
00113 /* For the emacs weenies in the crowd.
00114 Local Variables:
00115    c-basic-offset: 2
00116 End:
00117 */


sr_ronex_controllers
Author(s): Ugo Cupcic, Toni Oliver, Mark Pitchless
autogenerated on Thu Jun 6 2019 21:22:06