Skip to content
Snippets Groups Projects
Commit d532e9ea authored by Paloma de la Puente's avatar Paloma de la Puente
Browse files

some debugging

parent bfc3abfd
No related branches found
No related tags found
No related merge requests found
...@@ -16,9 +16,11 @@ void Constraint::SetType(int t) ...@@ -16,9 +16,11 @@ void Constraint::SetType(int t)
type = t; type = t;
} }
double Constraint::ApplyConstraint(int* indices, double* params) Values Constraint::ApplyConstraint(int* indices, double* params)
{ {
Values v;
double err = 0; double err = 0;
double grd = 0;
switch(type) switch(type)
{ {
...@@ -36,5 +38,8 @@ double Constraint::ApplyConstraint(int* indices, double* params) ...@@ -36,5 +38,8 @@ double Constraint::ApplyConstraint(int* indices, double* params)
} }
return err; v.error = err;
v.grad = grd;
return v;
} }
...@@ -8,6 +8,13 @@ ...@@ -8,6 +8,13 @@
#include <csm/csm_all.h> #include <csm/csm_all.h>
struct Values{
double error;
double grad;
};
class Constraint class Constraint
{ {
...@@ -22,7 +29,7 @@ protected: ...@@ -22,7 +29,7 @@ protected:
int type; int type;
// class methods // class methods
public: public:
double ApplyConstraint(int* indices, double* params = NULL); Values ApplyConstraint(int* indices, double* params = NULL);
void SetType(int t); void SetType(int t);
}; };
......
...@@ -34,9 +34,9 @@ void ConstraintManager::ClearConstraints() ...@@ -34,9 +34,9 @@ void ConstraintManager::ClearConstraints()
void ConstraintManager::ApplyConstraints() void ConstraintManager::ApplyConstraints()
{ {
//add as many types of constraints as wished //add as many types of constraints as wished
bool equal_to_either_active = false; bool equal_to_either_active = true;
bool apply_equal_to_either = false; bool apply_equal_to_either = false;
bool lock_diff_active = false; bool lock_diff_active = true;
bool apply_lock_diff = false; bool apply_lock_diff = false;
int n = laser_data->nrays; int n = laser_data->nrays;
...@@ -46,12 +46,14 @@ void ConstraintManager::ApplyConstraints() ...@@ -46,12 +46,14 @@ void ConstraintManager::ApplyConstraints()
if (equal_to_either_active && constraint_types_to_apply[i] == EQUAL_TO_EITHER) if (equal_to_either_active && constraint_types_to_apply[i] == EQUAL_TO_EITHER)
{ {
apply_equal_to_either = true; apply_equal_to_either = true;
equal_to_either_active = false;
continue; continue;
} }
if (lock_diff_active && constraint_types_to_apply[i] == LOCK_DIFF) if (lock_diff_active && constraint_types_to_apply[i] == LOCK_DIFF)
{ {
apply_lock_diff = true; apply_lock_diff = true;
lock_diff_active = false;
continue; continue;
} }
...@@ -69,9 +71,11 @@ void ConstraintManager::ApplyConstraints() ...@@ -69,9 +71,11 @@ void ConstraintManager::ApplyConstraints()
{ {
Constraint* c = new Constraint(EQUAL_TO_EITHER); Constraint* c = new Constraint(EQUAL_TO_EITHER);
int* ind; int* ind;
ind[0] = i-j; ind[1] =i; ind[2] =i+j; ind[0] = i-j; ind[1] =i; ind[2] =i+j;
e += c->ApplyConstraint(ind); Values v = c->ApplyConstraint(ind);
constraints.push_back(c); constraints.push_back(c);
e += v.error;
} }
} }
...@@ -80,19 +84,22 @@ void ConstraintManager::ApplyConstraints() ...@@ -80,19 +84,22 @@ void ConstraintManager::ApplyConstraints()
if(apply_lock_diff) //add lock_diff constraints if(apply_lock_diff) //add lock_diff constraints
{ {
Constraint* c = new Constraint(LOCK_DIFF);
for (int i=0;i<n-1;i++) for (int i=0;i<n-1;i++)
{ {
int* ind; int* ind;
ind[0] = i; ind[1]=i+1; ind[0] = i; ind[1]=i+1;
double* p; double* p;
p[0] = PI/2; p[1] = lock_diff_threshold; p[0] = PI/2; p[1] = lock_diff_threshold;
constraints.push_back(c); Constraint* c1 = new Constraint(LOCK_DIFF);
e+= c->ApplyConstraint(ind,p); Values v = c1->ApplyConstraint(ind,p);
constraints.push_back(c1);
e += v.error;
p[0] = -PI/2; p[0] = -PI/2;
e+= c->ApplyConstraint(ind,p); Constraint* c2 = new Constraint(LOCK_DIFF);
constraints.push_back(c); v = c2->ApplyConstraint(ind,p);
constraints.push_back(c2);
e += v.error;
} }
} }
......
...@@ -10,14 +10,19 @@ int main(int argc, const char** argv) ...@@ -10,14 +10,19 @@ int main(int argc, const char** argv)
if (argc < 2) if (argc < 2)
{ {
sm_error("Provide input file's name as an argument\n"); sm_error("Provide input file's name as an argument\n");
return 0; return -1;
} }
const char* file_name = argv[0]; const char* file_name = argv[1];
FILE* input_file = fopen(file_name, "r"); FILE* input_file = fopen(file_name, "r");
LDP laserdata; LDP laserdata;
laserdata = ld_read_smart(input_file); if(!(laserdata = ld_read_smart(input_file))) {
sm_error("Could not read scan.\n");
return -1;
}
std::vector<int> cons_types; std::vector<int> cons_types;
cons_types.push_back(EQUAL_TO_EITHER); cons_types.push_back(EQUAL_TO_EITHER);
...@@ -30,6 +35,6 @@ int main(int argc, const char** argv) ...@@ -30,6 +35,6 @@ int main(int argc, const char** argv)
return 1; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment