Skip to content

Simulation を作る

既存の robot や test fixture を Fibril Simulation へ載せる作業は、MuJoCo model を作り、Manifest で virtual hardware を構成し、validate と inspect で解決結果を確認する順に進めます。 最初から full robot を組み上げるより、必要な Component を一つずつ追加すると binding と timing の問題を切り分けやすくなります。

MuJoCo model を用意する

最初に physical plant と environment を MJCF で表します。 joint、geom、actuator、sensor、camera、site には、Manifest から参照する安定した name を付けます。 fixed timestep も MJCF の <option timestep="..."> で定義します。

model の root は通常の file path か package:// URI で指定できます。 package:// を使うと、ament package の install space に置いた model と nested include を logical URI のまま解決できます。

Manifest の骨格を作る

最小の Manifest は schema と model を持ちます。

1
2
3
4
5
6
7
8
schema_version:
  major: 3
  minor: 0
model:
  path: package://my_robot_description/mujoco/robot.xml
runtime:
  mode: deterministic_ci
  episode_seed: 1

MuJoCo model の option.timestep が Device、prescribed state、actuator application など runtime schedule が載る基準 grid になります。 必要な周期を決めてから timestep を選ぶと、strict schedule の不整合を避けやすくなります。

Model attachment を使う

独立した submodel を組み合わせる場合は MuJoCo の model asset と attach を使います。 Fibril 側に別の attachment schema はありません。

1
2
3
4
5
6
<asset>
  <model name="robot" file="package://my_robot_description/mujoco/robot.xml"/>
</asset>
<worldbody>
  <attach model="robot" prefix="robot_"/>
</worldbody>

composition、namespace 適用、object name validation は MuJoCo compile に委ねます。

Component を追加する

virtual hardware は components に列挙します。 各 Component は instance-local な id、registered type、type 固有の config を持ちます。

motor servo を使う場合は、先に MJCF へ actuator semantics を定義します。

1
2
3
4
5
6
7
<actuator>
  <position name="steering_motor"
            joint="steering_joint"
            kp="6"
            kv="0.5"
            forcerange="-2.2 2.2"/>
</actuator>
components:
  - id: steering_encoder
    type: fibril_sim/encoder
    config:
      joint: steering_joint
      counts_per_revolution: 4096
      period_s: 0.001
      latency_s: 0.001

  - id: drive
    type: fibril_sim/motor
    config:
      actuator: steering_motor
      command_latency_s: 0.002
      timeout_s: 0.1
      safe_command: 0.0
      application_period_s: 0.001
      feedback_period_s: 0.001

Component の object reference は compile 後の MuJoCo model に対して検証されます。 type ごとの required field と semantics は Component reference にまとめています。

Sensor fidelity を段階的に追加する

最初の test では latency、noise、bias、quantization をゼロにすると、geometry と binding の確認に集中できます。 物理モデルが正しいことを確認してから virtual hardware parameter を増やすと、model error と sensor model error を混同しにくくなります。

components:
  - id: front_lrf
    type: fibril_sim/rangefinder
    config:
      sensor: front_rangefinder_sensor
      period_s: 0.01
      latency_s: 0.0
      range_min: 0.05
      range_max: 10.0
      bias: 0.0
      resolution: 0.0
      noise_stddev: 0.0

Prescribed object を置く

simulation 内で既知の pose または trajectory に従わせたい object は prescribed Component で表せます。 対象 body は MuJoCo mocap body として model 化します。

components:
  - id: moving_target
    type: fibril_sim/prescribed_trajectory
    config:
      body: target
      keyframes:
        - time_s: 0.0
          position: [0.0, 0.0, 0.5]
          quaternion: [1.0, 0.0, 0.0, 0.0]
        - time_s: 2.0
          position: [1.0, 0.0, 0.5]
          quaternion: [1.0, 0.0, 0.0, 0.0]

trajectory time は非負かつ狭義単調増加である必要があります。 keyframe 間は runtime が physics boundary 上で補間し、端点の外側では端の pose を保持します。

Extension を読み込む

標準 Component 以外の Component や domain semantics は SimulationExtension から追加できます。 Manifest では pluginlib class name と extension 固有の config を指定します。

1
2
3
4
extensions:
  - class: my_simulation/MyExtension
    config:
      scenario: test_a

extension は Plan construction 中に capability を宣言してから configure されます。 通常の simulation 利用者が framework 内部の runtime phase を直接組み立てる必要はありません。

validate と inspect を繰り返す

Component を追加するたびに validate を通します。

fibril_sim validate my_simulation.yaml
fibril_sim inspect my_simulation.yaml

validate が成功しても MuJoCo compile warning が存在する場合は Plan に warning として保持されます。 inspect で resolved binding、schedule、Component、extension、provenance を確認してから test や長時間 run へ進みます。