[英]Calling super().__init__() on subclass of ForceElement causes No constructor defined
我正在尝试按如下方式创建自定义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!
你没有向我们展示父母的定义。
我有点惊讶你没有看到这个诊断:
TypeError: object.__init__() takes exactly one argument (the instance to initialize)
我想您使用的框架会引发“无构造函数”,以提醒您在使用父 class 之前还有更多代码要实现。
请查看此处的文档ForceElement
; “ForceElement 允许在 MultibodyTree 模型中建模 state 和时间相关力”。 也就是说,车轮上的扭矩为 function 的力元不能建模为ForceElement
。 我相信您想要的是FrontWheelSystem
,作为LeafSystem
,output 是您想要的 model 的力量。 您可以通过连接到 get_actuation_input_port() 的执行器或连接到get_actuation_input_port()
的外部应用空间力将 model 的外力施加到get_applied_spatial_force_input_port()
。
总结几条评论成正确答案
通过 ekhumoro
错误消息表明
ForceElement
class 不支持子类化。 也就是说,drake 的 python 绑定不会为这个 class 包装__init__
方法 - 所以大概ForceElement.__init__
会引发AttributeError
。
埃里克·库西诺
这个(ForceElement)不是一个蹦床class,这是pybind11允许绑定C++ class的Python子类所必需的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.