Skip to content

Commit

Permalink
Check joint type
Browse files Browse the repository at this point in the history
  • Loading branch information
lrapetti committed Jan 28, 2020
1 parent 6917e05 commit 99485d1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
#include <LinkAttacherServer.h>

const std::string LogPrefix = "LinkAttacher:";
// available joint types in SDF (http://sdformat.org/spec?ver=1.6&elem=joint#joint_type)
// with the exception of gearbox joint
const std::vector<std::string> jointTypes { "revolute", "revolute2",
"prismatic", "ball", "screw",
"universal", "fixed"};

class LinkAttacherServerImpl: public GazeboYarpPlugins::LinkAttacherServer
{
Expand Down Expand Up @@ -74,10 +79,7 @@ class LinkAttacherServerImpl: public GazeboYarpPlugins::LinkAttacherServer
_model=p;
}

void setJointType(const std::string j)
{
jointType=j;
}
bool setJointType(const std::string j);

};

Expand Down
6 changes: 5 additions & 1 deletion plugins/linkattacher/src/linkattacher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ void LinkAttacher::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
{
jointType="fixed";
}
m_la_server.setJointType(jointType);

if(!m_la_server.setJointType(jointType))
{
return;
}

std::string portname;
if(m_parameters.check("name"))
Expand Down
20 changes: 20 additions & 0 deletions plugins/linkattacher/src/linkattacherserverimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

#include <linkattacherserverimpl.h>

#include <algorithm>
#include <vector>

using namespace gazebo;
using namespace std;
using namespace yarp::os;
Expand Down Expand Up @@ -100,6 +103,8 @@ bool LinkAttacherServerImpl::attachUnscoped(const string& parent_model_name, con
joint = _world->GetPhysicsEngine()->CreateJoint(jointType,parent_model);
#endif

yInfo() << "joint created!";

if(!joint)
{
yError() << LogPrefix << "Attach: Unable to create joint";
Expand Down Expand Up @@ -214,3 +219,18 @@ bool LinkAttacherServerImpl::enableGravity(const string& model_name, const bool

return true;
}

bool LinkAttacherServerImpl::setJointType(const std::string j)
{
if(std::find(jointTypes.begin(), jointTypes.end(), j) != jointTypes.end())
{
jointType=j;
}
else
{
yError() << LogPrefix << "the choosen joint type [" << j << "] is not valid";
return false;
}

return true;
}

0 comments on commit 99485d1

Please sign in to comment.