Page MenuHomec4science

Oncilla.cpp
No OneTemporary

File Metadata

Created
Thu, Apr 25, 07:31

Oncilla.cpp

/*
* Oncilla.cpp
*
* Created on: 15 dec. 2011
* Author: Alexandre Tuleu, Arne Nordmann
*/
#include "Oncilla.h"
#include <liboncilla/utils/BackendLoader.h>
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,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)
void Oncilla::init() {
d_L0s.reserve(4);
d_L1s.reserve(4);
d_L2s.reserve(4);
d_L3s.reserve(4);
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"));
}
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;
}
}
}

Event Timeline