0

我正在尝试ForceElement按如下方式创建自定义

class FrontWheelForce(ForceElement):
    def __init__(self, plant):
        front_wheel = plant.GetBodyByName("front_wheel")
        front_wheel_node_index = front_wheel.index()
        pdb.set_trace()
        ForceElement.__init__(self, front_wheel.model_instance())

但是得到以下错误就行了ForceElement.__init__(self, front_wheel.model_instance())

TypeError: FrontWheelForce: No constructor defined!
4

3 回答 3

1

你没有向我们展示父母的定义。

我有点惊讶你没有看到这个诊断:

TypeError: object.__init__() takes exactly one argument (the instance to initialize)

我想您正在使用的框架会引发“无构造函数”,以提醒您在使用该父类之前还有更多代码要实现。

于 2019-10-26T16:17:36.300 回答
1

请查看此处的文档ForceElement;“ForceElement 允许在 MultibodyTree 模型中对状态和时间相关的力进行建模”。也就是说,不能将作为车轮扭矩函数的力元建模为ForceElement。我相信你想要的是 a FrontWheelSystem,作为 a LeafSystem,输出你想要建模的力。您可以通过连接到的执行器get_actuation_input_port()或作为连接到的外部施加的空间力将模型的外力施加到工厂get_applied_spatial_force_input_port()

于 2019-10-28T19:15:09.103 回答
0

总结几条评论成正确答案

通过 ekhumoro

错误消息表明ForceElement该类不支持子类化。也就是说,drake 的 python 绑定不包装__init__此类的方法 - 因此可能ForceElement.__init__会引发AttributeError.

埃里克·库西诺

this (ForceElement) 没有写成蹦床类,这是 pybind11 允许绑定 C++ 类的 Python 子类所必需的

参考: pybind11 文档ForceElement绑定

于 2019-11-04T05:50:58.260 回答