Commit f2644c41 authored by florent's avatar florent
Browse files

Implement set and get signal value

	  * src/dynamic-graph-py.cc,
	  * src/dynamic_graph/signal_base.py,
	  * src/signal-base-py.cc.
parent 0d1cc4e3
......@@ -19,6 +19,8 @@ namespace dynamicgraph {
namespace signalBase {
extern PyObject* create(PyObject* self, PyObject* args);
extern PyObject* getTime(PyObject* self, PyObject* args);
extern PyObject* getValue(PyObject* self, PyObject* args);
extern PyObject* setValue(PyObject* self, PyObject* args);
}
namespace entity {
extern PyObject* create(PyObject* self, PyObject* args);
......@@ -99,6 +101,10 @@ static PyMethodDef dynamicGraphMethods[] = {
"create a SignalBase C++ object"},
{"signalbase_get_time", dynamicgraph::python::signalBase::getTime,
METH_VARARGS, "Get time of a SignalBase"},
{"signal_base_get_value", dynamicgraph::python::signalBase::getValue,
METH_VARARGS, "Read the value of a signal"},
{"signal_base_set_value", dynamicgraph::python::signalBase::setValue,
METH_VARARGS, "Set the value of a signal"},
// Entity
{"create_entity", dynamicgraph::python::entity::create, METH_VARARGS,
"create an Entity C++ object"},
......
......@@ -29,3 +29,17 @@ class SignalBase:
"""
return wrap.signalBaseGetTime(self.object)
@property
def value(self) :
"""
Read the value of a signal
"""
return wrap.signal_base_get_value(self.object)
@value.setter
def value(self) :
"""
Set the signal as a constant signal with given value.
If the signal is plugged, it will be unplugged
"""
return wrap.signal_base_set_value(self.object, value)
......@@ -5,8 +5,7 @@
#include <Python.h>
#include <iostream>
//#include <sstream>
//#include <string>
#include <sstream>
#include <dynamic-graph/signal-base.h>
......@@ -27,17 +26,17 @@ namespace dynamicgraph {
PyObject* create(PyObject* self, PyObject* args)
{
char *name = NULL;
if (!PyArg_ParseTuple(args, "s", &name))
return NULL;
SignalBase<int>* obj = NULL;
obj = new SignalBase<int>(std::string(name));
// Return the pointer
return PyCObject_FromVoidPtr((void*)obj, destroy);
}
/**
\brief Destroy an instance of InvertedPendulum
*/
......@@ -46,7 +45,7 @@ namespace dynamicgraph {
SignalBase<int>* obj = (SignalBase<int>*)self;
delete obj;
}
PyObject* getTime(PyObject* self, PyObject* args)
{
void* pointer = NULL;
......@@ -58,10 +57,46 @@ namespace dynamicgraph {
pointer = PyCObject_AsVoidPtr(object);
SignalBase<int>* obj = (SignalBase<int>*)pointer;
int time = obj->getTime();
return Py_BuildValue("i", time);
}
PyObject* getValue(PyObject* self, PyObject* args)
{
void* pointer = NULL;
PyObject* object = NULL;
if (!PyArg_ParseTuple(args,"O", &object))
return NULL;
if (!PyCObject_Check(object))
return NULL;
pointer = PyCObject_AsVoidPtr(object);
SignalBase<int>* signal = (SignalBase<int>*)pointer;
std::ostringstream value;
signal->get(value);
return Py_BuildValue("s", value.str());
}
PyObject* setValue(PyObject* self, PyObject* args)
{
void * pointer = NULL;
PyObject* object = NULL;
char* valueString = NULL;
if (!PyArg_ParseTuple(args,"Os", &object, &valueString))
return NULL;
if (!PyCObject_Check(object))
return NULL;
pointer = PyCObject_AsVoidPtr(object);
SignalBase<int>* signal = (SignalBase<int>*)pointer;
std::istringstream value(valueString);
signal->set(value);
return Py_BuildValue("");
}
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment