-
Notifications
You must be signed in to change notification settings - Fork 0
/
gazebotools.cpp
80 lines (71 loc) · 2.39 KB
/
gazebotools.cpp
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
#include "gazebotools.h"
GazeboTools::GazeboTools(QObject *parent)
: QObject(parent)
{
m_portName = "/OcraGui/OcraGuiPlugin/rpc:o";
m_pluginPortName = "/Gazebo/OcraGuiPlugin/rpc:i";
m_port.open(m_portName);
conMon = new ConnectionMonitor(m_portName, m_pluginPortName);
connect(conMon, SIGNAL(connected()), this, SLOT(getRobotWorldPoseInternal()) );
}
GazeboTools::~GazeboTools()
{
}
void GazeboTools::addTaskFrames(const std::string& taskName)
{
if(conMon->isConnected()) {
yarp::os::Bottle request, reply;
request.addString("addTaskFrames");
request.addString(taskName);
m_port.write(request, reply);
if(reply.get(0).asBool()){
emit showUserMessage(reply.get(1).asString(), INFO);
} else {
emit showUserMessage(reply.get(1).asString(), ERROR);
}
} else {
emit showUserMessage("Not connected to Gazebo.", ERROR);
}
}
void GazeboTools::removeTaskFrames(const std::string& taskName)
{
if(conMon->isConnected()) {
yarp::os::Bottle request, reply;
request.addString("removeTaskFrames");
request.addString(taskName);
m_port.write(request, reply);
if(reply.get(0).asBool()){
emit showUserMessage(reply.get(1).asString(), INFO);
} else {
emit showUserMessage(reply.get(1).asString(), ERROR);
}
} else {
emit showUserMessage("Not connected to Gazebo.", ERROR);
}
}
void GazeboTools::sendRobotWorldPose()
{
emit newRobotWorldPose(robotWorldPose);
}
void GazeboTools::getRobotWorldPoseInternal()
{
if(conMon->isConnected()) {
yarp::os::Bottle request, reply;
request.addString("getRobotWorldPose");
m_port.write(request, reply);
robotWorldPose = Eigen::Displacementd(reply.get(0).asDouble(),reply.get(1).asDouble(),reply.get(2).asDouble(),reply.get(3).asDouble(),reply.get(4).asDouble(),reply.get(5).asDouble(),reply.get(6).asDouble());
if(reply.get(7).asBool()){
emit showUserMessage(reply.get(8).asString(), INFO);
emit newRobotWorldPose(robotWorldPose);
} else {
emit showUserMessage(reply.get(8).asString(), ERROR);
}
} else {
emit showUserMessage("Not connected to Gazebo.", ERROR);
}
}
Eigen::Displacementd GazeboTools::getRobotWorldPose()
{
getRobotWorldPoseInternal();
return robotWorldPose;
}