1 |
|
|
// Copyright (c) 2014, LAAS-CNRS |
2 |
|
|
// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) |
3 |
|
|
// |
4 |
|
|
|
5 |
|
|
// Redistribution and use in source and binary forms, with or without |
6 |
|
|
// modification, are permitted provided that the following conditions are |
7 |
|
|
// met: |
8 |
|
|
// |
9 |
|
|
// 1. Redistributions of source code must retain the above copyright |
10 |
|
|
// notice, this list of conditions and the following disclaimer. |
11 |
|
|
// |
12 |
|
|
// 2. Redistributions in binary form must reproduce the above copyright |
13 |
|
|
// notice, this list of conditions and the following disclaimer in the |
14 |
|
|
// documentation and/or other materials provided with the distribution. |
15 |
|
|
// |
16 |
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
17 |
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
18 |
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
19 |
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
20 |
|
|
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
21 |
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
22 |
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 |
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 |
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 |
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 |
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
27 |
|
|
// DAMAGE. |
28 |
|
|
|
29 |
|
|
#include "hpp/manipulation/srdf/factories/gripper.hh" |
30 |
|
|
|
31 |
|
|
#include <hpp/manipulation/device.hh> |
32 |
|
|
#include <hpp/pinocchio/gripper.hh> |
33 |
|
|
#include <hpp/util/debug.hh> |
34 |
|
|
#include <hpp/util/pointer.hh> |
35 |
|
|
#include <pinocchio/multibody/model.hpp> |
36 |
|
|
|
37 |
|
|
#include "hpp/manipulation/srdf/factories/position.hh" |
38 |
|
|
|
39 |
|
|
#ifndef TIXML_SSCANF |
40 |
|
|
#define TIXML_SSCANF sscanf |
41 |
|
|
#endif |
42 |
|
|
|
43 |
|
|
namespace hpp { |
44 |
|
|
namespace manipulation { |
45 |
|
|
namespace srdf { |
46 |
|
|
void GripperFactory::finishTags() { |
47 |
|
|
ObjectFactoryList factories = getChildrenOfType("position"); |
48 |
|
|
if (factories.empty()) { |
49 |
|
|
factories = getChildrenOfType("handle_position_in_joint"); |
50 |
|
|
hppDout(warning, "Use tag position instead of handle_position_in_joint"); |
51 |
|
|
} |
52 |
|
|
if (factories.size() != 1) |
53 |
|
|
throw std::invalid_argument("gripper tag " + name() + |
54 |
|
|
" should have exactly one <position>"); |
55 |
|
|
PositionFactory* pf = factories.front()->as<PositionFactory>(); |
56 |
|
|
localPosition_ = pf->position(); |
57 |
|
|
|
58 |
|
|
factories = getChildrenOfType("link"); |
59 |
|
|
if (factories.size() != 1) |
60 |
|
|
throw std::invalid_argument("gripper tag " + name() + |
61 |
|
|
" should have exactly one <link>"); |
62 |
|
|
linkName_ = root()->prependPrefix(factories.front()->name()); |
63 |
|
|
const std::string& gripperName = root()->prependPrefix(name()); |
64 |
|
|
if (gripperName == linkName_) |
65 |
|
|
throw std::invalid_argument("Gripper " + gripperName + |
66 |
|
|
" cannot have the same name as link " + |
67 |
|
|
linkName_ + |
68 |
|
|
". " |
69 |
|
|
"Cannot create gripper"); |
70 |
|
|
|
71 |
|
|
/// Get the clearance |
72 |
|
|
value_type clearance = 0; |
73 |
|
|
if (hasAttribute("clearance")) { |
74 |
|
|
if (TIXML_SSCANF(getAttribute("clearance").c_str(), "%lf", &clearance) != |
75 |
|
|
1) { |
76 |
|
|
hppDout(error, "Could not cast attribute clearance of tag " |
77 |
|
|
<< name() << " to double"); |
78 |
|
|
} |
79 |
|
|
} else { |
80 |
|
|
hppDout(warning, |
81 |
|
|
"Missing attribute clearance of tag " << name() << ". Assuming 0"); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
/// We have now all the information to build the handle. |
85 |
|
|
DevicePtr_t d = root()->device(); |
86 |
|
|
if (!d) { |
87 |
|
|
hppDout(error, "Failed to create gripper"); |
88 |
|
|
return; |
89 |
|
|
} |
90 |
|
|
const pinocchio::Model& model = d->model(); |
91 |
|
|
if (!model.existBodyName(linkName_)) |
92 |
|
|
throw std::invalid_argument("Link " + linkName_ + |
93 |
|
|
" not found. Cannot create gripper"); |
94 |
|
|
pinocchio::FrameIndex linkFrameId = model.getFrameId(linkName_); |
95 |
|
|
const ::pinocchio::Frame& linkFrame = model.frames[linkFrameId]; |
96 |
|
|
assert(linkFrame.type == ::pinocchio::BODY); |
97 |
|
|
// Gripper position is expressed in link frame. We need to compute |
98 |
|
|
// the position in joint frame. |
99 |
|
|
if (d->model().existFrame(gripperName, ::pinocchio::OP_FRAME)) |
100 |
|
|
throw std::runtime_error("Could not add gripper frame of gripper " + |
101 |
|
|
gripperName); |
102 |
|
|
d->model().addFrame(::pinocchio::Frame( |
103 |
|
|
gripperName, linkFrame.parent, linkFrameId, |
104 |
|
|
linkFrame.placement * localPosition_, ::pinocchio::OP_FRAME)); |
105 |
|
|
d->createData(); |
106 |
|
|
gripper_ = pinocchio::Gripper::create(gripperName, root()->device()); |
107 |
|
|
gripper_->clearance(clearance); |
108 |
|
|
d->grippers.add(gripper_->name(), gripper_); |
109 |
|
|
hppDout(info, "Add gripper " |
110 |
|
|
<< gripper_->name() << "\n\tattached to joint " |
111 |
|
|
<< d->model().names[linkFrame.parent] << " with position " |
112 |
|
|
<< gripper_->objectPositionInJoint() << "\n\tclearance " |
113 |
|
|
<< clearance); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
GripperPtr_t GripperFactory::gripper() const { return gripper_; } |
117 |
|
|
} // namespace srdf |
118 |
|
|
} // namespace manipulation |
119 |
|
|
} // namespace hpp |