YouBotGripperBar.cpp
Go to the documentation of this file.
1 /****************************************************************
2  *
3  * Copyright (c) 2011
4  * All rights reserved.
5  *
6  * Hochschule Bonn-Rhein-Sieg
7  * University of Applied Sciences
8  * Computer Science Department
9  *
10  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11  *
12  * Author:
13  * Jan Paulus, Nico Hochgeschwender, Michael Reckhaus, Azamat Shakhimardanov
14  * Supervised by:
15  * Gerhard K. Kraetzschmar
16  *
17  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
18  *
19  * This sofware is published under a dual-license: GNU Lesser General Public
20  * License LGPL 2.1 and BSD license. The dual-license implies that users of this
21  * code may choose which terms they prefer.
22  *
23  * +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24  *
25  * Redistribution and use in source and binary forms, with or without
26  * modification, are permitted provided that the following conditions are met:
27  *
28  * * Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * * Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in the
32  * documentation and/or other materials provided with the distribution.
33  * * Neither the name of the Hochschule Bonn-Rhein-Sieg nor the names of its
34  * contributors may be used to endorse or promote products derived from
35  * this software without specific prior written permission.
36  *
37  * This program is free software: you can redistribute it and/or modify
38  * it under the terms of the GNU Lesser General Public License LGPL as
39  * published by the Free Software Foundation, either version 2.1 of the
40  * License, or (at your option) any later version or the BSD license.
41  *
42  * This program is distributed in the hope that it will be useful,
43  * but WITHOUT ANY WARRANTY; without even the implied warranty of
44  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45  * GNU Lesser General Public License LGPL and the BSD license for more details.
46  *
47  * You should have received a copy of the GNU Lesser General Public
48  * License LGPL and BSD license along with this program.
49  *
50  ****************************************************************/
53 namespace youbot {
54 
55 YouBotGripperBar::YouBotGripperBar(const unsigned int barNo, const unsigned int jointNo, const std::string& configFilePath) {
56  // Bouml preserved body begin 000E0371
57  this->jointNumber = jointNo;
58  this->mailboxMsgRetries = 200;
59  this->timeTillNextMailboxUpdate = 1; //ms
60  this->barNo = barNo;
61  this->maxTravelDistance = 0.0115 * meter;
62  this->maxEncoderValue = 67000;
63  this->barSpacingOffset = 0 * meter;
64 
65  ethercatMaster = &(EthercatMaster::getInstance("youbot-ethercat.cfg", configFilePath));
66  // Bouml preserved body end 000E0371
67 }
68 
70  // Bouml preserved body begin 000E03F1
71  // Bouml preserved body end 000E03F1
72 }
73 
75  // Bouml preserved body begin 00061E71
76  this->maxEncoderValue = parameter.value;
77  // Bouml preserved body end 00061E71
78 }
79 
81  // Bouml preserved body begin 000D7871
82  parameter.value = this->maxEncoderValue;
83  // Bouml preserved body end 000D7871
84 }
85 
87  // Bouml preserved body begin 000D77F1
88  parameter.value = this->maxTravelDistance;
89  // Bouml preserved body end 000D77F1
90 }
91 
93  // Bouml preserved body begin 00061DF1
94  this->maxTravelDistance = parameter.value;
95  // Bouml preserved body end 00061DF1
96 }
97 
99  // Bouml preserved body begin 00061871
100  this->barSpacingOffset = parameter.value;
101  // Bouml preserved body end 00061871
102 }
103 
105  // Bouml preserved body begin 000D7771
106  parameter.value = this->barSpacingOffset;
107  // Bouml preserved body end 000D7771
108 }
109 
111  // Bouml preserved body begin 0010A271
112  this->name = parameter.value;
113  // Bouml preserved body end 0010A271
114 }
115 
117  // Bouml preserved body begin 0010A1F1
118  parameter.value = this->name;
119  // Bouml preserved body end 0010A1F1
120 }
121 
123  // Bouml preserved body begin 000E05F1
124 
125  if (parameter.getType() == MOTOR_CONTOLLER_PARAMETER) {
126 
127  YouBotSlaveMailboxMsg message;
128  parameter.getYouBotMailboxMsg(message);
129  message.stctOutput.commandNumber = GAP;
130  message.stctOutput.moduleAddress = GRIPPER;
131  message.stctOutput.motorNumber = this->barNo;
132  message.parameterName = parameter.getName();
133 
134  if (retrieveValueFromMotorContoller(message)) {
135  parameter.setYouBotMailboxMsg(message);
136  } else {
137  throw JointParameterException("Unable to get parameter: " + parameter.getName() + " from the gripper");
138  }
139  }else{
140  throw JointParameterException("Parameter " + parameter.getName() + " is not a motor controller parameter of the gripper");
141  }
142  // Bouml preserved body end 000E05F1
143 }
144 
146  // Bouml preserved body begin 000E0671
147  if (parameter.getType() == MOTOR_CONTOLLER_PARAMETER) {
148 
149  YouBotSlaveMailboxMsg message;
150  parameter.getYouBotMailboxMsg(message);
151  message.stctOutput.commandNumber = SAP;
152  message.stctOutput.moduleAddress = GRIPPER;
153  message.stctOutput.motorNumber = this->barNo;
154  message.parameterName = parameter.getName();
155 
156  if (!setValueToMotorContoller(message)) {
157  throw JointParameterException("Unable to set parameter: " + parameter.getName() + " to the gripper");
158  }
159  }else{
160  throw JointParameterException("Parameter " + parameter.getName() + " is not a motor controller parameter of the gripper");
161  }
162  // Bouml preserved body end 000E0671
163 }
164 
166  // Bouml preserved body begin 000E0A71
167  if (!retrieveValueFromMotorContoller(parameter)) {
168  throw JointParameterException("Unable to get parameter from the gripper");
169  }
170  this->parseMailboxStatusFlags(parameter);
171  // Bouml preserved body end 000E0A71
172 }
173 
175  // Bouml preserved body begin 000E0CF1
176  YouBotSlaveMailboxMsg message;
177  message.stctOutput.moduleAddress = GRIPPER;
178  message.stctOutput.commandNumber = MVP;
179  message.stctOutput.typeNumber = 0; //move gripper absolute
180  message.stctOutput.motorNumber = this->barNo;
181  message.stctOutput.value = encoderSetpoint.barEncoder * -1;
182 
183  setValueToMotorContoller(message);
184 
185  // Bouml preserved body end 000E0CF1
186 }
187 
189  // Bouml preserved body begin 000E0DF1
190  YouBotSlaveMailboxMsg message;
191  message.stctOutput.moduleAddress = GRIPPER;
192  message.stctOutput.commandNumber = GAP;
193  message.stctOutput.typeNumber = 3; //actual velocity
194  message.stctOutput.value = 0;
195 
196  message.stctOutput.motorNumber = this->barNo;
197 
199  //std::cout << message.stctInput.value << std::endl;
200 
201  barVelocity.barVelocity = message.stctInput.value;
202 
203 
204  // Bouml preserved body end 000E0DF1
205 }
206 
208  // Bouml preserved body begin 000F9171
209  int valueBar = 0;
210  ActualPosition actualPoseBar;
211  this->getConfigurationParameter(actualPoseBar);
212  actualPoseBar.getParameter(valueBar);
213 
214  barPosition.barPosition = (((double) valueBar / this->maxEncoderValue) * this->maxTravelDistance) + this->barSpacingOffset;
215 
216  // Bouml preserved body end 000F9171
217 }
218 
220  // Bouml preserved body begin 000F91F1
221 
222  if (barPosition.barPosition > (this->maxTravelDistance + this->barSpacingOffset) || barPosition.barPosition < this->barSpacingOffset) {
223  std::stringstream errorMessageStream;
224  errorMessageStream << "The bar position is not allowed to be less than "<< this->barSpacingOffset.value() <<" or higher than " << (this->maxTravelDistance.value() + this->barSpacingOffset.value()) << ". You set " << barPosition.barPosition.value();
225  throw std::out_of_range(errorMessageStream.str());
226  }
227 
228  quantity<si::length> setpoint;;
229  setpoint = (barPosition.barPosition - this->barSpacingOffset);
230 
231  GripperBarEncoderSetpoint setpointBar;
232  setpointBar.barEncoder = setpoint / this->maxTravelDistance * this->maxEncoderValue;
233  this->setData(setpointBar);
234 
235  // Bouml preserved body end 000F91F1
236 }
237 
238 void YouBotGripperBar::parseGripperErrorFlags(const unsigned int& errosFlags) {
239  // Bouml preserved body begin 00103CF1
240  if (errosFlags & STALL_GUARD_STATUS) {
241  // LOG(warning) << "Gripper " << "stallguard2 threshold reached";
242  }
243  if (errosFlags & GRIPPER_OVER_TEMPERATURE) {
244  LOG(error) << "Gripper " << "over temperature";
245  }
246  if (errosFlags & PRE_WARNING_OVER_TEMPERATURE) {
247  LOG(warning) << "Gripper " << "pre warning over temperature";
248  }
249  if (errosFlags & SHORT_TO_GROUND_A) {
250  LOG(error) << "Gripper " << "short to ground A";
251  }
252  if (errosFlags & SHORT_TO_GROUND_B) {
253  LOG(error) << "Gripper " << "short to ground B";
254  }
255  if (errosFlags & OPEN_LOAD_A) {
256  LOG(warning) << "Gripper " << "open load A";
257  }
258  if (errosFlags & OPEN_LOAD_B) {
259  LOG(warning) << "Gripper " << "open load B";
260  }
261  if (errosFlags & STAND_STILL) {
262  // LOG(info) << "Gripper " << "stand still";
263  }
264  if ( !(errosFlags & STAND_STILL) && (errosFlags & STALL_GUARD_STATUS) ) {
265  LOG(info) << "Gripper " << "motor stall";
266  }
267  // Bouml preserved body end 00103CF1
268 }
269 
271  // Bouml preserved body begin 000E0E71
272  std::stringstream errorMessageStream;
273  errorMessageStream << "Joint " << this->jointNumber << ": ";
274  std::string errorMessage;
275  errorMessage = errorMessageStream.str();
276 
277 
278  switch(mailboxMsg.stctInput.status){
279  case MAILBOX_SUCCESS:
280  break;
281  case INVALID_COMMAND:
282  LOG(error) << errorMessage << "Parameter name: " << mailboxMsg.parameterName << "; Command no: " << mailboxMsg.stctOutput.commandNumber << " is an invalid command!" ;
283  // throw JointParameterException(errorMessage + "invalid command");
284  break;
285  case WRONG_TYPE:
286  LOG(error) << errorMessage << "Parameter name: " << mailboxMsg.parameterName << " has a wrong type!";
287  // throw JointParameterException(errorMessage + "wrong type");
288  break;
289  case INVALID_VALUE:
290  LOG(error) << errorMessage << "Parameter name: " << mailboxMsg.parameterName << " Value: " << mailboxMsg.stctOutput.value << " is a invalid value!";
291  // throw JointParameterException(errorMessage + "invalid value");
292  break;
294  LOG(error) << errorMessage << "Parameter name: " << mailboxMsg.parameterName << " Configuration EEPROM locked";
295  // throw JointParameterException(errorMessage + "configuration EEPROM locked");
296  break;
298  LOG(error) << errorMessage << "Parameter name: " << mailboxMsg.parameterName << "; Command no: " << mailboxMsg.stctOutput.commandNumber << "Command is not available!";
299  // throw JointParameterException(errorMessage + "command not available");
300  break;
301  }
302 
303 
304  // Bouml preserved body end 000E0E71
305 }
306 
308  // Bouml preserved body begin 000E0EF1
309 
310  YouBotSlaveMailboxMsg mailboxMsgBuffer;
311  mailboxMsgBuffer = mailboxMsg;
312  bool unvalid = true;
313  unsigned int retry = 0;
314 
315  ethercatMaster->setMailboxMsgBuffer(mailboxMsgBuffer, this->jointNumber);
316 // LOG(trace) << "set Output CommandNumber " << (int) mailboxMsgBuffer.stctOutput.commandNumber
317 // << " moduleAddress " << (int) mailboxMsgBuffer.stctOutput.moduleAddress
318 // << " motorNumber " << (int) mailboxMsgBuffer.stctOutput.motorNumber
319 // << " typeNumber " << (int) mailboxMsgBuffer.stctOutput.typeNumber
320 // << " value " << mailboxMsgBuffer.stctOutput.value;
321 
323 
324  do {
325 
326 
327  if (ethercatMaster->getMailboxMsgBuffer(mailboxMsgBuffer, this->jointNumber) &&
328  mailboxMsgBuffer.stctInput.status == MAILBOX_SUCCESS) {
329  unvalid = false;
330  } else {
332  retry++;
333  }
334 // LOG(trace) << "set Input CommandNumber " << (int) mailboxMsgBuffer.stctInput.commandNumber
335 // << " moduleAddress " << (int) mailboxMsgBuffer.stctInput.moduleAddress
336 // << " replyAddress " << (int) mailboxMsgBuffer.stctInput.replyAddress
337 // << " status " << (int) mailboxMsgBuffer.stctInput.status
338 // << " value " << mailboxMsgBuffer.stctInput.value;
339  } while (retry < mailboxMsgRetries && unvalid);
340 
341  if (unvalid) {
342  this->parseMailboxStatusFlags(mailboxMsgBuffer);
343  return false;
344  } else {
345  return true;
346  }
347 
348  // Bouml preserved body end 000E0EF1
349 }
350 
352  // Bouml preserved body begin 000E0F71
353 
354  bool unvalid = true;
355  unsigned int retry = 0;
356 
358 // LOG(trace) << "get Output CommandNumber " << (int) message.stctOutput.commandNumber
359 // << " moduleAddress " << (int) message.stctOutput.moduleAddress
360 // << " motorNumber " << (int) message.stctOutput.motorNumber
361 // << " typeNumber " << (int) message.stctOutput.typeNumber
362 // << " value " << message.stctOutput.value
363 // << " No " << this->jointNumber;
364 
366 
367  do {
368 
369 
370  if (ethercatMaster->getMailboxMsgBuffer(message, this->jointNumber) &&
371  message.stctInput.status == MAILBOX_SUCCESS) {
372  unvalid = false;
373  } else {
375  retry++;
376  }
377 // LOG(trace) << "get input CommandNumber " << (int) message.stctInput.commandNumber
378 // << " moduleAddress " << (int) message.stctInput.moduleAddress
379 // << " replyAddress " << (int) message.stctInput.replyAddress
380 // << " status " << (int) message.stctInput.status
381 // << " value " << message.stctInput.value
382 // << " No " << this->jointNumber;
383 
384  } while (retry < mailboxMsgRetries && unvalid);
385 
386  if (unvalid) {
387  this->parseMailboxStatusFlags(message);
388  return false;
389  } else {
390  return true;
391  }
392 
393  // Bouml preserved body end 000E0F71
394 }
395 
396 
397 } // namespace youbot
virtual void getData(GripperSensedVelocity &barVelocity) const
YouBotGripperBar(const unsigned int barNo, const unsigned int jointNo, const std::string &configFilePath="../config/")
void parseMailboxStatusFlags(const YouBotSlaveMailboxMsg &mailboxMsg) const
The encoder value when the gripper has reached it&#39;s maximum bar spacing position. ...
quantity< si::length > barSpacingOffset
virtual void setMailboxMsgBuffer(const YouBotSlaveMailboxMsg &msgBuffer, const unsigned int jointNumber)=0
bool setValueToMotorContoller(const YouBotSlaveMailboxMsg &mailboxMsg) const
Actual position of one gripper bar.
virtual void getYouBotMailboxMsg(YouBotSlaveMailboxMsg &message) const =0
The encoder setpoint for one bar.
virtual void getConfigurationParameter(MaxEncoderValue &parameter) const
virtual std::string getName() const =0
virtual void setYouBotMailboxMsg(const YouBotSlaveMailboxMsg &message)=0
The maximum bar spacing distance of the gripper.
virtual void setData(const GripperBarEncoderSetpoint &encoderSetpoint)
#define LOG(level)
Definition: Logger.hpp:102
Joint parameter exception.
Definition: Exceptions.hpp:104
EtherCAT mailbox message of the youBot slaves.
virtual void setConfigurationParameter(const MaxEncoderValue &parameter)
virtual ParameterType getType() const =0
void parseGripperErrorFlags(const unsigned int &errosFlags)
The sensed bar velocity for a one DOF gripper.
Represents a bar spacing offset. It could be useful if the gripper can not be totally closed...
#define SLEEP_MILLISEC(millisec)
Definition: Time.hpp:60
quantity< si::length > maxTravelDistance
bool retrieveValueFromMotorContoller(YouBotSlaveMailboxMsg &message) const
abstract youBot gripper parameter
The name for a gripper bar or finger.
void getParameter(int &parameter) const
The bar position for a one gripper bar.
static EthercatMasterInterface & getInstance(const std::string configFile="youbot-ethercat.cfg", const std::string configFilePath="../config/", const bool ethercatMasterWithThread=true)
unsigned int timeTillNextMailboxUpdate
The sensed bar position for a one gripper bar.
EthercatMasterInterface * ethercatMaster
virtual bool getMailboxMsgBuffer(YouBotSlaveMailboxMsg &mailboxMsg, const unsigned int jointNumber)=0


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