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

Lab 7 Deliverable 3 #15

Open
votmA opened this issue Feb 22, 2024 · 0 comments
Open

Lab 7 Deliverable 3 #15

votmA opened this issue Feb 22, 2024 · 0 comments

Comments

@votmA
Copy link

votmA commented Feb 22, 2024

I have been stuck in lab 7 at the deliverable 3.
Probably, I am doing something wrong. But I could not understand where. Any advice would be appreciated. The error is that the optimizer quits after the 1st iteration stating that the error increased.

Here is the code for 3a:

  // Error function.
  // @param p 3D pose.
  // @param H optional Jacobian matrix.
  gtsam::Vector evaluateError(
      const gtsam::Pose3& p,
      boost::optional<gtsam::Matrix&> H = boost::none) const {

    // 3a. Complete definition of factor
    // TODO: 
    // Return error vector and jacobian if requested (aka H !=
    // boost::none).
    //
    // Insert code below:
    // Extract the rotation component from the pose.
    Vector3 translation = p.translation();
    Rot3 rotation = p.rotation();

    if (H) {
      Matrix H_tmp = Matrix::Zero(3, 6);
      H_tmp.block<3, 3>(0, 0) = rotation.matrix(); 
      H_tmp.block<3, 3>(0, 3) = I_3x3;
      (*H) = H_tmp;
    }

    return (Vector(3) << translation.x() - m_.x(), translation.y() - m_.y(), translation.z() - m_.z()).finished();
    // End 3a. 
  }

Here is the code for 3b:

  if (use_mocap) {
    // 3b. Add motion capture measurements (mocap_measurements)
    // TODO: create the 3D MoCap measurement noise model (a diagonal noise
    // model should be sufficient). Think of how many dimensions it should have.
    // You are given mocap_std_dev (defined above)
    //
    //

    //  TODO: add the MoCap factors
    // Note that there is no prior factor needed at first pose, since MoCap
    // provides the global positions (and rotations given more than 1 MoCap
    // measurement).
    //
    // Insert code below:
    noiseModel::Diagonal::shared_ptr mocapNoise =
    noiseModel::Diagonal::Sigmas(Vector3(mocap_std_dev, mocap_std_dev, mocap_std_dev));

    for (const auto& mocap_measurement : mocap_measurements) {
        // Extract information from the mocap_measurement
        int pose_key = mocap_measurement.first;
        Point3 mocap_position = mocap_measurement.second;

        // Add a MoCap factor to the graph
        graph.add(boost::make_shared<MoCapPosition3Factor>(pose_key, mocap_position, mocapNoise));
    }
    // End 3b. 
  }
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