Newer
Older
#include <stdexcept>
#include <boost/assign.hpp>
#include <boost/bind.hpp>
#include <boost/format.hpp>
#include <boost/function.hpp>
#include <boost/make_shared.hpp>
#include <ros/ros.h>
#include <std_msgs/Float64.h>
#include <dynamic-graph/factory.h>
#include "ros_import.hh"
namespace dynamicgraph
{
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(RosImport, "RosImport");
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
namespace command
{
namespace rosImport
{
Clear::Clear
(RosImport& entity, const std::string& docstring)
: Command
(entity,
std::vector<Value::Type> (),
docstring)
{}
Value Clear::doExecute ()
{
RosImport& entity =
static_cast<RosImport&> (owner ());
entity.clear ();
return Value ();
}
List::List
(RosImport& entity, const std::string& docstring)
: Command
(entity,
std::vector<Value::Type> (),
docstring)
{}
Value List::doExecute ()
{
RosImport& entity =
static_cast<RosImport&> (owner ());
entity.list ();
return Value ();
}
Add::Add
(RosImport& entity, const std::string& docstring)
: Command
(entity,
boost::assign::list_of
(Value::STRING) (Value::STRING) (Value::STRING),
docstring)
{}
Value Add::doExecute ()
{
RosImport& entity =
static_cast<RosImport&> (owner ());
std::vector<Value> values = getParameterValues ();
const std::string& type = values[0].value ();
const std::string& signal = values[1].value ();
const std::string& topic = values[2].value ();
if (type == "double")
entity.add<double> (signal, topic);
else if (type == "matrix")
entity.add<ml::Matrix> (signal, topic);
else if (type == "vector")
entity.add<ml::Vector> (signal, topic);
else
throw std::runtime_error("bad type");
return Value ();
}
Rm::Rm
(RosImport& entity, const std::string& docstring)
: Command
(entity,
boost::assign::list_of (Value::STRING),
docstring)
{}
Value Rm::doExecute ()
{
RosImport& entity =
static_cast<RosImport&> (owner ());
std::vector<Value> values = getParameterValues ();
const std::string& signal = values[0].value ();
entity.rm (signal);
return Value ();
}
} // end of errorEstimator.
} // end of namespace command.
const char* rosInit()
{
int argc = 1;
char* arg0 = strdup("ros_import");
char* argv[] = {arg0, 0};
ros::init(argc, argv, "ros_import");
free (arg0);
return "dynamic_graph";
}
RosImport::RosImport (const std::string& n)
: dynamicgraph::Entity(n),
nh_ (rosInit ()),
bindedSignal_ ()
{
std::string docstring;
addCommand ("add",
new command::rosImport::Add
(*this, docstring));
addCommand ("rm",
new command::rosImport::Rm
(*this, docstring));
addCommand ("clear",
new command::rosImport::Clear
(*this, docstring));
addCommand ("list",
new command::rosImport::List
(*this, docstring));
}
RosImport::~RosImport ()
{
}
void RosImport::display (std::ostream& os) const
{
os << CLASS_NAME << std::endl;
}