Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BoundingConstraint1 segfaults on optimization #1905

Open
tunan1111 opened this issue Nov 26, 2024 · 0 comments
Open

BoundingConstraint1 segfaults on optimization #1905

tunan1111 opened this issue Nov 26, 2024 · 0 comments

Comments

@tunan1111
Copy link

Hi,
I've been using BoundingConstraint1 from the gtsam library lately 。
Here's my code ,code is from here(thanks to the author):

class Pose3Bounds : public gtsam::BoundingConstraint1<Eigen::Vector3d> {
 public:
  using shared_ptr = gtsam::NonlinearFactor::shared_ptr;

  Pose3Bounds(
      gtsam::Key key, size_t idx, double threshold, bool is_greater, double mu = 1000.0)
      : gtsam::BoundingConstraint1<Eigen::Vector3d>(key, threshold, is_greater, mu),
        idx_(idx),
        threshold_(threshold),
        is_greater_(is_greater),
        mu_(mu) {}

  double value(const Eigen::Vector3d& x,
                GtsamJacobianType H = JACOBIAN_DEFAULT) const override {
    if (H) {
        gtsam::Matrix D =
          gtsam::Matrix::Zero(1, 3);
      D(0, idx_) = 1.0;
      *H = D;
    }
    return x(idx_);
  }

  shared_ptr clone() const override {
    return shared_ptr(new Pose3Bounds(front(), idx_, threshold_, is_greater_, mu_));
  }

 private:
  size_t idx_;
  double threshold_;
  bool is_greater_;
  double mu_;
};

//This part is pseudocode
	std::shared_ptr<gtsam::NonlinearFactorGraph> graph_factor_;
	std::shared_ptr<gtsam::Values> initial_values_;
	std::shared_ptr<gtsam::ISAM2> optimizer_imu_gps_;

graph_factor_->emplace_shared<Pose3Bounds>(V(*correction_count), 1,-0.4, true);
optimizer_->update(*graph_factor_, *initial_values_);

I have a three-dimensional vector and Key is V。
graph_factor_->emplace_shared<Pose3Bounds>(V(*correction_count), 1,-0.4, true); optimizer_->update(*graph_factor_, *initial_values_);
Within a loop, there is constantly new data and then optimized。

if don't use BoundingConstraint1 , this optimizer_->update() can run smoothly and optimize successfully。 Once BoundingConstraint1 is used, the program will be segfaults on the second execution of the optimizer_->update() session。

this issue like at line [268] of file testBoundingConstraint.cpp

OS [e.g. Ubuntu 18.04, Ubuntu 20.04]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant