![](/img/trans.png)
[英]How can I check whether two numbers are within “x” significant figures of the precision limits of the floating point type?
[英]Is Drake obeying joint limits in this case and how can I check?
在這個簡單的例子中,我試圖了解 Drake 是否遵循聯合限制。
我有這個 URDF
<?xml version="1.0"?>
<robot name="SimpleDoublePendulum">
<link name="base">
<inertial>
<origin rpy="0 0 0" xyz="0 0 0"/>
<mass value="1"/>
<inertia ixx="0" ixy="0" ixz="0" iyy="0" iyz="0" izz="0"/>
</inertial>
<visual>
<origin xyz="0 0.1 0"/>
<geometry>
<box size="1 0.2 1"/>
</geometry>
<material name="Red"/>
</visual>
</link>
<link name="upper_arm">
<inertial>
<origin rpy="0 0 0" xyz="0 -0.5 0"/>
<mass value="1"/>
<inertia ixx="0" ixy="0" ixz="0" iyy="0" iyz="0" izz="0"/>
</inertial>
<visual>
<origin rpy="1.57079632679 0 0" xyz="0 -0.5 0"/>
<geometry>
<cylinder length="1.0" radius="0.1"/>
</geometry>
<material name="Green"/>
</visual>
</link>
<link name="lower_arm">
<inertial>
<origin rpy="0 0 0" xyz="0 -0.5 0"/>
<mass value="1"/>
<inertia ixx="0" ixy="0" ixz="0" iyy="0" iyz="0" izz="0"/>
</inertial>
<visual>
<origin rpy="1.57079632679 0 0" xyz="0 -0.5 0"/>
<geometry>
<cylinder length="1.0" radius="0.1"/>
</geometry>
<material name="Blue"/>
</visual>
</link>
<joint name="joint1" type="revolute">
<parent link="base"/>
<child link="upper_arm"/>
<origin rpy="0 0 0" xyz="0 0.0 0"/>
<axis xyz="0 0 1"/>
<limit lower="0" upper="0.2" effort="5" velocity="4" />
<dynamics damping="0.1"/>
</joint>
<joint name="joint2" type="revolute">
<parent link="upper_arm"/>
<child link="lower_arm"/>
<origin rpy="0 0 0" xyz="0 -1.0 0"/>
<axis xyz="0 0 1"/>
<!-- <limit lower="-1.87" upper="1.87" /> -->
<dynamics damping="0.1"/>
</joint>
</robot>
這是我正在運行的代碼
// ... includes and using
double target_realtime_rate = 1.0;
double simulation_time = 1000;
double max_time_step = 1.0e-4;
double Kp_ = 1.0;
double Ki_ = 0.0;
double Kd_ = 0.0;
// Fixed path to double pendulum URDF model.
static const char* const kDoublePendulumSdfPath = "double_pendulum/pendulum.urdf";
void DoMain() {
DRAKE_DEMAND(simulation_time > 0);
DiagramBuilder<double> builder;
SceneGraph<double>& scene_graph = *builder.AddSystem<SceneGraph>();
scene_graph.set_name("scene_graph");
// Load and parse double pendulum SDF from file into a tree.
MultibodyPlant<double>* dp = builder.AddSystem<MultibodyPlant<double>>(max_time_step);
dp->set_name("plant");
dp->RegisterAsSourceForSceneGraph(&scene_graph);
Parser parser(dp);
parser.AddModelFromFile(kDoublePendulumSdfPath);
// Weld the base link to world frame with no rotation.
const auto& root_link = dp->GetBodyByName("base");
dp->AddJoint<WeldJoint>("weld_base", dp->world_body(), std::nullopt,
root_link, std::nullopt,
RigidTransform<double>::Identity());
dp->AddJointActuator("a2", dp->GetJointByName("joint2"));
dp->AddJointActuator("a1", dp->GetJointByName("joint1"));
// Now the plant is complete.
dp->Finalize();
// Create PID Controller.
const Eigen::VectorXd Kp = Eigen::Vector2d(1,1) * Kp_;
const Eigen::VectorXd Ki = Eigen::Vector2d(1,1) * Ki_;
const Eigen::VectorXd Kd = Eigen::Vector2d(1,1) * Kd_;
const auto* const pid = builder.AddSystem<PidController<double>>(Kp, Ki, Kd);
builder.Connect(dp->get_state_output_port(),
pid->get_input_port_estimated_state());
builder.Connect(pid->get_output_port_control(),
dp->get_actuation_input_port());
// Set PID desired states.
auto desired_base_source = builder.AddSystem<ConstantVectorSource<double>>(Eigen::VectorXd::Zero(dp->num_multibody_states()));
builder.Connect(desired_base_source->get_output_port(),
pid->get_input_port_desired_state());
// Connect plant with scene_graph to get collision information.
DRAKE_DEMAND(!!dp->get_source_id());
builder.Connect(dp->get_geometry_poses_output_port(),
scene_graph.get_source_pose_port(dp->get_source_id().value()));
builder.Connect(scene_graph.get_query_output_port(),
dp->get_geometry_query_input_port());
ConnectDrakeVisualizer(&builder, scene_graph);
auto diagram = builder.Build();
std::unique_ptr<Context<double>> diagram_context =
diagram->CreateDefaultContext();
// Create plant_context to set velocity.
Context<double>& plant_context =
diagram->GetMutableSubsystemContext(*dp, diagram_context.get());
// Set init position.
Eigen::VectorXd positions = Eigen::VectorXd::Zero(2);
positions[0] = 0.1;
positions[1] = 0.4;
dp->SetPositions(&plant_context, positions);
Simulator<double> simulator(*diagram, std::move(diagram_context));
simulator.set_publish_every_time_step(true);
simulator.set_target_realtime_rate(target_realtime_rate);
simulator.Initialize();
simulator.AdvanceTo(simulation_time);
}
int main(int argc, char** argv) {
DoMain();
return 0;
}
我的問題是雙重的:
這是我看到的圖像的 GIF。 但是,僅使用觀察結果,關節joint1
似乎並未遵守我為其設置的關節限制。
https://user-images.githubusercontent.com/4957157/92673069-130d1d00-f2cf-11ea-8af5-a97a9817e785.gif
Drake 是否正確遵守了關節限制?
Drake 在模擬過程中並不嚴格遵守關節限制。 它將關節限制視為彈簧阻尼系統。 當關節超過關節限制時,彈簧阻尼系統會施加更大的恢復力,將關節推回到關節限制范圍內。
有沒有辦法使用 API 和 cout 來檢查這個屏幕。 有沒有辦法從模擬中讀取關節狀態?
你可以使用SignalLogger
系統,一個例子在https://github.com/RobotLocomotion/drake/blob/9c30d5b73580616badd75905da7733ff64663bb8/examples/manipulation_station/joint_teleop.py#L118-L120連接到機器人,你可以連接一個 SignalLogger 狀態給機器人端口,模擬后,您可以讀取記錄的機器人狀態,類似於https://github.com/RobotLocomotion/drake/blob/9c30d5b73580616badd75905da7733ff64663bb8/examples/manipulation_station/joint_teleop.py#L157-L16
和Sherm聊過之后,我覺得問題是慣性ixx, iyy, izz
都為零。 我認為如果您將慣性更改為非零值,那么模擬看起來會正確。
原因是我們使用相鄰鏈接的質量/慣性屬性來估計關節限制的剛度。 當慣性為零時,關節剛度為零。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.