Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
s5suzuki committed May 20, 2024
1 parent 86dbaf5 commit 71b2d40
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 65 deletions.
30 changes: 10 additions & 20 deletions example/cs/Samples/Custom.cs
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
using AUTD3Sharp;
using AUTD3Sharp.Gain;
using AUTD3Sharp.Modulation;
using AUTD3Sharp.Derive;
using AUTD3Sharp.Utils;
using static AUTD3Sharp.Units;

namespace Samples;

[Gain]
partial class MyFocus(Vector3d point)
{
private Dictionary<int, Drive[]> Calc(Geometry geometry)
{
return Transform(geometry, (dev, tr) =>
{
var tp = tr.Position;
var dist = (tp - point).L2Norm;
var phase = Phase.FromRad(dist * dev.Wavenumber);
return new Drive { Phase = phase, Intensity = EmitIntensity.Max };
});
}
}

internal static class CustomTest
internal static class TransTest
{
public static async Task Test<T>(Controller<T> autd)
{
var config = Silencer.Default();
await autd.SendAsync(config);

var m = new Sine(150 * Hz);
var g = new MyFocus(autd.Geometry.Center + new Vector3d(0, 0, 150));

var g = new Custom(
(dev, tr) => (dev.Idx, tr.Idx) switch
{
(0, 0) => new Drive(new Phase(0), EmitIntensity.Max),
(0, 248) => new Drive(new Phase(0), EmitIntensity.Max),
_ => Drive.Null
}
);
await autd.SendAsync((m, g));
}
}
4 changes: 2 additions & 2 deletions example/cs/Samples/SampleRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ public static async Task Run<T>(Controller<T> autd)
(FocusSTMTest.Test, "FocusSTM test"),
(GainSTMTest.Test, "GainSTM test"),
(GainHoloTest.Test, "Multiple foci test"),
(CustomTest.Test, "Custom Gain & Modulation test"),
(UserDefinedTest.Test, "User-defined Gain & Modulation test"),
(FlagTest.Test, "Flag test"),
(TransTest.Test, "TransducerTest test"),
(Custom.Test, "Custom gain test"),

Check failure on line 22 in example/cs/Samples/SampleRunner.cs

View workflow job for this annotation

GitHub Actions / build-cs-ubuntu-latest

'Custom' does not contain a definition for 'Test'

Check failure on line 22 in example/cs/Samples/SampleRunner.cs

View workflow job for this annotation

GitHub Actions / build-cs-ubuntu-latest

'Custom' does not contain a definition for 'Test'

Check failure on line 22 in example/cs/Samples/SampleRunner.cs

View workflow job for this annotation

GitHub Actions / build-unity-ubuntu-latest

'Custom' does not contain a definition for 'Test'

Check failure on line 22 in example/cs/Samples/SampleRunner.cs

View workflow job for this annotation

GitHub Actions / build-unity-ubuntu-latest

'Custom' does not contain a definition for 'Test'

Check failure on line 22 in example/cs/Samples/SampleRunner.cs

View workflow job for this annotation

GitHub Actions / build-cs-windows-latest

'Custom' does not contain a definition for 'Test'

Check failure on line 22 in example/cs/Samples/SampleRunner.cs

View workflow job for this annotation

GitHub Actions / build-cs-windows-latest

'Custom' does not contain a definition for 'Test'

Check failure on line 22 in example/cs/Samples/SampleRunner.cs

View workflow job for this annotation

GitHub Actions / build-unity-windows-latest

'Custom' does not contain a definition for 'Test'

Check failure on line 22 in example/cs/Samples/SampleRunner.cs

View workflow job for this annotation

GitHub Actions / build-unity-windows-latest

'Custom' does not contain a definition for 'Test'

Check failure on line 22 in example/cs/Samples/SampleRunner.cs

View workflow job for this annotation

GitHub Actions / build-cs-macos-latest

'Custom' does not contain a definition for 'Test'

Check failure on line 22 in example/cs/Samples/SampleRunner.cs

View workflow job for this annotation

GitHub Actions / build-cs-macos-latest

'Custom' does not contain a definition for 'Test'

Check failure on line 22 in example/cs/Samples/SampleRunner.cs

View workflow job for this annotation

GitHub Actions / build-unity-macos-latest

'Custom' does not contain a definition for 'Test'

Check failure on line 22 in example/cs/Samples/SampleRunner.cs

View workflow job for this annotation

GitHub Actions / build-unity-macos-latest

'Custom' does not contain a definition for 'Test'
(GroupByTransducerTest.Test, "Group (by Transducer) test")
};
if (autd.Geometry.NumDevices >= 2) examples.Add((GroupByDeviceTest.Test, "Group (by Device) test"));
Expand Down
26 changes: 0 additions & 26 deletions example/cs/Samples/TransTest.cs

This file was deleted.

36 changes: 36 additions & 0 deletions example/cs/Samples/UserDefined.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using AUTD3Sharp;
using AUTD3Sharp.Modulation;
using AUTD3Sharp.Derive;
using AUTD3Sharp.Utils;
using static AUTD3Sharp.Units;

namespace Samples;

[Gain]
partial class MyFocus(Vector3d point)
{
private Dictionary<int, Drive[]> Calc(Geometry geometry)
{
return Transform(geometry, (dev, tr) =>
{
var tp = tr.Position;
var dist = (tp - point).L2Norm;
var phase = Phase.FromRad(dist * dev.Wavenumber);
return new Drive { Phase = phase, Intensity = EmitIntensity.Max };
});
}
}

internal static class UserDefinedTest
{
public static async Task Test<T>(Controller<T> autd)
{
var config = Silencer.Default();
await autd.SendAsync(config);

var m = new Sine(150 * Hz);
var g = new MyFocus(autd.Geometry.Center + new Vector3d(0, 0, 150));

await autd.SendAsync((m, g));
}
}
3 changes: 2 additions & 1 deletion example/fs/Samples/BesselBeam.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ open AUTD3Sharp
open AUTD3Sharp.Gain
open AUTD3Sharp.Modulation
open AUTD3Sharp.Utils
open type AUTD3Sharp.Units

module BesselBeamTest =
let Test<'T> (autd : Controller<'T>) =
(Silencer.Default()) |> autd.SendAsync |> Async.AwaitTask |> Async.RunSynchronously |> ignore;

let m = new Sine 150;
let m = new Sine (150u * Hz);

let start = autd.Geometry.Center;
let dir = Vector3d.UnitZ;
Expand Down
1 change: 1 addition & 0 deletions example/fs/Samples/Flag.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
open AUTD3Sharp
open System
open System.Threading.Tasks
open type AUTD3Sharp.Units

module FlagTest =
let Test<'T> (autd : Controller<'T>) =
Expand Down
3 changes: 2 additions & 1 deletion example/fs/Samples/FocusTest.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ open AUTD3Sharp
open AUTD3Sharp.Gain
open AUTD3Sharp.Modulation
open AUTD3Sharp.Utils
open type AUTD3Sharp.Units

module FocusTest =
let Test<'T> (autd : Controller<'T>) =
(Silencer.Default()) |> autd.SendAsync |> Async.AwaitTask |> Async.RunSynchronously |> ignore;

let m = new Sine 150;
let m = new Sine (150u * Hz);
let g = new Focus(autd.Geometry.Center + Vector3d(0, 0, 150));
(m, g) |> autd.SendAsync |> Async.AwaitTask |> Async.RunSynchronously |> ignore;
7 changes: 4 additions & 3 deletions example/fs/Samples/GainHoloTest.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ open AUTD3Sharp
open AUTD3Sharp.Gain.Holo
open AUTD3Sharp.Modulation
open AUTD3Sharp.Utils
open type AUTD3Sharp.Units

module GainHoloTest =
let Test<'T> (autd : Controller<'T>) =
(Silencer.Default()) |> autd.SendAsync |> Async.AwaitTask |> Async.RunSynchronously |> ignore;

let m = new Sine 150;
let m = new Sine (150u * Hz);

let center = autd.Geometry.Center + Vector3d(0, 0, 150);
let backend = new NalgebraBackend();
let g = (new GSPAT<NalgebraBackend>(backend))
.AddFocus(center + 20.0 * Vector3d.UnitX, 5e3 * Amplitude.Units.Pascal)
.AddFocus(center - 20.0 * Vector3d.UnitX, 5e3 * Amplitude.Units.Pascal);
.AddFocus(center + 20.0 * Vector3d.UnitX, 5e3 * Pa)
.AddFocus(center - 20.0 * Vector3d.UnitX, 5e3 * Pa);

(m, g) |> autd.SendAsync |> Async.AwaitTask |> Async.RunSynchronously |> ignore;
5 changes: 3 additions & 2 deletions example/fs/Samples/GroupTest.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open AUTD3Sharp
open AUTD3Sharp.Gain
open AUTD3Sharp.Modulation
open AUTD3Sharp.Utils
open type AUTD3Sharp.Units

module GroupByDeviceTest =
let Test<'T> (autd : Controller<'T>) =
Expand All @@ -15,7 +16,7 @@ module GroupByDeviceTest =
| _ -> null
)
.Set("null", new Static(), new Null())
.Set("focus", new Sine(150 * Hz), new Focus(autd.Geometry.Center + new Vector3d(0,0,150)))
.Set("focus", new Sine(150u * Hz), new Focus(autd.Geometry.Center + new Vector3d(0,0,150)))
.SendAsync()|> Async.AwaitTask |> Async.RunSynchronously |> ignore;

module GroupByTransducerTest =
Expand All @@ -29,6 +30,6 @@ module GroupByTransducerTest =
let grouping (dev: Device) (tr: Transducer) =
if (tr.Position.X < cx) then "focus" :> obj else "null" :> obj
let g = (new Group(grouping)).Set("focus", g1).Set("null", g2);
let m = new Sine(150 * Hz);
let m = new Sine(150u * Hz);

(m, g) |> autd.SendAsync |> Async.AwaitTask |> Async.RunSynchronously |> ignore;
3 changes: 2 additions & 1 deletion example/fs/Samples/Plane.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ open AUTD3Sharp
open AUTD3Sharp.Gain
open AUTD3Sharp.Modulation
open AUTD3Sharp.Utils
open type AUTD3Sharp.Units

module PlaneTest =
let Test<'T> (autd : Controller<'T>) =
(Silencer.Default()) |> autd.SendAsync |> Async.AwaitTask |> Async.RunSynchronously |> ignore;

let m = new Sine(150 * Hz);
let m = new Sine(150u * Hz);
let g = new Plane(new Vector3d(0,0,1));
(m, g) |> autd.SendAsync |> Async.AwaitTask |> Async.RunSynchronously |> ignore;
7 changes: 3 additions & 4 deletions example/fs/Samples/STMTest.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ open AUTD3Sharp.Gain
open AUTD3Sharp.Modulation
open AUTD3Sharp.Utils
open System.Threading.Tasks
open type AUTD3Sharp.Units

module STMTest =
let GainSTMTest<'T> (autd : Controller<'T>) =
Expand All @@ -19,9 +20,8 @@ module STMTest =
|> List.map (fun i -> (2.0 * Math.PI * (float)i / 200.0))
|> List.map (fun theta -> (center + 30.0 * Vector3d(cos(theta), sin(theta), 0.0)))
|> List.map (fun p -> (new Focus(p)))
|> List.fold (fun (acc: GainSTM) v -> acc.AddGain v) (GainSTM.FromFreq(1.))
|> List.fold (fun (acc: GainSTM) v -> acc.AddGain v) (GainSTM.FromFreq(1.0 * Hz))

printfn $"Actual frequency is {stm.Freq}";
(stm )|> autd.SendAsync |> Async.AwaitTask|> ignore

let FocusSTMTest<'T> (autd : Controller<'T>) =
Expand All @@ -34,7 +34,6 @@ module STMTest =
[0..199]
|> List.map (fun i -> (2.0 * Math.PI * (float)i / 200.0))
|> List.map (fun theta -> (center + 30.0 * Vector3d(cos(theta), sin(theta), 0.0)))
|> List.fold (fun (acc: FocusSTM) v -> acc.AddFocus v) (FocusSTM.FromFreq(1.))
|> List.fold (fun (acc: FocusSTM) v -> acc.AddFocus v) (FocusSTM.FromFreq(1.0 * Hz))

printfn $"Actual frequency is {stm.Freq}";
(stm)|> autd.SendAsync |> Async.AwaitTask|> ignore
11 changes: 6 additions & 5 deletions example/fs/Samples/Transtest.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
open AUTD3Sharp
open AUTD3Sharp.Gain
open AUTD3Sharp.Modulation
open type AUTD3Sharp.Units

module TransTest =
let Test<'T> (autd : Controller<'T>) =
(Silencer.Default()) |> autd.SendAsync |> Async.AwaitTask |> Async.RunSynchronously |> ignore;

let m = new Sine(150 * Hz);
let g = new TransducerTest(fun dev tr -> match (dev.Idx, tr.Idx) with
| (0, 0) -> System.Nullable(new Drive(new Phase(byte(0)), EmitIntensity.Max))
| (0, 248) -> System.Nullable(new Drive(new Phase(byte(0)), EmitIntensity.Max))
| _ -> System.Nullable());
let m = new Sine(150u * Hz);
let g = new Custom(fun dev tr -> match (dev.Idx, tr.Idx) with
| (0, 0) -> new Drive(new Phase(byte(0)), EmitIntensity.Max)
| (0, 248) -> new Drive(new Phase(byte(0)), EmitIntensity.Max)
| _ -> Drive.Null);
(m, g) |> autd.SendAsync |> Async.AwaitTask |> Async.RunSynchronously |> ignore;
1 change: 1 addition & 0 deletions example/fs/Samples/Wav.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ open AUTD3Sharp.Gain
open AUTD3Sharp.Modulation.AudioFile
open AUTD3Sharp.Utils
open System.IO
open type AUTD3Sharp.Units

module WavTest =
let Test<'T> (autd : Controller<'T>) =
Expand Down

0 comments on commit 71b2d40

Please sign in to comment.