[英]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.