Skip to content

Commit 1650c8f

Browse files
committed
Commit to be squashed and fixed
1 parent 4eaac18 commit 1650c8f

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

src/creo2urdf/include/creo2urdf/Utils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ std::pair<bool, iDynTree::Transform> getTransformFromPart(pfcModel_ptr modelhdl,
439439
* @param scale The scaling factor for the origin of the child frame
440440
* @return std::pair<bool, iDynTree::Direction> Pair containing a success/failure flag, and the axis direction
441441
*/
442-
std::tuple<bool, iDynTree::Direction, iDynTree::Position> getAxisFromPart(pfcModel_ptr modelhdl, const std::string& axis_name, const std::string& link_frame_name, const array<double, 3>& scale);
442+
std::tuple<bool, iDynTree::Direction, iDynTree::Transform> getAxisFromPart(pfcModel_ptr modelhdl, const std::string& axis_name, const std::string& link_frame_name, const array<double, 3>& scale);
443443

444444
/**
445445
* @brief Extracts the folder path from a file path.

src/creo2urdf/src/Creo2Urdf.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,11 @@ void Creo2Urdf::OnCommand() {
267267
if (joint_info.second.type == JointType::Revolute || joint_info.second.type == JointType::Linear) {
268268

269269
iDynTree::Direction axis;
270-
iDynTree::Position axis_offset;
271-
std::tie(ret, axis, axis_offset) = getAxisFromPart(parent_model, axis_name, parent_link_frame, scale);
270+
iDynTree::Transform oldChild_H_newChild;
271+
std::tie(ret, axis, oldChild_H_newChild) = getAxisFromPart(parent_model, axis_name, parent_link_frame, scale);
272+
273+
274+
parent_H_child = parent_H_child * oldChild_H_newChild;
272275

273276
if (!ret && warningsAreFatal)
274277
{
@@ -283,32 +286,29 @@ void Creo2Urdf::OnCommand() {
283286

284287
auto urdf_child_link_name = getRenameElementFromConfig(child_link_name);
285288

289+
printToMessageWindow("joint " + urdf_child_link_name);
290+
286291
// THIS IS NOT HAVING EFFECT
287-
/*auto link_H_collision_solid_shape = idyn_model.collisionSolidShapes().getLinkSolidShapes()[idyn_model.getLinkIndex(urdf_child_link_name)][0]->getLink_H_geometry();
292+
auto link_H_collision_solid_shape = idyn_model.collisionSolidShapes().getLinkSolidShapes()[idyn_model.getLinkIndex(urdf_child_link_name)][0]->getLink_H_geometry();
288293
auto link_H_visual_solid_shape = idyn_model.visualSolidShapes().getLinkSolidShapes()[idyn_model.getLinkIndex(urdf_child_link_name)][0]->getLink_H_geometry();
289294

290-
link_H_collision_solid_shape.setPosition(link_H_collision_solid_shape.getPosition() - axis_offset);
291-
link_H_visual_solid_shape.setPosition(link_H_visual_solid_shape.getPosition() - axis_offset);
295+
printToMessageWindow("BEFORE link_H_collision_solid_shape " + link_H_visual_solid_shape.toString());
292296

293-
idyn_model.collisionSolidShapes().getLinkSolidShapes()[idyn_model.getLinkIndex(urdf_child_link_name)][0]->setLink_H_geometry(link_H_collision_solid_shape);
294-
idyn_model.visualSolidShapes().getLinkSolidShapes()[idyn_model.getLinkIndex(urdf_child_link_name)][0]->setLink_H_geometry(link_H_visual_solid_shape);
297+
idyn_model.collisionSolidShapes().getLinkSolidShapes()[idyn_model.getLinkIndex(urdf_child_link_name)][0]->setLink_H_geometry(oldChild_H_newChild.inverse() * link_H_collision_solid_shape);
298+
idyn_model.visualSolidShapes().getLinkSolidShapes()[idyn_model.getLinkIndex(urdf_child_link_name)][0]->setLink_H_geometry(oldChild_H_newChild.inverse() * link_H_visual_solid_shape);
295299

300+
link_H_visual_solid_shape = idyn_model.visualSolidShapes().getLinkSolidShapes()[idyn_model.getLinkIndex(urdf_child_link_name)][0]->getLink_H_geometry();
301+
printToMessageWindow("AFTER link_H_collision_solid_shape " + link_H_visual_solid_shape.toString());
296302

297-
parent_H_child.setPosition(parent_H_child.getPosition() + axis_offset);
298-
*/
299-
300-
301-
// I need to rotate the axis offset by the parent_H_child rotation ????
302-
//axis_offset = parent_H_child.getRotation() * axis_offset;
303303

304304
std::shared_ptr<iDynTree::IJoint> joint_sh_ptr;
305305
if (joint_info.second.type == JointType::Revolute) {
306306
joint_sh_ptr = std::make_shared<iDynTree::RevoluteJoint>();
307-
dynamic_cast<iDynTree::RevoluteJoint*>(joint_sh_ptr.get())->setAxis(iDynTree::Axis(axis, parent_H_child.getPosition() + axis_offset));
307+
dynamic_cast<iDynTree::RevoluteJoint*>(joint_sh_ptr.get())->setAxis(iDynTree::Axis(axis, parent_H_child.getPosition()));
308308
}
309309
else if (joint_info.second.type == JointType::Linear) {
310310
joint_sh_ptr = std::make_shared<iDynTree::PrismaticJoint>();
311-
dynamic_cast<iDynTree::PrismaticJoint*>(joint_sh_ptr.get())->setAxis(iDynTree::Axis(axis, parent_H_child.getPosition() + axis_offset));
311+
dynamic_cast<iDynTree::PrismaticJoint*>(joint_sh_ptr.get())->setAxis(iDynTree::Axis(axis, parent_H_child.getPosition()));
312312
}
313313

314314
joint_sh_ptr->setRestTransform(parent_H_child);

src/creo2urdf/src/Utils.cpp

+9-11
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,21 @@ std::pair<bool, iDynTree::Transform> getTransformFromPart(pfcModel_ptr modelhdl,
172172
return { false, H_child };
173173
}
174174

175-
std::tuple<bool, iDynTree::Direction, iDynTree::Position> getAxisFromPart(pfcModel_ptr modelhdl, const std::string& axis_name, const string& link_frame_name, const array<double, 3>& scale) {
175+
std::tuple<bool, iDynTree::Direction, iDynTree::Transform> getAxisFromPart(pfcModel_ptr modelhdl, const std::string& axis_name, const string& link_frame_name, const array<double, 3>& scale) {
176176

177177
iDynTree::Direction axis_unit_vector;
178-
iDynTree::Position axis_offset;
179-
axis_offset.zero();
178+
iDynTree::Transform oldChild_H_newChild = iDynTree::Transform::Identity();
180179
axis_unit_vector.zero();
181180

182181
auto axes_list = modelhdl->ListItems(pfcModelItemType::pfcITEM_AXIS);
183182
if (axes_list->getarraysize() == 0) {
184183
printToMessageWindow("There is no Axis in the part " + string(modelhdl->GetFullName()), c2uLogLevel::WARN);
185184

186-
return { false, axis_unit_vector, axis_offset };
185+
return { false, axis_unit_vector, oldChild_H_newChild };
187186
}
188187

189188
if (axis_name.empty())
190-
return { false, axis_unit_vector, axis_offset };
189+
return { false, axis_unit_vector, oldChild_H_newChild };
191190

192191
pfcAxis* axis = nullptr;
193192

@@ -208,11 +207,11 @@ std::tuple<bool, iDynTree::Direction, iDynTree::Position> getAxisFromPart(pfcMod
208207
// We use the medium point of the axis as offset
209208
pfcPoint3D_ptr pstart = axis_line->GetEnd1();
210209
pfcPoint3D_ptr pend = axis_line->GetEnd2();
211-
axis_offset[0] = ((pend->get(0) + pstart->get(0)) / 2.0) * scale[0];
212-
axis_offset[1] = ((pend->get(1) + pstart->get(1)) / 2.0) * scale[1];
213-
axis_offset[2] = ((pend->get(2) + pstart->get(2)) / 2.0) * scale[2];
210+
auto x = ((pend->get(0) + pstart->get(0)) / 2.0) * scale[0];
211+
auto y = ((pend->get(1) + pstart->get(1)) / 2.0) * scale[1];
212+
auto z = ((pend->get(2) + pstart->get(2)) / 2.0) * scale[2];
213+
oldChild_H_newChild.setPosition({ x, y, z });
214214

215-
printToMessageWindow("Axis offset: " + axis_offset.toString());
216215
}
217216

218217
// There are just two points in the array
@@ -227,12 +226,11 @@ std::tuple<bool, iDynTree::Direction, iDynTree::Position> getAxisFromPart(pfcMod
227226

228227

229228
auto& csys_H_child = getTransformFromPart(modelhdl, link_frame_name, scale).second;
230-
printToMessageWindow("csys_H_child: " + csys_H_child.toString());
231229

232230
axis_unit_vector = csys_H_child.inverse() * axis_unit_vector; // We might benefit from performing this operation directly in Creo
233231
axis_unit_vector.Normalize();
234232

235-
return { true, axis_unit_vector, axis_offset };
233+
return { true, axis_unit_vector, oldChild_H_newChild };
236234
}
237235

238236
std::string extractFolderPath(const std::string& filePath) {

0 commit comments

Comments
 (0)