Group
Using the Group
, you can group devices by device, and send different data for each group.
use autd3::prelude::*;
use std::collections::HashMap;
fn main() {
let x = 0.;
let y = 0.;
let z = 0.;
let _ =
Group::new(
|dev| match dev.idx() {
0 => Some("focus"),
1 => Some("null"),
_ => None,
},
HashMap::from([
(
"focus",
BoxedDatagram::new(Focus {
pos: Point3::new(x, y, z),
option: Default::default(),
}),
),
("null", BoxedDatagram::new(Null {})),
]),
);
}
NOTE: In the Rust version, since the values of
HashMap
must all be of the same type,BoxedDatagram
is used here to unify the types.
#include<autd3.hpp>
int main() {
using namespace autd3;
const auto x = 0.0;
const auto y = 0.0;
const auto z = 0.0;
autd3::Group(
[](const Device& dev) -> std::optional<const char*> {
if (dev.idx() == 0) {
return "null";
} else if (dev.idx() == 1) {
return "focus";
} else {
return std::nullopt;
}
},
std::unordered_map<const char*, std::shared_ptr<driver::Datagram>>{
{"focus",
std::make_shared<Focus>(Focus(Point3(x, y, z), FocusOption{}))},
{"null", std::make_shared<Null>()}});
return 0; }
NOTE: In C++,
std::optional
must be used for the keys. Also, to unify the types,std::shared_ptr<driver::Datagram>
is used.
using AUTD3Sharp;
using AUTD3Sharp.Link;
using AUTD3Sharp.Gain;
using AUTD3Sharp.Modulation;
using AUTD3Sharp.Utils;
var x = 0.0f;
var y = 0.0f;
var z = 0.0f;
new AUTD3Sharp.Group(dev =>
{
return dev.Idx() switch
{
0 => "null",
1 => "focus",
_ => null
};
},
new GroupDictionary {
{ "null", new Null() },
{ "focus", new Focus(pos: new Point3(x, y, z), option: new FocusOption()) }
}
);
from pyautd3 import Device, Group
from pyautd3.gain import Focus, FocusOption, Null
x = 0.0
y = 0.0
z = 0.0
def key_map(dev: Device) -> str | None:
if dev.idx == 0:
return "null"
if dev.idx == 1:
return "focus"
return None
Group(
key_map=key_map,
data_map={"null": Null(), "focus": Focus(pos=[x, y, z], option=FocusOption())},
)
Unlike GainGroup
, you can use any data that can be sent with the usual send
.
However, you can only group by device.
NOTE: In this sample, strings are used as keys, but you can use anything that can be used as a key for
HashMap
.