00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #include <stdio.h>
00048 #include <math.h>
00049 #include "sinecontroller.h"
00050
00051 SineController::SineController(int number_controlled){
00052 t=0;
00053 sineRate=40;
00054 phaseShift=1;
00055
00056 number_sensors=0;
00057 number_motors=0;
00058 this->number_controlled=number_controlled;
00059
00060
00061
00062 Configurable::insertCVSInfo(name, "$RCSfile: sinecontroller.cpp,v $",
00063 "$Revision: 1.1.2.3 $");
00064 };
00065
00066
00067
00068
00069 void SineController::init(int sensornumber, int motornumber){
00070 number_sensors=sensornumber;
00071 number_motors=motornumber;
00072 if(number_controlled==-1) number_controlled=motornumber;
00073 };
00074
00075
00076
00077
00078
00079
00080
00081
00082 void SineController::step(const sensor* sensors, int sensornumber,
00083 motor* motors, int motornumber) {
00084 stepNoLearning(sensors, sensornumber, motors, motornumber);
00085 };
00086
00087
00088
00089
00090 void SineController::stepNoLearning(const sensor* sensors, int number_sensors,
00091 motor* motors, int number_motors) {
00092
00093 for (int i=0; i<number_motors; i++){
00094 if(i < number_controlled){
00095 motors[i]=sin(t/sineRate + i*phaseShift*M_PI/2);
00096 }else {
00097 motors[i]=0;
00098 }
00099 }
00100 t++;
00101 };
00102
00103
00104
00105 Configurable::paramval SineController::getParam(const paramkey& key) const{
00106 if(key == "sinerate") return sineRate;
00107 else if(key == "phaseshift") return phaseShift;
00108 else return AbstractController::getParam(key) ;
00109 }
00110
00111 bool SineController::setParam(const paramkey& key, paramval val){
00112 if(key == "sinerate") sineRate=val;
00113 else if(key == "phaseshift") phaseShift=val;
00114 else return AbstractController::setParam(key, val);
00115 return true;
00116 }
00117
00118 Configurable::paramlist SineController::getParamList() const{
00119 paramlist l;
00120 l += pair<paramkey, paramval> (string("sinerate"), sineRate);
00121 l += pair<paramkey, paramval> (string("phaseshift"), phaseShift);
00122 return l;
00123 }
00124
00125
00126