ronex_transmission.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 
00026 #include <sr_ronex_transmissions/ronex_transmission.hpp>
00027 #include "pluginlib/class_list_macros.h"
00028 #include <cstring>
00029 
00030 #include "sr_ronex_transmissions/mapping/general_io/analogue_to_position.hpp"
00031 #include "sr_ronex_transmissions/mapping/general_io/analogue_to_effort.hpp"
00032 #include "sr_ronex_transmissions/mapping/general_io/command_to_pwm.hpp"
00033 
00034 PLUGINLIB_EXPORT_CLASS( ronex::RonexTransmission, ros_ethercat_model::Transmission)
00035 
00036 namespace ronex
00037 {
00038   bool RonexTransmission::initXml(TiXmlElement *elt, ros_ethercat_model::RobotState *robot)
00039   {
00040     if (!ros_ethercat_model::Transmission::initXml(elt, robot))
00041       return false;
00042 
00043     //Extract all the mapping information from the transmission
00044     for( TiXmlElement *mapping_el = elt->FirstChildElement("mapping"); mapping_el;
00045          mapping_el = mapping_el->NextSiblingElement("mapping") )
00046     {
00047       const char *property = mapping_el ? mapping_el->Attribute("property") : NULL;
00048       if (!property)
00049       {
00050         ROS_ERROR("RonexTransmission: no property defined for the mapping. Skipping the mapping.");
00051       }
00052       else
00053       {
00054         //@todo is there a better way of instantiating the correct type?
00055         if( std::strcmp("position", property) == 0 )
00056         {
00057           ronex_mappings_.push_back( new mapping::general_io::AnalogueToPosition(mapping_el, robot) );
00058         }
00059         else if( std::strcmp("effort", property) == 0 )
00060         {
00061           ronex_mappings_.push_back( new mapping::general_io::AnalogueToEffort(mapping_el, robot) );
00062         }
00063         else if( std::strcmp("command", property) == 0 )
00064         {
00065           ronex_mappings_.push_back( new mapping::general_io::CommandToPWM(mapping_el, robot) );
00066         }
00067         else
00068           ROS_WARN_STREAM("Property not recognized: " << property);
00069       }
00070     }
00071 
00072     return true;
00073   }
00074 
00075   void RonexTransmission::propagatePosition()
00076   {
00077     for(ronex_iter_ = ronex_mappings_.begin(); ronex_iter_ != ronex_mappings_.end(); ++ronex_iter_)
00078     {
00079       ronex_iter_->propagateFromRonex(joint_);
00080     }
00081   }
00082 
00083   void RonexTransmission::propagateEffort()
00084   {
00085     for(ronex_iter_ = ronex_mappings_.begin(); ronex_iter_ != ronex_mappings_.end(); ++ronex_iter_)
00086     {
00087       ronex_iter_->propagateToRonex(joint_);
00088     }
00089   }
00090 }
00091 
00092 /* For the emacs weenies in the crowd.
00093    Local Variables:
00094    c-basic-offset: 2
00095    End:
00096 */


sr_ronex_transmissions
Author(s): Ugo Cupcic, Toni Oliver, Mark Pitchless
autogenerated on Fri Aug 28 2015 13:12:29