Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4478d1e
Integrate C3+ into push_anything branch (#390)
xuanhien070594 Aug 4, 2025
48550f8
Add reconstructed meshes of few objects, tune parameters of C3+ for p…
xuanhien070594 Aug 7, 2025
a3b4080
feat: use external c3 repo for sampling example
Meow404 Aug 5, 2025
fcf9a14
feat: update commit for c3
Meow404 Aug 12, 2025
9e969e1
fix: use of correct N
Meow404 Aug 19, 2025
b6593d7
Include workspace and input limits as constraints in C3 QP step
ebianchi Jul 8, 2025
2090e5c
Resolve merge conflicts with main (#386)
xuanhien070594 Jul 10, 2025
e16c9ad
feat: inital commit -- bring plate balancing example from robust_c3
Meow404 Jun 20, 2025
3addc92
fix: removed c3 dependency from franka_c3_controller.cc
Meow404 Jun 23, 2025
b57d2fa
style: refactor
Meow404 Jun 24, 2025
96920be
dependencies: remove unnecessary dependencies
Meow404 Jun 24, 2025
fcf491d
doc: update readme
Meow404 Jun 24, 2025
5315bd1
fix: update .bazelrc
Meow404 Jun 26, 2025
8bc04c0
fix: add c3 lcmtypes to lcm-spy
Meow404 Jun 26, 2025
1a161c7
fix: update to incorporate changes in c3
Meow404 Jun 27, 2025
14cb6ab
fix: use update force visualization
Meow404 Jul 1, 2025
bb087a8
feat: use trajectory generator in C3
Meow404 Jul 5, 2025
c0090b2
fix: refactory and remove c3 state sender
Meow404 Jul 7, 2025
2166ff3
recfactor: cleanup
Meow404 Jul 7, 2025
527b6b4
fix: use static c3 library
Meow404 Jul 8, 2025
f3bd2c1
feat: add lcmt systems
Meow404 Jul 9, 2025
b7e6c59
fix: refactor after rebase on sampling_based_c3_public
Meow404 Jul 12, 2025
4e9a26b
todo: add todo for robot_lcm_systems.h
Meow404 Jul 14, 2025
8f3bd57
fix: pmd typo
Meow404 Jul 14, 2025
ac1f0e9
fix: minor fixes
Meow404 Jul 24, 2025
989d96b
fix: revert changes in config
Meow404 Jul 24, 2025
742c706
feat: add delay to c3 controller
Meow404 Jul 29, 2025
f437aca
fixes after rebase
Meow404 Aug 14, 2025
a922a8f
feat: add config for C3+
Meow404 Aug 15, 2025
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
8 changes: 7 additions & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,16 @@ archive_override(
strip_prefix = "drake-{}".format(DRAKE_VERSION.lstrip("v")),
)

bazel_dep(name = "c3")
git_override(
module_name = "c3",
remote = "https://github.com/DAIRLab/c3.git",
commit = "ed1cb0ed199901aeae85725502b583a2b40c9553"
)

INEKF_COMMIT = "297c308e50fa599af92ce3bd5f11d71e2bf8af69"
INEKF_CHECKSUM = "c5a056ce00e1625e52f5a71b1d5c202acd53c1a8c7bca33da458db1e4f3f2edf"


# Before changing the COMMIT, temporarily uncomment the next line so that Bazel
# displays the suggested new value for the CHECKSUM.
#INEKF_CHECKSUM = "0" * 64
Expand Down
38 changes: 15 additions & 23 deletions bindings/pydairlib/solvers/c3_py.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <drake/bindings/pydrake/common/sorted_pair_pybind.h>
#include <pybind11/eigen.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <drake/bindings/pydrake/common/sorted_pair_pybind.h>

#include "solvers/c3_miqp.h"
#include "solvers/lcs.h"
Expand All @@ -23,11 +23,11 @@ namespace pyc3 {
PYBIND11_MODULE(c3, m) {
py::class_<dairlib::solvers::LCS>(m, "LCS")
.def(py::init<const vector<MatrixXd>&, const vector<MatrixXd>&,
const vector<MatrixXd>&, const vector<VectorXd>&,
const vector<MatrixXd>&, const vector<MatrixXd>&,
const vector<MatrixXd>&, const vector<VectorXd>&, double>(),
arg("A"), arg("B"), arg("D"), arg("d"), arg("E"), arg("F"), arg("H"),
arg("c"), arg("dt"))
const vector<MatrixXd>&, const vector<VectorXd>&,
const vector<MatrixXd>&, const vector<MatrixXd>&,
const vector<MatrixXd>&, const vector<VectorXd>&, double>(),
arg("A"), arg("B"), arg("D"), arg("d"), arg("E"), arg("F"), arg("H"),
arg("c"), arg("dt"))
.def(py::init<const MatrixXd&, const MatrixXd&, const MatrixXd&,
const MatrixXd&, const MatrixXd&, const MatrixXd&,
const MatrixXd&, const VectorXd&, int, double>(),
Expand All @@ -44,17 +44,10 @@ PYBIND11_MODULE(c3, m) {
.def("Simulate", &LCS::Simulate);

m.def("LinearizePlantToLCS",
&dairlib::solvers::LCSFactory::LinearizePlantToLCS,
py::arg("plant"),
py::arg("context"),
py::arg("plant_ad"),
py::arg("context_ad"),
py::arg("contact_geoms"),
py::arg("num_friction_directions"),
py::arg("mu"),
py::arg("dt"),
py::arg("N"),
py::arg("contact_model"));
&dairlib::solvers::LCSFactory::LinearizePlantToLCS, py::arg("plant"),
py::arg("context"), py::arg("plant_ad"), py::arg("context_ad"),
py::arg("contact_geoms"), py::arg("num_friction_directions"),
py::arg("mu"), py::arg("dt"), py::arg("N"), py::arg("contact_model"));

{
using Enum = dairlib::solvers::ContactModel;
Expand All @@ -64,13 +57,13 @@ PYBIND11_MODULE(c3, m) {
.value("kAnitescu", Enum::kAnitescu);
}

py::class_<dairlib::solvers::C3::CostMatrices>(m, "CostMatrices")
py::class_<dairlib::solvers::C3Base::CostMatrices>(m, "CostMatrices")
.def(py::init<const std::vector<Eigen::MatrixXd>&, const std::vector<Eigen::MatrixXd>&,
const std::vector<Eigen::MatrixXd>&, const std::vector<Eigen::MatrixXd>&>(),
arg("Q"), arg("R"), arg("G"), arg("U"));

py::class_<dairlib::solvers::C3MIQP>(m, "C3MIQP")
.def(py::init<const LCS&, const dairlib::solvers::C3::CostMatrices&,
.def(py::init<const LCS&, const dairlib::solvers::C3Base::CostMatrices&,
const vector<VectorXd>&, const C3Options&>(),
arg("LCS"), arg("costs"), arg("x_des"), arg("c3_options"))
.def("Solve", &C3MIQP::Solve, arg("x0"), arg("verbose") = false)
Expand All @@ -80,10 +73,11 @@ PYBIND11_MODULE(c3, m) {
arg("G"), arg("admm_iteration"), arg("verbose") = false)
.def("SolveQP", &C3MIQP::SolveQP, arg("x0"), arg("G"), arg("WD"),
arg("admm_iteration"), arg("is_final_solve"))
.def("SolveProjection", &C3MIQP::SolveProjection, arg("U"), arg("WZ"), arg("admm_iteration"))
.def("SolveProjection", &C3MIQP::SolveProjection, arg("U"), arg("WZ"),
arg("admm_iteration"))
.def("AddLinearConstraint", &C3MIQP::AddLinearConstraint, arg("A"),
arg("lower_bound"), arg("upper_bound"), arg("constraint"))
.def("RemoveConstraints", &C3MIQP::RemoveConstraints)
.def("RemoveConstraints", &C3MIQP::RemoveUserConstraints)
.def("GetFullSolution", &C3MIQP::GetFullSolution)
.def("GetStateSolution", &C3MIQP::GetStateSolution)
.def("GetForceSolution", &C3MIQP::GetForceSolution)
Expand All @@ -102,8 +96,6 @@ PYBIND11_MODULE(c3, m) {
.def_readwrite("warm_start", &C3Options::warm_start)
.def_readwrite("use_predicted_x0", &C3Options::use_predicted_x0)
.def_readwrite("end_on_qp_step", &C3Options::end_on_qp_step)
.def_readwrite("use_robust_formulation",
&C3Options::use_robust_formulation)
.def_readwrite("solve_time_filter_alpha",
&C3Options::solve_time_filter_alpha)
.def_readwrite("publish_frequency", &C3Options::publish_frequency)
Expand Down
3 changes: 3 additions & 0 deletions examples/Cassie/cassie_state_estimator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,9 @@ void CassieStateEstimator::DoCalcNextUpdateTime(
const auto& self = dynamic_cast<const CassieStateEstimator&>(system);
return self.Update(c, s);
};
auto& uu_events = events->get_mutable_unrestricted_update_events();
uu_events.AddEvent(UnrestrictedUpdateEvent<double>(
drake::systems::TriggerType::kTimed, callback));
} else {
*time = INFINITY;
}
Expand Down
71 changes: 41 additions & 30 deletions examples/Cassie/diagrams/osc_running_controller_diagram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ namespace controllers {

OSCRunningControllerDiagram::OSCRunningControllerDiagram(
drake::multibody::MultibodyPlant<double>& plant,
const string& osc_running_gains_filename, const string& osqp_settings_filename)
const string& osc_running_gains_filename,
const string& osqp_settings_filename)
: plant_(&plant),
pos_map(multibody::MakeNameToPositionsMap(plant)),
vel_map(multibody::MakeNameToVelocitiesMap(plant)),
Expand Down Expand Up @@ -155,19 +156,20 @@ OSCRunningControllerDiagram::OSCRunningControllerDiagram(
auto state_receiver = builder.AddSystem<systems::RobotOutputReceiver>(plant);
auto command_sender = builder.AddSystem<systems::RobotCommandSender>(plant);
auto osc = builder.AddSystem<systems::controllers::OperationalSpaceControl>(
plant, plant, plant_context.get(), plant_context.get(), true);
plant, plant_context.get(), true);
auto radio_parser = builder.AddSystem<systems::RadioParser>();
auto failure_aggregator =
builder.AddSystem<systems::ControllerFailureAggregator>(
control_channel_name_, 1);

/**** OSC setup ****/
/// REGULARIZATION COSTS
osc->SetAccelerationCostWeights(osc_running_gains.w_accel * osc_running_gains.W_acceleration);
osc->SetAccelerationCostWeights(osc_running_gains.w_accel *
osc_running_gains.W_acceleration);
osc->SetInputSmoothingCostWeights(osc_running_gains.w_input_reg *
osc_running_gains.W_input_regularization);
osc_running_gains.W_input_regularization);
osc->SetInputCostWeights(osc_running_gains.w_input *
osc_running_gains.W_input_regularization);
osc_running_gains.W_input_regularization);
osc->SetLambdaContactRegularizationWeight(
osc_running_gains.w_lambda * osc_running_gains.W_lambda_c_regularization);
osc->SetLambdaHolonomicRegularizationWeight(
Expand All @@ -179,14 +181,22 @@ OSCRunningControllerDiagram::OSCRunningControllerDiagram(
// Contact information for OSC
osc->SetContactFriction(osc_running_gains.mu);

osc->AddStateAndContactPoint(RunningFsmState::kLeftStance,
&left_toe_evaluator);
osc->AddStateAndContactPoint(RunningFsmState::kLeftStance,
&left_heel_evaluator);
osc->AddStateAndContactPoint(RunningFsmState::kRightStance,
&right_toe_evaluator);
osc->AddStateAndContactPoint(RunningFsmState::kRightStance,
&right_heel_evaluator);
osc->AddContactPoint("left_toe",
std::unique_ptr<multibody::WorldPointEvaluator<double>>(
&left_toe_evaluator),
{RunningFsmState::kLeftStance});
osc->AddContactPoint("left_heel",
std::unique_ptr<multibody::WorldPointEvaluator<double>>(
&left_heel_evaluator),
{RunningFsmState::kLeftStance});
osc->AddContactPoint("right_toe",
std::unique_ptr<multibody::WorldPointEvaluator<double>>(
&right_toe_evaluator),
{RunningFsmState::kRightStance});
osc->AddContactPoint("right_heel",
std::unique_ptr<multibody::WorldPointEvaluator<double>>(
&right_heel_evaluator),
{RunningFsmState::kRightStance});

// Fix the springs in the dynamics
evaluators.add_evaluator(&left_fixed_knee_spring);
Expand All @@ -196,8 +206,9 @@ OSCRunningControllerDiagram::OSCRunningControllerDiagram(
evaluators.add_evaluator(&left_loop);
evaluators.add_evaluator(&right_loop);


osc->AddKinematicConstraint(&evaluators);
osc->AddKinematicConstraint(
std::unique_ptr<const multibody::KinematicEvaluatorSet<double>>(
&evaluators));

/**** Tracking Data *****/

Expand All @@ -208,8 +219,8 @@ OSCRunningControllerDiagram::OSCRunningControllerDiagram(
osc_running_gains.vel_scale_trans_lateral);

auto pelvis_trans_traj_generator =
builder.AddSystem<PelvisTransTrajGenerator>(
plant, plant_context.get(), feet_contact_points);
builder.AddSystem<PelvisTransTrajGenerator>(plant, plant_context.get(),
feet_contact_points);
pelvis_trans_traj_generator->SetSLIPParams(
osc_running_gains.rest_length, osc_running_gains.rest_length_offset);
auto l_foot_traj_generator = builder.AddSystem<FootTrajGenerator>(
Expand Down Expand Up @@ -261,8 +272,8 @@ OSCRunningControllerDiagram::OSCRunningControllerDiagram(
right_foot_tracking_data->AddStateAndPointToTrack(
RunningFsmState::kLeftFlight, "toe_right");

left_foot_tracking_data->AddStateAndPointToTrack(
RunningFsmState::kLeftFlight, "toe_left");
left_foot_tracking_data->AddStateAndPointToTrack(RunningFsmState::kLeftFlight,
"toe_left");
right_foot_tracking_data->AddStateAndPointToTrack(
RunningFsmState::kRightFlight, "toe_right");

Expand All @@ -274,17 +285,17 @@ OSCRunningControllerDiagram::OSCRunningControllerDiagram(
"right_hip_traj", osc_running_gains.K_p_swing_foot,
osc_running_gains.K_d_swing_foot, osc_running_gains.W_swing_foot, plant,
plant);
left_hip_tracking_data->AddStateAndPointToTrack(
RunningFsmState::kRightStance, "pelvis");
right_hip_tracking_data->AddStateAndPointToTrack(
RunningFsmState::kLeftStance, "pelvis");
right_hip_tracking_data->AddStateAndPointToTrack(
RunningFsmState::kLeftFlight, "pelvis");
left_hip_tracking_data->AddStateAndPointToTrack(
RunningFsmState::kRightFlight, "pelvis");

left_hip_tracking_data->AddStateAndPointToTrack(
RunningFsmState::kLeftFlight, "pelvis");
left_hip_tracking_data->AddStateAndPointToTrack(RunningFsmState::kRightStance,
"pelvis");
right_hip_tracking_data->AddStateAndPointToTrack(RunningFsmState::kLeftStance,
"pelvis");
right_hip_tracking_data->AddStateAndPointToTrack(RunningFsmState::kLeftFlight,
"pelvis");
left_hip_tracking_data->AddStateAndPointToTrack(RunningFsmState::kRightFlight,
"pelvis");

left_hip_tracking_data->AddStateAndPointToTrack(RunningFsmState::kLeftFlight,
"pelvis");
right_hip_tracking_data->AddStateAndPointToTrack(
RunningFsmState::kRightFlight, "pelvis");

Expand Down
64 changes: 33 additions & 31 deletions examples/Cassie/diagrams/osc_walking_controller_diagram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ OSCWalkingControllerDiagram::OSCWalkingControllerDiagram(
left_right_foot({left_toe_origin, right_toe_origin}),
left_foot_points({left_heel, left_toe}),
right_foot_points({right_heel, right_toe}),
view_frame_(
std::make_shared<multibody::WorldYawViewFrame<double>>(plant.GetBodyByName("pelvis"))),
view_frame_(std::make_shared<multibody::WorldYawViewFrame<double>>(
plant.GetBodyByName("pelvis"))),
left_toe_evaluator(multibody::WorldPointEvaluator(
plant, left_toe.first, left_toe.second, *view_frame_,
Matrix3d::Identity(), Vector3d::Zero(), {1, 2})),
Expand Down Expand Up @@ -198,16 +198,17 @@ OSCWalkingControllerDiagram::OSCWalkingControllerDiagram(
swing_ft_accel_gain_multiplier_samples[2](2, 2) *= 0;
swing_ft_accel_gain_multiplier_samples[3](2, 2) *= 0;
auto swing_ft_accel_gain_multiplier_gain_multiplier =
std::make_shared<PiecewisePolynomial<double>>(PiecewisePolynomial<double>::FirstOrderHold(
swing_ft_accel_gain_multiplier_breaks,
swing_ft_accel_gain_multiplier_samples));
std::make_shared<PiecewisePolynomial<double>>(
PiecewisePolynomial<double>::FirstOrderHold(
swing_ft_accel_gain_multiplier_breaks,
swing_ft_accel_gain_multiplier_samples));

/**** Initialize all the leaf systems ****/

auto state_receiver = builder.AddSystem<systems::RobotOutputReceiver>(plant);
auto command_sender = builder.AddSystem<systems::RobotCommandSender>(plant);
auto osc = builder.AddSystem<systems::controllers::OperationalSpaceControl>(
plant, plant, plant_context.get(), plant_context.get(), true);
plant, plant_context.get(), true);
auto fsm = builder.AddSystem<systems::TimeBasedFiniteStateMachine>(
plant, fsm_states, state_durations);
auto liftoff_event_time =
Expand All @@ -234,28 +235,26 @@ OSCWalkingControllerDiagram::OSCWalkingControllerDiagram(
// Contact information for OSC
osc->SetContactFriction(osc_walking_gains.mu);

osc->AddStateAndContactPoint(left_stance_state, &left_toe_evaluator);
osc->AddStateAndContactPoint(left_stance_state, &left_heel_evaluator);
osc->AddStateAndContactPoint(right_stance_state, &right_toe_evaluator);
osc->AddStateAndContactPoint(right_stance_state, &right_heel_evaluator);
if (has_double_stance) {
osc->AddStateAndContactPoint(post_left_double_support_state,
&left_toe_evaluator);
osc->AddStateAndContactPoint(post_left_double_support_state,
&left_heel_evaluator);
osc->AddStateAndContactPoint(post_left_double_support_state,
&right_toe_evaluator);
osc->AddStateAndContactPoint(post_left_double_support_state,
&right_heel_evaluator);
osc->AddStateAndContactPoint(post_right_double_support_state,
&left_toe_evaluator);
osc->AddStateAndContactPoint(post_right_double_support_state,
&left_heel_evaluator);
osc->AddStateAndContactPoint(post_right_double_support_state,
&right_toe_evaluator);
osc->AddStateAndContactPoint(post_right_double_support_state,
&right_heel_evaluator);
}
osc->AddContactPoint("left_toe",
std::unique_ptr<multibody::WorldPointEvaluator<double>>(
&left_toe_evaluator),
{left_stance_state, post_left_double_support_state,
post_right_double_support_state});
osc->AddContactPoint("left_heel",
std::unique_ptr<multibody::WorldPointEvaluator<double>>(
&left_heel_evaluator),
{left_stance_state, post_left_double_support_state,
post_right_double_support_state});
osc->AddContactPoint("right_toe",
std::unique_ptr<multibody::WorldPointEvaluator<double>>(
&right_toe_evaluator),
{right_stance_state, post_left_double_support_state,
post_right_double_support_state});
osc->AddContactPoint("right_heel",
std::unique_ptr<multibody::WorldPointEvaluator<double>>(
&right_heel_evaluator),
{right_stance_state, post_left_double_support_state,
post_right_double_support_state});

evaluators.add_evaluator(&left_loop);
evaluators.add_evaluator(&right_loop);
Expand All @@ -266,7 +265,8 @@ OSCWalkingControllerDiagram::OSCWalkingControllerDiagram(
evaluators.add_evaluator(&left_fixed_ankle_spring);
evaluators.add_evaluator(&right_fixed_ankle_spring);

osc->AddKinematicConstraint(&evaluators);
osc->AddKinematicConstraint(
std::unique_ptr<multibody::KinematicEvaluatorSet<double>>(&evaluators));

/**** Trajectory Generators ****/

Expand Down Expand Up @@ -346,8 +346,10 @@ OSCWalkingControllerDiagram::OSCWalkingControllerDiagram(
"swing_ft_traj", osc_walking_gains.K_p_swing_foot,
osc_walking_gains.K_d_swing_foot, osc_walking_gains.W_swing_foot, plant,
plant);
swing_ft_traj_global_->AddStateAndPointToTrack(left_stance_state, "toe_right");
swing_ft_traj_global_->AddStateAndPointToTrack(right_stance_state, "toe_left");
swing_ft_traj_global_->AddStateAndPointToTrack(left_stance_state,
"toe_right");
swing_ft_traj_global_->AddStateAndPointToTrack(right_stance_state,
"toe_left");
swing_ft_traj_local_->SetTimeVaryingPDGainMultiplier(
swing_ft_gain_multiplier_gain_multiplier);
swing_ft_traj_local_->SetTimerVaryingFeedForwardAccelMultiplier(
Expand Down
2 changes: 1 addition & 1 deletion examples/Cassie/networking/cassie_udp_publisher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ std::string CassieUDPPublisher::make_name(const std::string& address,
// period or publish period = 0.0 was passed to the constructor).
drake::systems::EventStatus CassieUDPPublisher::PublishInputAsUDPMessage(
const drake::systems::Context<double>& context) const {
SPDLOG_TRACE(drake::log(), "Publishing UDP {} message", address_);
SPDLOG_TRACE("Publishing UDP {} message", address_);

// Converts the input into message bytes.
const drake::AbstractValue* const input_value =
Expand Down
Loading