在德雷克中模拟弹性碰撞 [英] modelling elastic collisions in drake

查看:95
本文介绍了在德雷克中模拟弹性碰撞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试模拟雄鸭中的弹性弹跳球.但是,我还没有弄清楚如何为我加载的urdf模型设置恢复系数.德雷克是否支持点接触模型的弹性碰撞?如果是,如何设置各个参数?

I am trying to model an elastic bouncing ball in drake. However, I have not figured out how to set something like the coefficient of restitution for the urdf model I load. Does drake support elastic collisions for the point contact model? If yes how can I set the respective parameters?

我已经尝试使用plant.set_penetration_allowance(0.0001)设置渗透率,但是出现以下错误:AttributeError: 'MultibodyPlant_[float]' object has no attribute 'set_penetration_allowance'.但是,由于它是对临界阻尼系统进行建模的,所以我认为无论如何也无法解决我的问题.

I already tried setting the penetration allowance with plant.set_penetration_allowance(0.0001) but I got the following error: AttributeError: 'MultibodyPlant_[float]' object has no attribute 'set_penetration_allowance'. But since it models a critically damped system I assume it would not help with my problem anyways.

我当前的代码如下:

plane_friction_coef = CoulombFriction(static_friction=1.0, dynamic_friction=1.0)

# generate the diagram of the system
builder = DiagramBuilder()
plant, scene_graph = AddMultibodyPlantSceneGraph(builder, time_step=0.0)
parser = Parser(plant=plant)

# connect to Drake Visualizer
lcm = DrakeLcm()
ConnectDrakeVisualizer(builder, scene_graph, lcm=lcm)

# add plane to plant
X_WP = xyz_rpy_deg(xyz=[0, 0, 0], rpy_deg=[0,0,0])  # offset and orientation of plane wrt. 
world frame
plant.RegisterVisualGeometry(plant.world_body(), X_BG=X_WP, shape=HalfSpace(),
                             name='InclinedPlaneVisualGeometry', 
                             diffuse_color=np.array([1, 1, 1, 0.999]))
plant.RegisterCollisionGeometry(plant.world_body(), X_BG=X_WP, shape=HalfSpace(),
                                name='InclinedPlaneCollisionGeometry',
                                coulomb_friction=plane_friction_coef)
# set gravity in world
plant.mutable_gravity_field().set_gravity_vector(gravity_vec)

# add object from sdf or urdf file
my_object = parser.AddModelFromFile(obj_file_path, model_name='my_object')

plant.Finalize()

# add a logger
logger = LogOutput(plant.get_state_output_port(), builder)
logger.set_name('logger')
logger.set_publish_period(1 / recording_rate)

# build diagram and set its context
diagram = builder.Build()
diagram_context = diagram.CreateDefaultContext()
plant_context = diagram.GetMutableSubsystemContext(plant, diagram_context)
plant.SetPositionsAndVelocities(plant_context, gen_pos)

# start simulation
simulator = Simulator(diagram, diagram_context)
simulator.Initialize()
simulator.set_target_realtime_rate(1)
simulator.AdvanceTo(sim_time)
time_log = logger.sample_times()
state_log = logger.data()

我加载的urdf文件如下:

The urdf file I load looks like this:

<?xml version="1.0"?>
<robot name="my_ball">
  <material name="Black">
    <color rgba="0.0 0.0 0.0 1.0"/>
  </material>
  <link name="base_link">
    <inertial>
      <origin rpy="0 0 0" xyz="0.0 0.0 0.0"/>
      <mass value="5"/>
      <inertia ixx="0.05" ixy="0" ixz="0" iyy="0.05" iyz="0" izz="0.05"/>
    </inertial>
    <visual>
      <geometry>
        <sphere radius="0.2"/>
      </geometry>
      <material name="Black"/>
    </visual>

    <collision name='collision'>
     <geometry>
       <sphere radius="0.2"/>
     </geometry>

    <drake:proximity_properties>
     <drake:mu_dynamic value="1.0" />
     <drake:mu_static value="1.0" />
    </drake:proximity_properties>
   </collision>
  </link>
</robot>

推荐答案

尼古拉斯(Nicolas)

Nicolas,

不,目前我们不支持弹性碰撞,因为我们将精力集中在缓慢接近接触表面上,就像在操纵应用中一样.随着我们的联系求解器的成熟,我们一定会对此提供支持.

No, currently we do not support elastic collisions given we focused our efforts on slowly approaching contact surfaces as it is the case with manipulation applications. We will definitely support this as our contact solver matures.

话虽如此,目前尚无支持为模型指定恢复系数.

That being said, currently there is no support to specify a coefficient of restitution for your model.

最佳解决方案将取决于您的特定问题.这是一个垂直跳动的球吗?摩擦重要吗? (即球也可以水平移动吗?)是2D还是3D的盒子?

The best solution will depend on your particular problem. Is this a vertically bouncing ball? is friction important? (i.e. can the ball also move horizontally?) is it a 2D or 3D case?

从简单到复杂,我建议:

From simpler to more complex I'd suggest:

  1. 如果是一个垂直弹跳球,即1DOF,那么我建议您在LeafSystem中手动编写一个动态效果.
  2. 事件驱动"混合模型也是可能的.而且,您在在这里龙虎活虎,尽管可能是Drake的高级用法.
  3. 您可以创建自己的LeafSystem,以MBP的状态作为输入,并计算接触力作为其输出(例如,使用具有Hunt-Crossley耗散的Hertz模型之类的东西).然后,您将通过MBP端口连接作用力 MBP::get_applied_spatial_force_input_port() .
  1. If a vertically bouncing ball, 1DOF, then I'd suggest writing a the dynamics by hand in a LeafSystem.
  2. An "event driven" hybrid model is also possible. And you have an example in Drake here, though probably an advanced used of Drake.
  3. You can create your own LeafSystem that given the state of an MBP as input, computes a contact force as its output (for instance using something like a Hertz model with Hunt-Crossley dissipation). You'd then wire up the applied force through the MBP port MBP::get_applied_spatial_force_input_port().

希望这对您有所帮助.

这篇关于在德雷克中模拟弹性碰撞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆