I am using the examples/atlas/atlas_run_dynamics.cc
, and I want to add an LQR controller to make the robot stand. I add my code
int num_act,num_states;
num_act = plant.num_actuators();
num_states = plant.num_multibody_states();
std::cout<<"num_actuators: "<<num_act<<std::endl;
std::cout<<"num_multibody_states: "<<num_states<<std::endl;
Eigen::MatrixXd Q = 10*Eigen::MatrixXd::Identity(num_states, num_states);
Eigen::MatrixXd R = Eigen::MatrixXd::Identity(num_act, num_act);
const InputPort<double>& actuation_port = plant.get_actuation_input_port();
auto controller = systems::controllers::LinearQuadraticRegulator(
plant, plant_context, Q, R,
Eigen::Matrix<double, 0, 0>::Zero() /* No cross state/control costs */,
actuation_port.get_index());
and I got:
what(): System::FixInputPortTypeCheck(): expected value of type drake::geometry::QueryObject<drake::AutoDiffXd> for input port 'geometry_query' (index 0) but the actual type was drake::geometry::QueryObject<double>. (System ::plant)
Previous questions are here:
https://stackoverflow.com/questions/65471497/how-are-you-supposed-to-use-a-controller-with-a-urdf/65471632#65471632
https://stackoverflow.com/questions/61626553/when-doing-direct-collocation-inputporteval-required-inputport0-geometr#comment109060518_61633651
But still don't understand how to "pass a diagram containing both the MultibodyPlant
and the SceneGraph
into the LQR call", and set assume_non_continuous_states_are_fixed=true
in this case.
can someone offer some specific instruction? thanks!
updates:
For it's slightly unnatural to call LQR for a system with contact
, the more ordinary way is to use a trajectory optimization method to get a trajectory, including joint torque, contact force, etc, and then use a controller, like lqr, to control the system, right?
But drake seems so complicated to me. I don't know how to use direct collocation on a model with floating base and contact points, how to add centroidal momentum constraints to the direct collocation, how to apply the joint trajectory and contact force to the model. I ran acrobot/run_lqr, acrobot/run_swing_up_traj_optimization
, but they don't have a floating base, and are not involve with contacts, besides, adding a pin joint also changed the floating base feature, right?
For more traditional software, like Vrep, my understanding is that use some trajectory optimization method to get trajectory data, and use IK/ID to get joint input, then use a controller to control the multibody model. Drake seems more powerful than other software I used, but I am kind of lost in the documents and tutorials.