Pamoja.Sim
0.2.0
dotnet add package Pamoja.Sim --version 0.2.0
NuGet\Install-Package Pamoja.Sim -Version 0.2.0
<PackageReference Include="Pamoja.Sim" Version="0.2.0" />
<PackageVersion Include="Pamoja.Sim" Version="0.2.0" />
<PackageReference Include="Pamoja.Sim" />
paket add Pamoja.Sim --version 0.2.0
#r "nuget: Pamoja.Sim, 0.2.0"
#:package Pamoja.Sim@0.2.0
#addin nuget:?package=Pamoja.Sim&version=0.2.0
#tool nuget:?package=Pamoja.Sim&version=0.2.0
Pamoja.Sim
Noisy and replay sensors, a recording actuator, a simulated robot that dead-reckons its pose, and a link that loses sends on a pattern. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.
Install
dotnet add package Pamoja.Sim
using Pamoja.Sim;
This pulls in Pamoja.Native, the compiled engine, and Pamoja.Codec and Pamoja.Kit. dotnet add package Pamoja is the whole framework in one package.
Example
The guide project's example, spliced here as it ran in CI.
From bindings/dotnet/samples/Pamoja.Guides/SimGuide.cs:
// The clear distance ahead, in meters, replayed from an earlier survey of the
// row, so every run sees the same row.
using var ahead = new Replay([4.0f, 3.0f, 1.5f, 0.5f]);
// The drive keeps the commands it is given instead of turning a motor.
using var drive = new RecordingActuator();
// The rover's pose comes from integrating each command over half a second.
const float Dt = 0.5f;
using var rover = new SimulatedRobot(Dt);
// The soil probe reads around 31 percent, drying half a point a reading, with a
// wobble drawn from a seed, so the same seed gives the same readings every run.
using var soil = new SimulatedSensor(31.0f, -0.5f, 0.3f, 7);
// The radio loses every third report on its way to the base.
using var station = new LoopbackBroker();
using Transport radio = Transport.Degraded(station.Rung(), dropEvery: 3);
await radio.ConnectAsync();
List<float> moisture = [];
int delivered = 0;
while (true)
{
// A replay that has handed back every reading reports that it is closed.
float clear;
try
{
clear = await ahead.ReadAsync();
}
catch (PamojaException error)
{
Console.WriteLine($"ahead ran out after {moisture.Count} readings: {error.Message}");
break;
}
(float speed, float turn) = clear > 1.0f ? (1.0f, 0.0f) : (0.0f, 1.0f);
await drive.ApplyAsync(speed);
await rover.ApplyAsync(new Twist(speed, Omega: turn));
float wet = await soil.ReadAsync();
float elapsed = moisture.Count * Dt;
moisture.Add(wet);
string report = Tenths(wet);
try
{
await radio.SendAsync("vineyard/row-4/soil", report);
delivered++;
}
catch (PamojaException)
{
}
Console.WriteLine(
$"{Tenths(elapsed)} s {Tenths(clear)} m clear:"
+ $" drive {Tenths(speed)}, turn {Tenths(turn)}, soil {report}");
}
// The drive kept every command, which is how a test says what the loop decided
// rather than only what it ended up doing.
Console.WriteLine($"drive recorded {string.Join(", ", drive.Commands.Select(Tenths))}");
// Three half-second commands at 1 m/s reach 1.5 m along x. The last turns on
// the spot at 1 rad/s for half a second, which moves the rover nowhere.
Pose pose = rover.Pose;
Console.WriteLine(
$"rover ended at x {Tenths(pose.X)} m, y {Tenths(pose.Y)} m, heading {Tenths(pose.Theta)} rad");
// A second probe with the same seed reads exactly the same values.
using var twin = new SimulatedSensor(31.0f, -0.5f, 0.3f, 7);
List<float> again = [];
foreach (float _ in moisture)
{
again.Add(await twin.ReadAsync());
}
string verdict = again.SequenceEqual(moisture) ? "the same" : "different";
Console.WriteLine($"soil a probe with the same seed read {verdict} {again.Count} values");
Console.WriteLine($"radio delivered {delivered} of {moisture.Count} soil reports and lost the third");
The same capability in every language
| Language | Package | Reference |
|---|---|---|
| Rust | pamoja-sim |
reference, docs.rs, install |
| TypeScript | @pamoja/sim |
reference, install |
| Python | pamoja-sim |
reference, install |
| C# | Pamoja.Sim |
reference, install |
Documentation
Pamoja.Simreference, every type in this namespace.- The Simulators guide, with the same example in Rust, TypeScript, and Python.
- Every capability, and the install page.
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Pamoja.Codec (>= 0.2.0)
- Pamoja.Kit (>= 0.2.0)
- Pamoja.Native (>= 0.2.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Pamoja.Sim:
| Package | Downloads |
|---|---|
|
Pamoja
The whole pamoja framework in one package: every capability of one memory-safe Rust core, behind an idiomatic C# facade, for IoT, robotics, and drones. |
|
|
Pamoja.Transports
Transports and testing: Reaching the network when no single link always works, and testing all of it with nothing plugged in. |
GitHub repositories
This package is not used by any popular GitHub repositories.