EthercatMasterWithThread.hpp
Go to the documentation of this file.
1 #ifndef YOUBOT_ETHERCATMASTERWITHTHREAD_H
2 #define YOUBOT_ETHERCATMASTERWITHTHREAD_H
3 
4 /****************************************************************
5  *
6  * Copyright (c) 2011
7  * All rights reserved.
8  *
9  * Hochschule Bonn-Rhein-Sieg
10  * University of Applied Sciences
11  * Computer Science Department
12  *
13  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
14  *
15  * Author:
16  * Jan Paulus, Nico Hochgeschwender, Michael Reckhaus, Azamat Shakhimardanov
17  * Supervised by:
18  * Gerhard K. Kraetzschmar
19  *
20  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
21  *
22  * This sofware is published under a dual-license: GNU Lesser General Public
23  * License LGPL 2.1 and BSD license. The dual-license implies that users of this
24  * code may choose which terms they prefer.
25  *
26  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27  *
28  * Redistribution and use in source and binary forms, with or without
29  * modification, are permitted provided that the following conditions are met:
30  *
31  * * Redistributions of source code must retain the above copyright
32  * notice, this list of conditions and the following disclaimer.
33  * * Redistributions in binary form must reproduce the above copyright
34  * notice, this list of conditions and the following disclaimer in the
35  * documentation and/or other materials provided with the distribution.
36  * * Neither the name of the Hochschule Bonn-Rhein-Sieg nor the names of its
37  * contributors may be used to endorse or promote products derived from
38  * this software without specific prior written permission.
39  *
40  * This program is free software: you can redistribute it and/or modify
41  * it under the terms of the GNU Lesser General Public License LGPL as
42  * published by the Free Software Foundation, either version 2.1 of the
43  * License, or (at your option) any later version or the BSD license.
44  *
45  * This program is distributed in the hope that it will be useful,
46  * but WITHOUT ANY WARRANTY; without even the implied warranty of
47  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48  * GNU Lesser General Public License LGPL and the BSD license for more details.
49  *
50  * You should have received a copy of the GNU Lesser General Public
51  * License LGPL and BSD license along with this program.
52  *
53  ****************************************************************/
54 #include <vector>
55 #include <sstream>
56 #include <string>
57 #include <cstdio>
58 #include <stdexcept>
59 #include <iostream>
60 #include <boost/thread.hpp>
61 #include <boost/date_time/posix_time/posix_time.hpp>
73 
74 extern "C"{
77 }
78 
79 namespace youbot {
80 
86 friend class EthercatMaster;
87 friend class YouBotJoint;
88 friend class YouBotGripper;
89 friend class YouBotGripperBar;
90  private:
91  EthercatMasterWithThread(const std::string& configFile, const std::string& configFilePath);
92 
94 
95 
96  public:
97  bool isThreadActive();
98 
100  unsigned int getNumberOfSlaves() const;
101 
102  void AutomaticSendOn(const bool enableAutomaticSend);
103 
104  void AutomaticReceiveOn(const bool enableAutomaticReceive);
105 
108  void getEthercatDiagnosticInformation(std::vector<ec_slavet>& ethercatSlaveInfos);
109 
112  bool sendProcessData();
113 
116  bool receiveProcessData();
117 
120  bool isErrorInSoemDriver();
121 
122  void registerJointTrajectoryController(JointTrajectoryController* object, const unsigned int JointNumber);
123 
124  void deleteJointTrajectoryControllerRegistration(const unsigned int JointNumber);
125 
126  unsigned int getNumberOfThreadCyclesPerSecond();
127 
129 
130  void registerJointLimitMonitor(JointLimitMonitor* object, const unsigned int JointNumber);
131 
132  void registerDataTrace(void* object, const unsigned int JointNumber);
133 
134  void deleteDataTraceRegistration(const unsigned int JointNumber);
135 
136 
137  private:
139  void initializeEthercat();
140 
142  bool closeEthercat();
143 
147  void setMsgBuffer(const YouBotSlaveMsg& msgBuffer, const unsigned int jointNumber);
148 
152  void getMsgBuffer(const unsigned int jointNumber, YouBotSlaveMsg& returnMsg);
153 
157  void setMailboxMsgBuffer(const YouBotSlaveMailboxMsg& msgBuffer, const unsigned int jointNumber);
158 
162  bool getMailboxMsgBuffer(YouBotSlaveMailboxMsg& mailboxMsg, const unsigned int jointNumber);
163 
166  bool sendMailboxMessage(const YouBotSlaveMailboxMsg& mailboxMsg);
167 
171 
175 
176  void parseYouBotErrorFlags(const YouBotSlaveMsg& messageBuffer);
177 
178  std::string ethernetDevice;
179 
180  char IOmap_[4096];
181 
183 
184  unsigned int nrOfSlaves;
185 
186  std::vector<SlaveMessageOutput*> ethercatOutputBufferVector;
187 
188  std::vector<SlaveMessageInput*> ethercatInputBufferVector;
189 
190  std::vector<YouBotSlaveMsgThreadSafe> slaveMessages;
191 
192  std::vector<ec_slavet> ethercatSlaveInfo;
193 
194  unsigned int ethercatTimeout;
195 
196  //in microseconds
198 
199  boost::thread_group threads;
200 
201  volatile bool stopThread;
202 
204 
206 
207  std::vector<YouBotSlaveMsg> automaticSendOffBufferVector;
208 
209  std::vector<YouBotSlaveMsg> automaticReceiveOffBufferVector;
210 
211  std::vector<YouBotSlaveMailboxMsgThreadSafe> mailboxMessages;
212 
213  unsigned int mailboxTimeout;
214 
215  std::vector<bool> newInputMailboxMsgFlag;
216 
217  std::vector<bool> outstandingMailboxMsgFlag;
218 
219  std::vector<bool> pendingMailboxMsgsReply;
220 
222 
223  static std::string configFileName;
224 
225  static std::string configFilepath;
226 
228 
230 
232 
234 
236 
237  std::vector<JointTrajectoryController*> trajectoryControllers;
238 
240 
241  std::vector<JointLimitMonitor*> jointLimitMonitors;
242 
244 
245  std::vector<void*> dataTraces;
246 
247  boost::mutex dataTracesMutex;
248 
249 };
250 
251 } // namespace youbot
252 #endif
void AutomaticReceiveOn(const bool enableAutomaticReceive)
void setMailboxMsgBuffer(const YouBotSlaveMailboxMsg &msgBuffer, const unsigned int jointNumber)
void setMsgBuffer(const YouBotSlaveMsg &msgBuffer, const unsigned int jointNumber)
The Ethercat Master factory.
std::vector< SlaveMessageInput * > ethercatInputBufferVector
bool getMailboxMsgBuffer(YouBotSlaveMailboxMsg &mailboxMsg, const unsigned int jointNumber)
std::vector< YouBotSlaveMailboxMsgThreadSafe > mailboxMessages
Reads and writes a configuration file.
Definition: ConfigFile.hpp:125
void deleteJointTrajectoryControllerRegistration(const unsigned int JointNumber)
The youBot gripper with one degree of freedom.
void registerJointTrajectoryController(JointTrajectoryController *object, const unsigned int JointNumber)
std::vector< YouBotSlaveMsgThreadSafe > slaveMessages
General typedefs and defines for EtherCAT.
std::vector< JointLimitMonitor * > jointLimitMonitors
std::vector< SlaveMessageOutput * > ethercatOutputBufferVector
void getMsgBuffer(const unsigned int jointNumber, YouBotSlaveMsg &returnMsg)
void deleteDataTraceRegistration(const unsigned int JointNumber)
void initializeEthercat()
establishes the ethercat connection
bool receiveMailboxMessage(YouBotSlaveMailboxMsg &mailboxMsg)
EthercatMasterWithThread(const std::string &configFile, const std::string &configFilePath)
bool sendMailboxMessage(const YouBotSlaveMailboxMsg &mailboxMsg)
It monitors the joint position and will decelerate and stop the joint if it is close the limits...
void registerDataTrace(void *object, const unsigned int JointNumber)
EtherCAT mailbox message of the youBot slaves.
void AutomaticSendOn(const bool enableAutomaticSend)
The Ethercat Master interface.
One bar of the youBot gripper.
std::vector< JointTrajectoryController * > trajectoryControllers
std::vector< YouBotSlaveMsg > automaticReceiveOffBufferVector
void getEthercatDiagnosticInformation(std::vector< ec_slavet > &ethercatSlaveInfos)
Headerfile for ethercatmain.c.
void registerJointLimitMonitor(JointLimitMonitor *object, const unsigned int JointNumber)
void parseYouBotErrorFlags(const YouBotSlaveMsg &messageBuffer)
EtherCat message of the youBot EtherCat slaves.
bool closeEthercat()
closes the ethercat connection
std::vector< YouBotSlaveMsg > automaticSendOffBufferVector
unsigned int getNumberOfSlaves() const
return the quantity of ethercat slave which have an input/output buffer
uint8 ec_mbxbuft[EC_MAXMBX+1]
Definition: ethercatmain.h:341


youbot_driver
Author(s): Jan Paulus
autogenerated on Mon Jun 10 2019 15:46:24