A simple example for the integration of a robot into the framework (with agent, controller, wiring). This facilitates you with the plotting options, tracing and such like. Here the data flow is controlled by the agent, which then asks the robot about the sensors, invokes the controller and sends the motor values the robot again. See also selforg.
#include <signal.h>
#include <unistd.h>
#include <iostream>
#include <vector>
#include <list>
#include <iterator>
using namespace std;
#include <selforg/invertmotorspace.h>
#include <selforg/one2onewiring.h>
#include <selforg/derivativewiring.h>
public:
myparam=0;
motornumber = 3;
sensornumber = 3;
x = new double[sensornumber];
y = new double[motornumber];
}
if(x) delete[] x;
if(y) delete[] y;
}
virtual int getSensors(
sensor* sensors,
int sensornumber){
assert(sensornumber == this->sensornumber);
memcpy(sensors, x,
sizeof(
sensor) * sensornumber);
return sensornumber;
}
virtual void setMotors(
const motor* motors,
int motornumber){
assert(motornumber == this->motornumber);
memcpy(y, motors,
sizeof(
motor) * motornumber);
for(int i=0; i<sensornumber; i++){
x[i] = sin(myparam) * y[i%motornumber];
}
myparam+=0.01;
}
virtual int getSensorNumber(){ return sensornumber; }
virtual int getMotorNumber() { return motornumber; }
return m;
};
if(key == "myparam") return myparam;
}
virtual bool setParam(
const paramkey& key,
paramval val,
bool traverseChildren){
cerr << "huhu";
if(key == "myparam") myparam = val;
return true;
}
virtual paramlist getParamList() const {
paramlist list;
list += pair<paramkey, paramval> (string("myparam"), myparam);
return list;
};
private:
int motornumber;
int sensornumber;
double* x;
double* y;
};
}
int contains(
char **list,
int len,
const char *str){
for(int i=0; i<len; i++){
if(strcmp(list[i],str) == 0) return i+1;
}
return 0;
}
int main(
int argc,
char** argv){
list<PlotOption> plotoptions;
printf("Usage: %s [-g] [-f]\n",argv[0]);
printf("\t-g\tstart guilogger\n\t-f\twrite logfile\n\t-h\tdisplay this help\n");
exit(0);
}
printf("\nPress Ctrl-c to invoke parameter input shell (and again Ctrl-c to quit)\n");
agent->
init(controller, robot, wiring);
configs.push_back(robot);
configs.push_back(controller);
for(int n=0; n<20; n++) {
usleep(1000);
}
};
fprintf(stderr,"terminating\n");
delete agent;
delete controller;
delete wiring;
delete robot;
return 0;
}