EthercatMasterWithoutThread.hpp
Go to the documentation of this file.
00001 #ifndef YOUBOT_ETHERCATMASTERWITHOUTTHREAD_H
00002 #define YOUBOT_ETHERCATMASTERWITHOUTTHREAD_H
00003 
00004 /****************************************************************
00005  *
00006  * Copyright (c) 2011
00007  * All rights reserved.
00008  *
00009  * Hochschule Bonn-Rhein-Sieg
00010  * University of Applied Sciences
00011  * Computer Science Department
00012  *
00013  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00014  *
00015  * Author:
00016  * Jan Paulus, Nico Hochgeschwender, Michael Reckhaus, Azamat Shakhimardanov
00017  * Supervised by:
00018  * Gerhard K. Kraetzschmar
00019  *
00020  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00021  *
00022  * This sofware is published under a dual-license: GNU Lesser General Public 
00023  * License LGPL 2.1 and BSD license. The dual-license implies that users of this
00024  * code may choose which terms they prefer.
00025  *
00026  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
00027  *
00028  * Redistribution and use in source and binary forms, with or without
00029  * modification, are permitted provided that the following conditions are met:
00030  *
00031  *     * Redistributions of source code must retain the above copyright
00032  *       notice, this list of conditions and the following disclaimer.
00033  *     * Redistributions in binary form must reproduce the above copyright
00034  *       notice, this list of conditions and the following disclaimer in the
00035  *       documentation and/or other materials provided with the distribution.
00036  *     * Neither the name of the Hochschule Bonn-Rhein-Sieg nor the names of its
00037  *       contributors may be used to endorse or promote products derived from
00038  *       this software without specific prior written permission.
00039  *
00040  * This program is free software: you can redistribute it and/or modify
00041  * it under the terms of the GNU Lesser General Public License LGPL as
00042  * published by the Free Software Foundation, either version 2.1 of the
00043  * License, or (at your option) any later version or the BSD license.
00044  *
00045  * This program is distributed in the hope that it will be useful,
00046  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00047  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00048  * GNU Lesser General Public License LGPL and the BSD license for more details.
00049  *
00050  * You should have received a copy of the GNU Lesser General Public
00051  * License LGPL and BSD license along with this program.
00052  *
00053  ****************************************************************/
00054 
00055 #include <vector>
00056 #include <sstream>
00057 #include <string>
00058 #include <cstdio>
00059 #include <stdexcept>
00060 #include <iostream>
00061 #include <boost/thread.hpp>
00062 #include <boost/date_time/posix_time/posix_time.hpp>
00063 #include <youbot_driver/generic/Logger.hpp>
00064 #include <youbot_driver/generic/Units.hpp>
00065 #include <youbot_driver/generic/Time.hpp>
00066 #include <youbot_driver/generic/Exceptions.hpp>
00067 #include <youbot_driver/generic/ConfigFile.hpp>
00068 #include <youbot_driver/youbot/ProtocolDefinitions.hpp>
00069 #include <youbot_driver/youbot/YouBotSlaveMsg.hpp>
00070 #include <youbot_driver/youbot/YouBotSlaveMailboxMsg.hpp>
00071 #include <youbot_driver/youbot/EthercatMaster.hpp>
00072 #include <youbot_driver/youbot/JointLimitMonitor.hpp>
00073 
00074 extern "C"
00075 {
00076 #include <youbot_driver/soem/ethercattype.h>
00077 #include <youbot_driver/soem/ethercatmain.h>
00078 }
00079 
00080 namespace youbot
00081 {
00082 
00087 class EthercatMasterWithoutThread : public EthercatMasterInterface
00088 {
00089   friend class EthercatMaster;
00090   friend class YouBotJoint;
00091   friend class YouBotGripper;
00092   friend class YouBotGripperBar;
00093 private:
00094   EthercatMasterWithoutThread(const std::string& configFile, const std::string& configFilePath);
00095 
00096   ~EthercatMasterWithoutThread();
00097 
00098 public:
00099   bool isThreadActive();
00100 
00102   unsigned int getNumberOfSlaves() const;
00103 
00104   void AutomaticSendOn(const bool enableAutomaticSend);
00105 
00106   void AutomaticReceiveOn(const bool enableAutomaticReceive);
00107 
00110   void getEthercatDiagnosticInformation(std::vector<ec_slavet>& ethercatSlaveInfos);
00111 
00114   bool sendProcessData();
00115 
00118   bool receiveProcessData();
00119 
00122   bool isErrorInSoemDriver();
00123 
00124   bool isEtherCATConnectionEstablished();
00125 
00126   void registerJointLimitMonitor(JointLimitMonitor* object, const unsigned int JointNumber);
00127 
00128 private:
00130   void initializeEthercat();
00131 
00133   bool closeEthercat();
00134 
00138   void setMsgBuffer(const YouBotSlaveMsg& msgBuffer, const unsigned int jointNumber);
00139 
00143   void getMsgBuffer(const unsigned int jointNumber, YouBotSlaveMsg& returnMsg);
00144 
00148   void setMailboxMsgBuffer(const YouBotSlaveMailboxMsg& msgBuffer, const unsigned int jointNumber);
00149 
00153   bool getMailboxMsgBuffer(YouBotSlaveMailboxMsg& mailboxMsg, const unsigned int jointNumber);
00154 
00157   bool sendMailboxMessage(const YouBotSlaveMailboxMsg& mailboxMsg);
00158 
00161   bool receiveMailboxMessage(YouBotSlaveMailboxMsg& mailboxMsg);
00162 
00163   void parseYouBotErrorFlags(const YouBotSlaveMsg& messageBuffer);
00164 
00165   std::string ethernetDevice;
00166 
00167   std::vector<YouBotSlaveMsg> processDataBuffer;
00168 
00169   unsigned int nrOfSlaves;
00170 
00171   std::vector<SlaveMessageOutput*> ethercatOutputBufferVector;
00172 
00173   std::vector<SlaveMessageInput*> ethercatInputBufferVector;
00174 
00175   std::vector<YouBotSlaveMailboxMsg> firstMailboxBufferVector;
00176 
00177   ec_mbxbuft mailboxBufferSend;
00178 
00179   unsigned int mailboxTimeout;
00180 
00181   ec_mbxbuft mailboxBufferReceive;
00182 
00183   ConfigFile* configfile;
00184 
00185   std::vector<ec_slavet> ethercatSlaveInfo;
00186 
00187   char IOmap_[4096];
00188 
00189   unsigned int ethercatTimeout;
00190 
00191   static std::string configFileName;
00192 
00193   static std::string configFilepath;
00194 
00195   bool ethercatConnectionEstablished;
00196 
00197 };
00198 
00199 } // namespace youbot
00200 #endif


youbot_driver
Author(s): Jan Paulus
autogenerated on Mon Oct 6 2014 09:08:01