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

Fix all the scripts #385

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gtdynamics/utils/Initializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ Values Initializer::ZeroValues(
int j = joint->id();
InsertWrench(&values, joint->parent()->id(), j, t, sampler.sample());
InsertWrench(&values, joint->child()->id(), j, t, sampler.sample());

// Joint angles, velocities, accelerations, and torques.
std::vector<DynamicsSymbol> keys = {TorqueKey(j, t), JointAngleKey(j, t),
JointVelKey(j, t), JointAccelKey(j, t)};
for (size_t i = 0; i < keys.size(); i++)
Expand Down
8 changes: 3 additions & 5 deletions scripts/alejandro_yetong_01_id_four_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main(int argc, char** argv) {
using four_bar_linkage_pure::planar_axis;
auto robot = four_bar_linkage_pure::getRobot();

gtsam::Values joint_angles_vels_accels;
Initializer initializer;

gtsam::Vector3 gravity(0, -10, 0);
robot = robot.fixLink("l1");
Expand All @@ -42,7 +42,7 @@ int main(int argc, char** argv) {
graph_builder.dynamicsFactorGraph(robot, 0);

// Inverse dynamics priors. We care about the torques.
gtsam::Vector joint_accels = gtsam::Vector::Zero(robot.numJoints());
gtsam::Values joint_angles_vels_accels = initializer.ZeroValues(robot, 0);
gtsam::NonlinearFactorGraph prior_factors =
graph_builder.inverseDynamicsPriors(robot, 0, joint_angles_vels_accels);

Expand All @@ -52,8 +52,7 @@ int main(int argc, char** argv) {
prior_factors.addPrior(PoseKey(i, 0), link->bMcom(),
gtsam::noiseModel::Constrained::All(6));
prior_factors.addPrior<gtsam::Vector6>(
TwistKey(i, 0), gtsam::Z_6x1,
gtsam::noiseModel::Constrained::All(6));
TwistKey(i, 0), gtsam::Z_6x1, gtsam::noiseModel::Constrained::All(6));
}
graph.add(prior_factors);

Expand All @@ -64,7 +63,6 @@ int main(int argc, char** argv) {
gtsam::noiseModel::Gaussian::Covariance(gtsam::I_1x1)));

// Initialize solution.
Initializer initializer;
gtsam::Values init_values = initializer.ZeroValues(robot, 0);

std::cout << "\033[1;32;7mFactor Graph Optimization:\033[0m" << std::endl;
Expand Down
6 changes: 4 additions & 2 deletions scripts/gerry00_ForwardDynamicsPrismatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ int main(int argc, char** argv) {
InsertJointVel(&theta_and_theta_dot, j2, 0, 0.1);
InsertJointVel(&theta_and_theta_dot, j3, 0, 0.0);

std::vector<gtsam::Vector> taus;
// Insert torque values for all timesteps
for (int t = 0; t <= T; t++) {
taus.push_back(gtsam::Vector::Zero(3));
InsertTorque(&theta_and_theta_dot, j1, t, 0.0);
InsertTorque(&theta_and_theta_dot, j2, t, 0.0);
InsertTorque(&theta_and_theta_dot, j3, t, 0.0);
}
auto fd_priors =
graph_builder.trajectoryFDPriors(simple_rpr, T, theta_and_theta_dot);
Expand Down
1 change: 1 addition & 0 deletions scripts/nithya00_constrained_opt_benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ int main(int argc, char** argv) {
};

/// Write results to files for plotting.
std::cout << "Writing resutls to penalty_data.txt and augl_data.txt for plotting" << std::endl;
std::ofstream penalty_file;
penalty_file.open("penalty_data.txt");
for (size_t i = 0; i < penalty_info.num_iters.size(); i++) {
Expand Down
6 changes: 3 additions & 3 deletions scripts/stephanie01_ForwardDynamicsThreeLink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ int main(int argc, char **argv) {
// Load the three-link robot using the relevant namespace from RobotModels.
auto robot = simple_rr::getRobot();

Initializer initializer;

// Build the factor graph for the robot.
robot = robot.fixLink("link_0");
gtsam::Vector3 gravity = (gtsam::Vector(3) << 0, 0, -9.8).finished();
Expand All @@ -32,13 +34,11 @@ int main(int argc, char **argv) {
auto graph = graph_builder.dynamicsFactorGraph(robot, 0);

// Add forward dynamics priors to factor graph.
gtsam::Values values;

gtsam::Values values = initializer.ZeroValues(robot, 0);
auto priorFactors = graph_builder.forwardDynamicsPriors(robot, 0, values);
graph.add(priorFactors);

// Generate initial values to be passed in to the optimization function.
Initializer initializer;
auto init_values = initializer.ZeroValues(robot, 0);

// Compute forward dynamics.
Expand Down
Loading