Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ostasse/dynamic-graph-python
  • gsaurel/dynamic-graph-python
  • stack-of-tasks/dynamic-graph-python
3 results
Show changes
Showing
with 665 additions and 640 deletions
/*
* Copyright 2010,
* François Bleibel,
* Olivier Stasse,
*
* CNRS/AIST
*
* This file is part of dynamic-graph.
* dynamic-graph is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* dynamic-graph is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
*/
#include <dynamic-graph/python/exception-python.hh>
#include <dynamic-graph/debug.h>
#include <stdarg.h>
#include <cstdio>
namespace dynamicgraph {
namespace python {
/* --------------------------------------------------------------------- */
/* --- CLASS ----------------------------------------------------------- */
/* --------------------------------------------------------------------- */
const std::string ExceptionPython::EXCEPTION_NAME = "Python";
ExceptionPython::
ExceptionPython ( const ExceptionPython::ErrorCodeEnum& errcode,
const std::string & msg )
:ExceptionAbstract(errcode,msg)
{
dgDEBUGF( 15,"Created with message <%s>.",msg.c_str ());
dgDEBUG( 1) <<"Created with message <%s>."<<msg<<std::endl;
}
ExceptionPython::
ExceptionPython ( const ExceptionPython::ErrorCodeEnum& errcode,
const std::string & msg,const char* format, ... )
:ExceptionAbstract(errcode,msg)
{
va_list args;
va_start(args,format);
const unsigned int SIZE = 256;
char buffer[SIZE];
vsnprintf(buffer,SIZE,format,args);
dgDEBUG(15) <<"Created "<<" with message <"
<<msg<<"> and buffer <"<<buffer<<">. "<<std::endl;
message += buffer;
va_end(args);
dgDEBUG(1) << "Throw exception " << EXCEPTION_NAME << "[#" << errcode<<"]: "
<<"<"<< message << ">."<<std::endl;
}
} // namespace dynamicgraph
} // namespace python
/*
* Local variables:
* c-basic-offset: 2
* End:
*/
// Copyright 2010, Florent Lamiraux, Thomas Moulard, LAAS-CNRS.
//
// This file is part of dynamic-graph-python.
// dynamic-graph-python is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either
// version 3 of the License, or (at your option) any later version.
//
// dynamic-graph-python is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Lesser Public License for more details. You should
// have received a copy of the GNU Lesser General Public License along
// with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
#include <Python.h>
#include <iostream>
#include <dynamic-graph/factory.h>
using dynamicgraph::Entity;
using dynamicgraph::ExceptionAbstract;
namespace dynamicgraph {
namespace python {
namespace factory {
/**
\brief Get name of entity
*/
PyObject* getEntityClassList(PyObject* /*self*/, PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
return NULL;
std::vector <std::string> classNames;
dynamicgraph::g_factory.listEntities(classNames);
unsigned int classNumber = classNames.size();
// Build a tuple object
PyObject* classTuple = PyTuple_New(classNumber);
for (unsigned int iEntity = 0; iEntity < classNames.size(); iEntity++) {
PyObject* className = Py_BuildValue("s", classNames[iEntity].c_str());
PyTuple_SetItem(classTuple, iEntity, className);
}
return Py_BuildValue("O", classTuple);
}
} // namespace factory
} // namespace python
} // namespace dynamicgraph
This diff is collapsed.
// -*- mode: c++ -*-
// Copyright 2011, Florent Lamiraux, CNRS.
//
// This file is part of dynamic-graph-python.
// dynamic-graph is free software: you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// dynamic-graph is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
#ifdef WIN32
#include <Windows.h>
#else
#include <dlfcn.h>
#endif
namespace dynamicgraph {
namespace python {
std::string libpython("@PYTHON_LIBRARY@");
} // namespace python
} // namespace dynamicgraph
// Copyright 2010, Florent Lamiraux, Thomas Moulard, LAAS-CNRS.
//
// This file is part of dynamic-graph-python.
// dynamic-graph-python is free software: you can redistribute it
// and/or modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation, either
// version 3 of the License, or (at your option) any later version.
//
// dynamic-graph-python is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Lesser Public License for more details. You should
// have received a copy of the GNU Lesser General Public License along
// with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
#include <Python.h>
#include <iostream>
#include <sstream>
#include <dynamic-graph/signal-base.h>
#include <dynamic-graph/signal.h>
#include <dynamic-graph/signal-caster.h>
#include <dynamic-graph/linear-algebra.h>
#include <../src/convert-dg-to-py.hh>
using dynamicgraph::SignalBase;
namespace dynamicgraph {
namespace python {
extern PyObject* dgpyError;
using namespace convert;
namespace signalBase {
static void destroy (void* self);
/**
\brief Create an instance of SignalBase
*/
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
*/
static void destroy (void* self)
{
SignalBase<int>* obj = (SignalBase<int>*)self;
delete obj;
}
PyObject* getTime(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>* obj = (SignalBase<int>*)pointer;
int time = obj->getTime();
return Py_BuildValue("i", time);
}
PyObject* setTime(PyObject* /*self*/, PyObject* args)
{
void* pointer = NULL;
PyObject* object = NULL;
int time;
if (!PyArg_ParseTuple(args,"Oi", &object, &time))
return NULL;
if (!PyCObject_Check(object)) {
PyErr_SetString(dgpyError, "object should be a C object");
return NULL;
}
pointer = PyCObject_AsVoidPtr(object);
SignalBase<int>* obj = (SignalBase<int>*)pointer;
obj->setTime(time);
return Py_BuildValue("");
}
PyObject* display(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>* obj = (SignalBase<int>*)pointer;
std::ostringstream oss;
try {
obj->display(oss);
} catch (const std::exception& exc) {
PyErr_SetString(dgpyError, exc.what());
return NULL;
}
return Py_BuildValue("s", oss.str().c_str());
}
PyObject* displayDependencies(PyObject* /*self*/, PyObject* args)
{
void* pointer = NULL;
PyObject* object = NULL;
int time;
if (!PyArg_ParseTuple(args,"OI", &object,&time))
return NULL;
if (!PyCObject_Check(object))
return NULL;
pointer = PyCObject_AsVoidPtr(object);
SignalBase<int>* obj = (SignalBase<int>*)pointer;
std::ostringstream oss;
try {
obj->displayDependencies(oss,time);
} catch (const std::exception& exc) {
PyErr_SetString(dgpyError, exc.what());
return NULL;
}
return Py_BuildValue("s", oss.str().c_str());
}
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;
/* Temptative for specific signal type. */
Signal<dynamicgraph::Vector,int> * sigvec
= dynamic_cast< Signal<dynamicgraph::Vector,int>* >( signal );
if( NULL!= sigvec )
{
return vectorToPython( sigvec->accessCopy() );
}
Signal<dynamicgraph::Matrix,int> * sigmat
= dynamic_cast< Signal<dynamicgraph::Matrix,int>* >( signal );
if( NULL!= sigmat )
{
return matrixToPython( sigmat->accessCopy() );
}
Signal<double,int> * sigdouble
= dynamic_cast< Signal<double,int>* >( signal );
if( NULL!= sigdouble )
{
return Py_BuildValue("d", sigdouble->accessCopy() );
}
/* Non specific signal: use a generic way. */
std::ostringstream value;
try {
signal->get(value);
} catch (const std::exception& exc) {
PyErr_SetString(dgpyError, exc.what());
return NULL;
} catch (...) {
PyErr_SetString(dgpyError, "Unknown exception");
return NULL;
}
std::string valueString = value.str();
return Py_BuildValue("s", valueString.c_str());
}
PyObject* getName(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::string name;
try {
name = signal->getName();
} catch (const std::exception& exc) {
PyErr_SetString(dgpyError, exc.what());
return NULL;
} catch (...) {
PyErr_SetString(dgpyError, "Unknown exception");
return NULL;
}
return Py_BuildValue("s", name.c_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::ostringstream os;
os << valueString;
std::istringstream value(os.str());
try {
signal->set(value);
} catch (const std::exception& exc) {
PyErr_SetString(dgpyError, exc.what());
return NULL;
} catch (...) {
PyErr_SetString(dgpyError, "Unknown exception");
return NULL;
}
return Py_BuildValue("");
}
PyObject* recompute(PyObject* /*self*/, PyObject* args)
{
void * pointer = NULL;
PyObject* object = NULL;
unsigned int time;
if (!PyArg_ParseTuple(args,"OI", &object, &time))
return NULL;
if (!PyCObject_Check(object))
return NULL;
pointer = PyCObject_AsVoidPtr(object);
SignalBase<int>* signal = (SignalBase<int>*)pointer;
try {
signal->recompute(time);
} catch (const std::exception& exc) {
PyErr_SetString(dgpyError, exc.what());
return NULL;
}
return Py_BuildValue("");
}
PyObject* unplug(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;
try {
signal->unplug();
} catch (const std::exception& exc) {
PyErr_SetString(dgpyError, exc.what());
return NULL;
}
return Py_BuildValue("");
}
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include "custom_entity.h"
typedef boost::mpl::vector<dynamicgraph::CustomEntity> entities_t;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/*
* Copyright
*/
#include "dynamic-graph-python-test.hh"
int main(int argc, char** argv) { GraphTest testGraph(); }
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.