Skip to content

Commit

Permalink
Can reconfigure parameters during sim, can load and unload nodelet, g…
Browse files Browse the repository at this point in the history
…ranite seq working
  • Loading branch information
somritabanerjee committed Dec 14, 2024
1 parent 844c00c commit 9db80d3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
8 changes: 8 additions & 0 deletions astrobee/config/mobility/planner_scp_gusto.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,13 @@ parameters = {
id = "epsilon", reconfigurable = true, type = "double",
default = 1e-3, min = 1e-6, max = 1e-1, unit = "unitless",
description = "Threshold below which magnitudes are ignored"
},{
id = "is_granite", reconfigurable = true, type = "boolean",
default = true, unit = "unitless",
description = "Flag for granite sim"
},{
id = "enforce_obs_avoidance_const", reconfigurable = true, type = "boolean",
default = true, unit = "unitless",
description = "Flag for avoiding (virtual) obstacle"
}
}
11 changes: 7 additions & 4 deletions mobility/planner_scp_gusto/src/optim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,6 @@ void TOP::ResetSCPParams() {

void TOP::UpdateProblemDimension(size_t N_) {
// Allocate matrices for variables and constraints
if (solver && N == N_) {
return;
}

N = N_;

Expand All @@ -241,7 +238,7 @@ void TOP::UpdateProblemDimension(size_t N_) {
solver->data()->clearLinearConstraintsMatrix();
}

std::cout << "cleared stuff" << std::endl;
std::cout << "TOP::UpdateProblemDimension: Cleared solver" << std::endl;

Xprev.resize(N);
Uprev.resize(N-1);
Expand All @@ -258,6 +255,8 @@ void TOP::UpdateProblemDimension(size_t N_) {
size_t num_vars = GetNumTOPVariables();
size_t num_cons = GetNumTOPConstraints();

std::cout << "TOP::UpdateProblemDimension: Num vars: " << num_vars << " Num cons: " << num_cons << std::endl;

hessian.resize(num_vars, num_vars);
linear_con_mat.resize(num_cons, num_vars);
gradient.resize(num_vars);
Expand Down Expand Up @@ -1119,6 +1118,10 @@ void TOP::SetSimpleCosts() {

bool TOP::Solve() {
solved_ = false;
ResetSCPParams();
UpdateProblemDimension(N);
std::cout << "TOP::Solve: Updated problem dimension" << std::endl;
std::cout << "linear_con_mat size: " << linear_con_mat.rows() << " x " << linear_con_mat.cols() << std::endl;
InitTrajStraightline();
bool add_custom_keep_out_zone = true;

Expand Down
24 changes: 23 additions & 1 deletion mobility/planner_scp_gusto/src/planner_scp_gusto_nodelet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class PlannerSCPGustoNodelet : public planner::PlannerImplementation {
float control_rate_; // Control frequency
double max_time_; // Max generation time
double epsilon_;
bool enforce_obs_avoidance_const_;
bool is_granite_;
bool use_2d; // true for granite table
std::string flight_mode_;
ros::NodeHandle *nh_;
Expand All @@ -93,6 +95,8 @@ class PlannerSCPGustoNodelet : public planner::PlannerImplementation {
nh_ = nh;
// Save the epsilon value
epsilon_ = cfg_.Get<double>("epsilon");
enforce_obs_avoidance_const_ = cfg_.Get<bool>("enforce_obs_avoidance_const");
is_granite_ = cfg_.Get<bool>("is_granite");
// Notify initialization complete
NODELET_DEBUG_STREAM("Initialization complete");
// Success
Expand All @@ -104,9 +108,13 @@ class PlannerSCPGustoNodelet : public planner::PlannerImplementation {
}

bool ReconfigureCallback(dynamic_reconfigure::Config &config) {
std::cout << "ReconfigureCallback" << std::endl;
if (!cfg_.Reconfigure(config))
return false;
epsilon_ = cfg_.Get<double>("epsilon");
enforce_obs_avoidance_const_ = cfg_.Get<bool>("enforce_obs_avoidance_const");
std::cout << "set enforce_obs_avoidance_const_ to " << enforce_obs_avoidance_const_ << std::endl;
is_granite_ = cfg_.Get<bool>("is_granite");
return true;
}

Expand Down Expand Up @@ -380,7 +388,21 @@ class PlannerSCPGustoNodelet : public planner::PlannerImplementation {
top->x_min(ii) = min(ii);
top->x_max(ii) = max(ii);
}
top->is_granite = true; // TODO(Somrita): Read from config

// if (!ReconfigureCallback(cfg_)) {
// std::cout << "Failed to reconfigure" << std::endl;
// return false;
// }
// std::cout << "Reconfigured" << std::endl;
std::cout << "Now the value of enforce_obs_avoidance_const_ is " << enforce_obs_avoidance_const_ << std::endl;
if (!cfg_.Get<bool>("enforce_obs_avoidance_const", enforce_obs_avoidance_const_)){
std::cout << "Failed to get param enforce_obs_avoidance_const_" << std::endl;
enforce_obs_avoidance_const_ = true;
}
std::cout << "Now the value of enforce_obs_avoidance_const_ is " << enforce_obs_avoidance_const_ << std::endl;
top->is_granite = cfg_.Get<bool>("is_granite");
top->enforce_obs_avoidance_const = enforce_obs_avoidance_const_;
std::cout << "calling TOP with enforce_obs_avoidance_const: " << top->enforce_obs_avoidance_const << std::endl;
if (top->is_granite) {
top->x_min(2) = -0.675; // z coordinate
top->x_max(2) = -0.67;
Expand Down

0 comments on commit 9db80d3

Please sign in to comment.