Page MenuHomec4science

Oncilla.cpp
No OneTemporary

File Metadata

Created
Wed, May 1, 18:43

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 {
::rci::oncilla::Synchronizer::Ptr Oncilla::s_synchronizer;
std::string Oncilla::nameOfLeg(Leg l){
static const char * legNames[NUM_LEGS + 1] = {
"Left Fore", //LEFT_FORE
"Right Fore", //RIGHT_FORE
"Left Hind", //LEFT_HIND
"Right Hind", //RIGHT_HIND
"Undefined"
};
//oncly consider index in range [0 NUM_LEGS], defaulting to NUM_LEGS if out of bound.
int index((l < 0 ) ? NUM_LEGS : (l > NUM_LEGS ? NUM_LEGS : l));
return legNames[index];
}
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() {
}
void Oncilla::init() {
d_L0s.reserve(4);
d_L1s.reserve(4);
d_L2s.reserve(4);
d_L3s.reserve(4);
LIBONCILLA_FOREACH_LEG(l){
d_L0s.push_back(d_backend->CreateL0(l,Oncilla::nameOfLeg(l) + " Oncilla L0"));
d_L1s.push_back(d_backend->CreateL1(l,Oncilla::nameOfLeg(l) + " Oncilla L1"));
d_L2s.push_back(d_backend->CreateL2(l,Oncilla::nameOfLeg(l) + " Oncilla L2"));
d_L3s.push_back(d_backend->CreateL3(l,Oncilla::nameOfLeg(l) + " Oncilla L3"));
}
d_trunk = d_backend->CreateTrunk();
d_supervisor = Supervisor::Ptr(new Supervisor(*d_backend));
s_synchronizer->calibrateIfNeeded();
}
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;
}
const rci::oncilla::Synchronizer::Ptr & 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;
}
const rci::oncilla::Supervisor::Ptr & Oncilla::getSupervisor() const {
return d_supervisor;
}
}
}

Event Timeline