GainGroup
GainGroup
は振動子ごとに別々のGain
を使用するためのGain
である.
NOTE: デバイスごとの分割で良いのであれば,
Group
の使用を推奨する.
GainGroup
では, 振動子に対してキーを割り当て, その各キーにGain
を紐付けて使用する.
use autd3::prelude::*;
use std::collections::HashMap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let x = 0.;
let y = 0.;
let z = 0.;
let _ =
GainGroup {
key_map: |_dev| {
|tr| match tr.idx() {
0..=100 => Some("null"),
_ => Some("focus"),
}
},
gain_map: HashMap::from([
("null", BoxedGain::new(Null {})),
(
"focus",
BoxedGain::new(Focus {
pos: Point3::new(x, y, z),
option: Default::default(),
}),
),
]),
};
Ok(())
}
NOTE: Rust版は
HashMap
の値がすべて同じ型である必要があるため, ここではBoxedGain
を使用して, 型を統一している.
#include<optional>
#include<autd3.hpp>
int main() {
using namespace autd3;
const auto x = 0.0;
const auto y = 0.0;
const auto z = 0.0;
GainGroup(
[](const auto& dev) {
return [](const auto& tr) -> std::optional<const char*> {
if (tr.idx() <= 100) return "null";
return "focus";
};
},
std::unordered_map<const char*, std::shared_ptr<Gain>>{
{"focus", std::make_shared<Focus>(Point3(x, y, z), FocusOption{})},
{"null", std::make_shared<Null>()}});
return 0; }
NOTE: C++の場合, キーには
std::optional
を使用する必要がある. また, 型を統一するため,std::shared_ptr<autd3::Gain>
を使用している.
using AUTD3Sharp.Utils;
using AUTD3Sharp.Gain;
using AUTD3Sharp.Driver.Datagram;
var x = 0.0f;
var y = 0.0f;
var z = 0.0f;
new GainGroup(
keyMap: dev => tr => tr.Idx() <= 100 ? "null" : "focus",
gainMap: new Dictionary<object, IGain> {
{ "null", new Null() },
{ "focus", new Focus(pos: new Point3(x, y, z), option: new FocusOption()) }
}
);
from pyautd3 import Focus, FocusOption, Null, GainGroup
x = 1.0
y = 0.0
z = 0.0
GainGroup(
key_map=lambda _: lambda tr: "null" if tr.idx() <= 100 else "focus",
gain_map={"null": Null(), "focus": Focus(pos=[x, y, z], option=FocusOption())},
)
上の場合は, ローカルインデックスがからの振動子はNull
を, それ以外の振動子はFocus
を出力する.
NOTE: このサンプルでは, キーとして文字列を使用しているが,
HashMap
のキーとして使用できるものなら何でも良い.