diff --git a/src/liboncilla/Oncilla.cpp b/src/liboncilla/Oncilla.cpp index b559930..0c16bdb 100644 --- a/src/liboncilla/Oncilla.cpp +++ b/src/liboncilla/Oncilla.cpp @@ -1,123 +1,109 @@ /* * Oncilla.cpp * * Created on: 15 dec. 2011 * Author: Alexandre Tuleu, Arne Nordmann */ #include "Oncilla.h" #include namespace rci { namespace oncilla { OncillaSynchronizerPtr Oncilla::s_synchronizer; Oncilla::LegNames Oncilla::s_legNames; const std::string & Oncilla::nameOfLeg(Leg l){ if(s_legNames.empty()){ s_legNames.push_back("Left Fore"); s_legNames.push_back("Right Fore"); s_legNames.push_back("Left Hind"); s_legNames.push_back("Right Hind"); s_legNames.push_back("Undefined"); } if(l >= NUM_LEGS){ return s_legNames.back(); } return s_legNames[l]; } Oncilla::Oncilla(){ if(!s_synchronizer){ if(!d_backend){ BackendLoader bl; //we have to keep alive the pointer or dlclose() will be called once //We free him. Or we could add BackendLoader as a member of Oncilla // I prefer only to have the Object creator interface. d_backend = bl.SuitableBackend(); } s_synchronizer = d_backend->CreateSynchronizer(); init(); } } Oncilla::~Oncilla() { } -#define CREATE_NODES(LegName)do{\ - d_L0s.push_back(L0::Ptr(new L0(LegName " Oncilla L0" )));\ - d_L1s.push_back(L1::Ptr(new L1(*s_synchronizer,\ - LegName " Oncilla L1")));\ - d_L2s.push_back(L2::Ptr(new L2(*s_synchronizer,\ - LegName " Oncilla L2")));\ - d_L3s.push_back(L3::Ptr(new L3(LegName " Oncilla L3")));\ +#define CREATE_NODES(LegName,Leg)do{\ + d_L0s.push_back(L0::Ptr(d_backend->CreateL0(Leg,LegName " Oncilla L0" )));\ + d_L1s.push_back(L1::Ptr(d_backend->CreateL1(Leg,\ + LegName " Oncilla L1")));\ + d_L2s.push_back(L2::Ptr(d_backend->CreateL2(Leg,\ + LegName " Oncilla L2")));\ + d_L3s.push_back(L3::Ptr(d_backend->CreateL3(Leg,LegName " Oncilla L3")));\ }while(0) -#define REGISTER_NODES(Type)do{\ - for(std::vector < Type::Ptr >::const_iterator n = d_ ## Type ## s.begin();\ - n != d_ ## Type ## s.end();\ - ++n){\ - Leg l = static_cast(n - d_ ## Type ## s.begin());\ - s_synchronizer->register ## Type ## Node(l,*n);\ - }\ -}while(0) void Oncilla::init() { d_L0s.reserve(4); d_L1s.reserve(4); d_L2s.reserve(4); d_L3s.reserve(4); - CREATE_NODES("Left Fore"); - CREATE_NODES("Right Fore"); - CREATE_NODES("Left Hind"); - CREATE_NODES("Right Hind"); + CREATE_NODES("Left Fore",LEFT_FORE); + CREATE_NODES("Right Fore",RIGHT_FORE); + CREATE_NODES("Left Hind",LEFT_HIND); + CREATE_NODES("Right Hind",RIGHT_HIND); d_trunk = Trunk::Ptr(new Trunk("Oncilla Trunk")); - REGISTER_NODES(L0); - REGISTER_NODES(L1); - REGISTER_NODES(L2); - REGISTER_NODES(L3); - s_synchronizer->registerTrunkNode(d_trunk); - } const L0::Ptr & Oncilla::getL0(Leg l) const { return this->d_L0s[l]; } const L1::Ptr & Oncilla::getL1(Leg l) const { return this->d_L1s[l]; } const L2::Ptr & Oncilla::getL2(Leg l) const { return this->d_L2s[l]; } const L3::Ptr & Oncilla::getL3(Leg l) const { return this->d_L3s[l]; } const Trunk::Ptr & Oncilla::getTrunk() const { return this->d_trunk; } OncillaSynchronizerPtr Oncilla::getSynchronizer() const { if(!s_synchronizer){ throw std::logic_error("Internal error : synchronizer seems unitialized" ", but it should never happen. Please report this bug."); } return this->s_synchronizer; } } } diff --git a/src/liboncilla/OncillaSynchronizer.h b/src/liboncilla/OncillaSynchronizer.h index 5ed758c..5e09b00 100644 --- a/src/liboncilla/OncillaSynchronizer.h +++ b/src/liboncilla/OncillaSynchronizer.h @@ -1,72 +1,48 @@ #pragma once #include #include #include #include #include "common.h" #include namespace rci { namespace oncilla { class OncillaSynchronizer; typedef boost::shared_ptr OncillaSynchronizerPtr; /** * OncillaSynchronizer * Different OncillaSynchronizers may be for example: * * Update with a given frequency * ** Send data every time * ** Send only if new data * * Update only if new data (event-based) * * Triggered from robot side (e.g. FRI) */ class OncillaSynchronizer: public Synchronizer { public: OncillaSynchronizer(const std::string &name); virtual ~OncillaSynchronizer(); - /** - * Registers a trunk node. - */ - virtual void registerTrunkNode(Trunk::Ptr node) = 0; - - /** - * Registers an L0 node. - */ - virtual void registerL0Node(Leg l, L0::Ptr node) = 0; - - /** - * Registers an L1 node. - */ - virtual void registerL1Node(Leg l, L1::Ptr node) = 0; - - /** - * Registers an L2 node. - */ - virtual void registerL2Node(Leg l, L2::Ptr node) = 0; - - /** - * Registers an L3 node. - */ - virtual void registerL3Node(Leg l, L3::Ptr node) = 0; /** * */ friend std::ostream & operator<<(std::ostream& os, const OncillaSynchronizer& val); virtual double lastProcessTimeStep() const = 0; }; } } diff --git a/src/liboncilla/utils/OncillaBackend.h b/src/liboncilla/utils/OncillaBackend.h index 77b15c1..07545ff 100644 --- a/src/liboncilla/utils/OncillaBackend.h +++ b/src/liboncilla/utils/OncillaBackend.h @@ -1,34 +1,50 @@ /* * Backend.h * * Created on: Jan 18, 2013 * Author: tuleu */ #ifndef LIBONCILLA_ONCILLABACKEND_H_ #define LIBONCILLA_ONCILLABACKEND_H_ #include #include #include +#include namespace rci{ namespace oncilla{ class OncillaSynchronizer; + class L0; + class L1L2; + class L3; + typedef L1L2 L1; + typedef L1L2 L2; } } class OncillaBackend { BIOROB_CPP_DECLARE_PLUGIN(OncillaBackend); DISABLE_ASSIGNEMENT(OncillaBackend); DISABLE_COPY(OncillaBackend); public : typedef std::tr1::shared_ptr Ptr; virtual ~OncillaBackend(); virtual boost::shared_ptr CreateSynchronizer() = 0; + + virtual boost::shared_ptr CreateL0(rci::oncilla::Leg l, + const std::string & name ) = 0; + virtual boost::shared_ptr CreateL1(rci::oncilla::Leg l, + const std::string & name ) = 0; + virtual boost::shared_ptr CreateL2(rci::oncilla::Leg l, + const std::string & name ) = 0; + virtual boost::shared_ptr CreateL3(rci::oncilla::Leg l, + const std::string & name ) = 0; + }; #endif /* LIBONCILLA_ONCILLABACKEND_H_ */