-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathlinkattacher.cc
118 lines (99 loc) · 3.7 KB
/
linkattacher.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Copyright (C) 2013-2015 Fondazione Istituto Italiano di Tecnologia RBCS & iCub Facility & ADVR
* Authors: see AUTHORS file.
* CopyPolicy: Released under the terms of the LGPLv2.1 or any later version, see LGPL.TXT or LGPL3.TXT
*/
#include <linkattacher.hh>
using namespace gazebo;
using namespace std;
using namespace yarp::os;
LinkAttacher::LinkAttacher()
{
}
LinkAttacher::~LinkAttacher()
{
if(m_rpcport)
{
m_rpcport->close();
}
}
void LinkAttacher::Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
{
if(m_network != 0)
{
return;
}
m_network = std::unique_ptr<yarp::os::Network>(new yarp::os::Network());
if(!yarp::os::Network::checkNetwork(GazeboYarpPlugins::yarpNetworkInitializationTimeout))
{
yError() << LogPrefix << "Load: yarp network does not seem to be available, is the yarpserver running?";
return;
}
std::string model_name = _model->GetName();
yInfo() << LogPrefix << "Load: Model name: " << model_name;
m_la_server.attachWorldPointer(_model->GetWorld());
m_la_server.attachModelPointer(_model);
// Getting .ini configuration file parameters from sdf
bool configuration_loaded = GazeboYarpPlugins::loadConfigModelPlugin(_model, _sdf, m_parameters);
if (!configuration_loaded)
{
yError() << LogPrefix << " File .ini not found, load failed." ;
return;
}
std::string jointType;
if(m_parameters.check("jointType"))
{
jointType = m_parameters.find("jointType").asString();
}
else
{
jointType="fixed";
}
if(!m_la_server.setJointType(jointType))
{
return;
}
std::string portname;
if(m_parameters.check("name"))
{
portname = m_parameters.find("name").asString();
}
else
{
yError() << LogPrefix << " <name> parameter missing in the configuration file";
return;
}
m_rpcport = std::unique_ptr<yarp::os::RpcServer>(new yarp::os::RpcServer());
if(!m_rpcport->open(portname))
{
yError() << LogPrefix << " failed to open rpcserver port";
return;
}
if(m_parameters.check("STARTUP"))
{
yarp::os::Bottle startupConfig = m_parameters.findGroup("STARTUP");
for(size_t i=1; i<startupConfig.size(); i++)
{
if(startupConfig.get(i).check("attachUnscoped") && startupConfig.get(i).find("attachUnscoped").isList() && startupConfig.get(i).find("attachUnscoped").asList()->size()==4)
{
yarp::os::Bottle* attachConfigList = startupConfig.get(i).find("attachUnscoped").asList();
m_la_server.attachUnscoped(attachConfigList->get(0).asString(), attachConfigList->get(1).asString(), attachConfigList->get(2).asString(), attachConfigList->get(3).asString());
}
else if(startupConfig.get(i).check("detachUnscoped") && startupConfig.get(i).find("detachUnscoped").isList() && startupConfig.get(i).find("detachUnscoped").asList()->size()==2)
{
yarp::os::Bottle* detachConfigList = startupConfig.get(i).find("detachUnscoped").asList();
m_la_server.detachUnscoped(detachConfigList->get(0).asString(), detachConfigList->get(1).asString());
}
else if(startupConfig.get(i).check("enableGravity") && startupConfig.get(i).find("enableGravity").isList() && startupConfig.get(i).find("enableGravity").asList()->size()==2)
{
yarp::os::Bottle* enableGravityConfigList = startupConfig.get(i).find("enableGravity").asList();
m_la_server.enableGravity(enableGravityConfigList->get(0).asString(), enableGravityConfigList->get(1).asBool());
}
else
{
yWarning() << LogPrefix << "Failed to load startup configuration line [" << i << "]";
}
}
}
m_la_server.yarp().attachAsServer(*m_rpcport);
}