Commit ede3edb6 authored by Bruno Laurencich's avatar Bruno Laurencich

fix lap adjustent on scheduler

parent a43306c5
......@@ -46,7 +46,7 @@
<Branch Name="left" id="1">
CH_1
<K_Ceptor Name="Unico" id="2">
6
1
</K_Ceptor>
</Branch>
</Mux>
......
......@@ -372,6 +372,7 @@ namespace Chordata {
bool wait;
bool raw;
int kc_ver;
int empirical_add;
struct Program_State{
mutable char beta_timer_init;
......
......@@ -128,7 +128,7 @@ Configuration_Data Chordata::parse_cmd_line(int argc, const char **argv){
args::Flag wait(parser, "no_wait", msgs::wait, {'y', "yes"});
args::Flag raw(parser, "raw_lectures", msgs::wait, {'r', "raw"});
args::ValueFlag<int> kc_ver(parser, "K_Ceptor revision", msgs::kc_ver, {'k', "kceptor"});
args::ValueFlag<int> empirical_add(parser, "Empirical ADD", "temporary parameter", {'E', "empirical_add"});
args::Group xml(parser, msgs::xml_g, args::Group::Validators::DontCare);
......@@ -180,6 +180,7 @@ Configuration_Data Chordata::parse_cmd_line(int argc, const char **argv){
conf.wait = (wait)? false : true;
conf.raw = (raw)? true : false;
conf.empirical_add = (empirical_add)? get(empirical_add) : 0;
if (kc_ver){
args::Error e("");
......
......@@ -55,10 +55,11 @@ namespace comm = Chordata::Communicator;
using namespace std;
using namespace Chordata;
using scheduler_citer = std::vector<I2C_Node*>::const_iterator;
#define LAP_MODIF_RATE 10
#define LAP_TOLERANCE 100
#define LAP_CORRECT_TIME_MARGIN 20*1000
#define LAP_CORRECT_TIME_MARGIN 10*1000
void Node_Scheluder::addNode(I2C_Node *n){
nodelist.push_back(n);
......@@ -69,6 +70,12 @@ void Node_Scheluder::addNode(I2C_Node *n){
};
const scheduler_citer seek_first_sensor(const std::vector<I2C_Node*>& list){
for (scheduler_citer i = list.begin(); i != list.end(); ++i){
if ((*i)->isSensor()) return i;
}
}
long int Node_Scheluder::bang(long int wait){
//not threaded at the moment
......@@ -77,13 +84,19 @@ long int Node_Scheluder::bang(long int wait){
static long int lap_teoric_duration = 1000000 / _CHORDATA_ODR;
static long int teoric_wait = lap_teoric_duration / getODRModifiers();
if (current == nodelist.begin()+1){
static auto first_sensor = seek_first_sensor(nodelist);
if (current == first_sensor){
//Check if lap duration is correct and adjust;
auto lap = comm::timekeeper.ellapsedLapMicros();
comm::trace(" ===== Ellapsed Lap Micros: {} =====", lap);
comm::timekeeper.resetLap();
if (comm::timekeeper.ellapsedMillis() > LAP_CORRECT_TIME_MARGIN ){
//Leave the first second of execution untouched
//after that start cheking if the lap has to be increased or decreased
if (lap > lap_teoric_duration + LAP_TOLERANCE){
wait -= LAP_MODIF_RATE;
comm::debug(" (- ) Read wait reduced, now is {} (teoric = {}, [Lap measured: {}, Lap teoric: {}])",
......@@ -94,11 +107,10 @@ long int Node_Scheluder::bang(long int wait){
comm::debug(" ( +) Read wait increased, now is {} (teoric = {}, [Lap measured: {}, Lap teoric: {}])",
wait, teoric_wait,
lap, lap_teoric_duration);
}
}
}
} // End lap duration cheking
doSearch();
return wait;
......@@ -112,7 +124,7 @@ void Node_Scheluder::doSearch(){
// mp->unlock();
step();
if (!(*current)->isSensor()){
while (!(*current)->isSensor()){
main_buffer.put(*current);
step();
}
......
......@@ -268,14 +268,14 @@ bool Notochord::run(){
int user_xor_val;
string user_label;
// The +2 is here because it was observed on the oscilloscope that there were 2 extra delay periods
// Presumably when the gates go to K_Ceptor_offset_calib
// This is not used when in raw mode, which at the moment is used only for collecting data for callibration
//TOFIX:change the way this is implemented!
int empirical_add = (config.raw)? 0 : 2;
//It was observed on the oscilloscope that there were some extra delays
//so the "config.empirical_add" value was introduced to virually change the ODRModifiers
//on runtime.
//Perhaps this is due to the nested multiplexer hack used on the R1 prototype.
//TODO:why is this happening?!
long sleepMicros = (1000*1000) /
((scheluder.getODRModifiers() + empirical_add) * _CHORDATA_ODR );
((scheluder.getODRModifiers() + config.empirical_add) * _CHORDATA_ODR );
const int notODRModifiers = scheluder.length() - scheluder.getODRModifiers();
if (notODRModifiers < 1){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment