Skip to content

Commit 6ff8645

Browse files
authored
Merge pull request #83 from jmirabel/devel
Clean commands
2 parents 7f75648 + 7d991eb commit 6ff8645

14 files changed

+83
-284
lines changed

src/ros_publish-python-module-py.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,10 @@ BOOST_PYTHON_MODULE(wrap)
88
{
99
bp::import("dynamic_graph");
1010

11-
dg::python::exposeEntity<dg::RosPublish, bp::bases<dg::Entity>, dg::python::AddCommands>() ;
11+
dg::python::exposeEntity<dg::RosPublish, bp::bases<dg::Entity>, dg::python::AddCommands>()
12+
.def("clear", &dg::RosPublish::clear, "Remove all signals writing data to a ROS topic")
13+
.def("rm", &dg::RosPublish::rm, "Remove a signal writing data to a ROS topic",
14+
bp::args("signal_name"))
15+
.def("list", &dg::RosPublish::list, "List signals writing data to a ROS topic")
16+
;
1217
}

src/ros_publish.cpp

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,6 @@ const double RosPublish::ROS_JOINT_STATE_PUBLISHER_RATE = 0.01;
2828

2929
namespace command {
3030
namespace rosPublish {
31-
Clear::Clear(RosPublish& entity, const std::string& docstring)
32-
: Command(entity, std::vector<Value::Type>(), docstring) {}
33-
34-
Value Clear::doExecute() {
35-
RosPublish& entity = static_cast<RosPublish&>(owner());
36-
37-
entity.clear();
38-
return Value();
39-
}
40-
41-
List::List(RosPublish& entity, const std::string& docstring)
42-
: Command(entity, std::vector<Value::Type>(), docstring) {}
43-
44-
Value List::doExecute() {
45-
RosPublish& entity = static_cast<RosPublish&>(owner());
46-
return Value(entity.list());
47-
}
4831

4932
Add::Add(RosPublish& entity, const std::string& docstring)
5033
: Command(entity, boost::assign::list_of(Value::STRING)(Value::STRING)(Value::STRING), docstring) {}
@@ -88,16 +71,6 @@ Value Add::doExecute() {
8871
return Value();
8972
}
9073

91-
Rm::Rm(RosPublish& entity, const std::string& docstring)
92-
: Command(entity, boost::assign::list_of(Value::STRING), docstring) {}
93-
94-
Value Rm::doExecute() {
95-
RosPublish& entity = static_cast<RosPublish&>(owner());
96-
std::vector<Value> values = getParameterValues();
97-
const std::string& signal = values[0].value();
98-
entity.rm(signal);
99-
return Value();
100-
}
10174
} // namespace rosPublish
10275
} // end of namespace command.
10376

@@ -143,29 +116,6 @@ RosPublish::RosPublish(const std::string& n)
143116
" - topic: the topic name in ROS.\n"
144117
"\n";
145118
addCommand("add", new command::rosPublish::Add(*this, docstring));
146-
docstring =
147-
"\n"
148-
" Remove a signal writing data to a ROS topic\n"
149-
"\n"
150-
" Input:\n"
151-
" - name of the signal to remove (see method list for the list of "
152-
"signals).\n"
153-
"\n";
154-
addCommand("rm", new command::rosPublish::Rm(*this, docstring));
155-
docstring =
156-
"\n"
157-
" Remove all signals writing data to a ROS topic\n"
158-
"\n"
159-
" No input:\n"
160-
"\n";
161-
addCommand("clear", new command::rosPublish::Clear(*this, docstring));
162-
docstring =
163-
"\n"
164-
" List signals writing data to a ROS topic\n"
165-
"\n"
166-
" No input:\n"
167-
"\n";
168-
addCommand("list", new command::rosPublish::List(*this, docstring));
169119
}
170120

171121
RosPublish::~RosPublish() { aofs_.close(); }
@@ -187,13 +137,10 @@ void RosPublish::rm(const std::string& signal) {
187137
bindedSignal_.erase(signal);
188138
}
189139

190-
std::string RosPublish::list() const {
191-
std::string result("[");
192-
for (std::map<std::string, bindedSignal_t>::const_iterator it = bindedSignal_.begin(); it != bindedSignal_.end();
193-
it++) {
194-
result += "'" + it->first + "',";
195-
}
196-
result += "]";
140+
std::vector<std::string> RosPublish::list() const {
141+
std::vector<std::string> result(bindedSignal_.size());
142+
std::transform(bindedSignal_.begin(), bindedSignal_.end(),
143+
result.begin(), [](const auto& pair) { return pair.first; });
197144
return result;
198145
}
199146

src/ros_publish.hh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ using ::dynamicgraph::command::Value;
3434
}
3535

3636
ROS_PUBLISH_MAKE_COMMAND(Add);
37-
ROS_PUBLISH_MAKE_COMMAND(Clear);
38-
ROS_PUBLISH_MAKE_COMMAND(List);
39-
ROS_PUBLISH_MAKE_COMMAND(Rm);
4037

4138
#undef ROS_PUBLISH_MAKE_COMMAND
4239

@@ -62,7 +59,7 @@ class RosPublish : public dynamicgraph::Entity {
6259

6360
void add(const std::string& signal, const std::string& topic);
6461
void rm(const std::string& signal);
65-
std::string list() const;
62+
std::vector<std::string> list() const;
6663
void clear();
6764

6865
int& trigger(int&, int);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <dynamic-graph/python/module.hh>
2+
#include "ros_queued_subscribe.hh"
3+
4+
namespace dg = dynamicgraph;
5+
6+
7+
BOOST_PYTHON_MODULE(wrap)
8+
{
9+
bp::import("dynamic_graph");
10+
11+
dg::python::exposeEntity<dg::RosQueuedSubscribe, bp::bases<dg::Entity>, dg::python::AddCommands>()
12+
.def("clear", &dg::RosQueuedSubscribe::clear, "Remove all signals reading data from a ROS topic")
13+
.def("rm", &dg::RosQueuedSubscribe::rm, "Remove a signal reading data from a ROS topic",
14+
bp::args("signal_name"))
15+
.def("list", &dg::RosQueuedSubscribe::list, "List signals reading data from a ROS topic")
16+
17+
.def("clearQueue", &dg::RosQueuedSubscribe::clearQueue,
18+
"Empty the queue of a given signal", bp::args("signal_name"))
19+
.def("queueSize", &dg::RosQueuedSubscribe::queueSize,
20+
"Return the queue size of a given signal", bp::args("signal_name"))
21+
.def("readQueue", &dg::RosQueuedSubscribe::queueSize,
22+
"Whether signals should read values from the queues, and when.",
23+
bp::args("start_time"))
24+
;
25+
}

src/ros_queued_subscribe-python.hh

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/ros_queued_subscribe.cpp

Lines changed: 4 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,6 @@ DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(RosQueuedSubscribe, "RosQueuedSubscribe");
2424

2525
namespace command {
2626
namespace rosQueuedSubscribe {
27-
Clear::Clear(RosQueuedSubscribe& entity, const std::string& docstring)
28-
: Command(entity, std::vector<Value::Type>(), docstring) {}
29-
30-
Value Clear::doExecute() {
31-
RosQueuedSubscribe& entity = static_cast<RosQueuedSubscribe&>(owner());
32-
33-
entity.clear();
34-
return Value();
35-
}
36-
37-
ClearQueue::ClearQueue(RosQueuedSubscribe& entity, const std::string& docstring)
38-
: Command(entity, boost::assign::list_of(Value::STRING), docstring) {}
39-
40-
Value ClearQueue::doExecute() {
41-
RosQueuedSubscribe& entity = static_cast<RosQueuedSubscribe&>(owner());
42-
43-
std::vector<Value> values = getParameterValues();
44-
const std::string& signal = values[0].value();
45-
entity.clearQueue(signal);
46-
47-
return Value();
48-
}
49-
50-
List::List(RosQueuedSubscribe& entity, const std::string& docstring)
51-
: Command(entity, std::vector<Value::Type>(), docstring) {}
52-
53-
Value List::doExecute() {
54-
RosQueuedSubscribe& entity = static_cast<RosQueuedSubscribe&>(owner());
55-
return Value(entity.list());
56-
}
57-
5827
Add::Add(RosQueuedSubscribe& entity, const std::string& docstring)
5928
: Command(entity, boost::assign::list_of(Value::STRING)(Value::STRING)(Value::STRING), docstring) {}
6029

@@ -84,42 +53,6 @@ Value Add::doExecute() {
8453
throw std::runtime_error("bad type");
8554
return Value();
8655
}
87-
88-
Rm::Rm(RosQueuedSubscribe& entity, const std::string& docstring)
89-
: Command(entity, boost::assign::list_of(Value::STRING), docstring) {}
90-
91-
Value Rm::doExecute() {
92-
RosQueuedSubscribe& entity = static_cast<RosQueuedSubscribe&>(owner());
93-
std::vector<Value> values = getParameterValues();
94-
const std::string& signal = values[0].value();
95-
entity.rm(signal);
96-
return Value();
97-
}
98-
99-
QueueSize::QueueSize(RosQueuedSubscribe& entity, const std::string& docstring)
100-
: Command(entity, boost::assign::list_of(Value::STRING), docstring) {}
101-
102-
Value QueueSize::doExecute() {
103-
RosQueuedSubscribe& entity = static_cast<RosQueuedSubscribe&>(owner());
104-
105-
std::vector<Value> values = getParameterValues();
106-
const std::string& signal = values[0].value();
107-
108-
return Value((unsigned)entity.queueSize(signal));
109-
}
110-
111-
ReadQueue::ReadQueue(RosQueuedSubscribe& entity, const std::string& docstring)
112-
: Command(entity, boost::assign::list_of(Value::INT), docstring) {}
113-
114-
Value ReadQueue::doExecute() {
115-
RosQueuedSubscribe& entity = static_cast<RosQueuedSubscribe&>(owner());
116-
117-
std::vector<Value> values = getParameterValues();
118-
int read = values[0].value();
119-
entity.readQueue(read);
120-
121-
return Value();
122-
}
12356
} // namespace rosQueuedSubscribe
12457
} // end of namespace command.
12558

@@ -141,53 +74,6 @@ RosQueuedSubscribe::RosQueuedSubscribe(const std::string& n)
14174
" - topic: the topic name in ROS.\n"
14275
"\n";
14376
addCommand("add", new command::rosQueuedSubscribe::Add(*this, docstring));
144-
docstring =
145-
"\n"
146-
" Remove a signal reading data from a ROS topic\n"
147-
"\n"
148-
" Input:\n"
149-
" - name of the signal to remove (see method list for the list of "
150-
"signals).\n"
151-
"\n";
152-
addCommand("rm", new command::rosQueuedSubscribe::Rm(*this, docstring));
153-
docstring =
154-
"\n"
155-
" Remove all signals reading data from a ROS topic\n"
156-
"\n"
157-
" No input:\n"
158-
"\n";
159-
addCommand("clear", new command::rosQueuedSubscribe::Clear(*this, docstring));
160-
docstring =
161-
"\n"
162-
" List signals reading data from a ROS topic\n"
163-
"\n"
164-
" No input:\n"
165-
"\n";
166-
addCommand("list", new command::rosQueuedSubscribe::List(*this, docstring));
167-
docstring =
168-
"\n"
169-
" Empty the queue of a given signal\n"
170-
"\n"
171-
" Input is:\n"
172-
" - name of the signal (see method list for the list of signals).\n"
173-
"\n";
174-
addCommand("clearQueue", new command::rosQueuedSubscribe::ClearQueue(*this, docstring));
175-
docstring =
176-
"\n"
177-
" Return the queue size of a given signal\n"
178-
"\n"
179-
" Input is:\n"
180-
" - name of the signal (see method list for the list of signals).\n"
181-
"\n";
182-
addCommand("queueSize", new command::rosQueuedSubscribe::QueueSize(*this, docstring));
183-
docstring =
184-
"\n"
185-
" Whether signals should read values from the queues, and when.\n"
186-
"\n"
187-
" Input is:\n"
188-
" - int (dynamic graph time at which the reading begin).\n"
189-
"\n";
190-
addCommand("readQueue", new command::rosQueuedSubscribe::ReadQueue(*this, docstring));
19177
}
19278

19379
RosQueuedSubscribe::~RosQueuedSubscribe() {}
@@ -206,13 +92,10 @@ void RosQueuedSubscribe::rm(const std::string& signal) {
20692
}
20793
}
20894

209-
std::string RosQueuedSubscribe::list() {
210-
std::string result("[");
211-
for (std::map<std::string, bindedSignal_t>::const_iterator it = bindedSignal_.begin(); it != bindedSignal_.end();
212-
it++) {
213-
result += "'" + it->first + "',";
214-
}
215-
result += "]";
95+
std::vector<std::string> RosQueuedSubscribe::list() {
96+
std::vector<std::string> result(bindedSignal_.size());
97+
std::transform(bindedSignal_.begin(), bindedSignal_.end(),
98+
result.begin(), [](const auto& pair) { return pair.first; });
21699
return result;
217100
}
218101

src/ros_queued_subscribe.hh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ using ::dynamicgraph::command::Value;
3838
}
3939

4040
ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(Add);
41-
ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(Clear);
42-
ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(List);
43-
ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(Rm);
44-
ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(ClearQueue);
45-
ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(QueueSize);
46-
ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND(ReadQueue);
4741

4842
#undef ROS_QUEUED_SUBSCRIBE_MAKE_COMMAND
4943

@@ -142,7 +136,7 @@ class RosQueuedSubscribe : public dynamicgraph::Entity {
142136
void display(std::ostream& os) const;
143137

144138
void rm(const std::string& signal);
145-
std::string list();
139+
std::vector<std::string> list();
146140
void clear();
147141
void clearQueue(const std::string& signal);
148142
void readQueue(int beginReadingAt);

src/ros_subscribe-python-module-py.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <dynamic-graph/python/module.hh>
2+
#include "ros_subscribe.hh"
3+
4+
namespace dg = dynamicgraph;
5+
6+
7+
BOOST_PYTHON_MODULE(wrap)
8+
{
9+
bp::import("dynamic_graph");
10+
11+
dg::python::exposeEntity<dg::RosSubscribe, bp::bases<dg::Entity>, dg::python::AddCommands>()
12+
.def("clear", &dg::RosSubscribe::clear, "Remove all signals reading data from a ROS topic")
13+
.def("rm", &dg::RosSubscribe::rm, "Remove a signal reading data from a ROS topic",
14+
bp::args("signal_name"))
15+
.def("list", &dg::RosSubscribe::list, "List signals reading data from a ROS topic")
16+
;
17+
}

src/ros_subscribe-python.hh

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)