latest pushes

This commit is contained in:
2024-12-17 22:48:38 -05:00
parent 741eed7053
commit 1f46f68425
22 changed files with 627 additions and 1 deletions

2
Package/rust/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
target
Cargo.lock

28
Package/rust/Cargo.toml Normal file
View File

@@ -0,0 +1,28 @@
[package]
name = "bellande_particle"
version = "0.1.0"
edition = "2021"
authors = ["Bellande Robotics Sensors Research Innovation Center"]
description = "A particle system using Bellande distributions for robust state estimation and localization"
license = "GPL-3.0-or-later"
repository = "https://github.com/Robotics-Sensors/bellande_particle"
documentation = "https://bellande-robotics-sensors-research-innovation-center.org/bellande_particle/docs"
homepage = "https://bellande-robotics-sensors-research-innovation-center.org"
readme = "README.md"
keywords = ["robotics", "particle-filter", "state-estimation", "localization", "bellande"]
categories = ["science::robotics", "algorithms", "mathematics", "simulation"]
[dependencies]
reqwest = { version = "0.11", features = ["json", "rustls-tls"] }
serde_json = "1.0"
structopt = "0.3"
tokio = { version = "1.0", features = ["full"] }
[dev-dependencies]
tokio-test = "0.4"
mockito = "0.31"
assert_approx_eq = "1.1"
[lib]
name = "bellande_particle"
path = "src/bellande_particle.rs"

4
Package/rust/publish.sh Executable file
View File

@@ -0,0 +1,4 @@
cp ../../README.md .
bash ../../git_scripts/push.sh
cargo publish
rm -f README.md

View File

@@ -0,0 +1,114 @@
// Copyright (C) 2024 Bellande Robotics Sensors Research Innovation Center, Ronaldson Bellande
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use reqwest;
use serde_json::{json, Value};
use std::error::Error;
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
#[structopt(name = "bellande_particle", about = "Bellande Particles Tool")]
struct Opt {
#[structopt(
long,
help = "Particle state as JSON-formatted list [x, y, heading, weight]"
)]
particle: String,
#[structopt(
long,
help = "Movement parameters as JSON-formatted list [rotation1, translation, rotation2]"
)]
movement: Option<String>,
#[structopt(
long,
help = "World information as JSON object with width, height, and markers"
)]
world: Option<String>,
#[structopt(long, help = "Particle count for random generation")]
count: Option<i32>,
}
async fn make_bellande_particles_request(
particle: Value,
movement: Option<Value>,
world: Option<Value>,
count: Option<i32>,
) -> Result<Value, Box<dyn Error>> {
let client = reqwest::Client::new();
let url = "https://bellande-robotics-sensors-research-innovation-center.org/api/Bellande_Particle/bellande_particle";
let payload = json!({
"particle": particle,
"movement": movement,
"world": world,
"count": count,
"auth": {
"authorization_key": "bellande_web_api_opensource"
}
});
let response = client
.post(url)
.header("accept", "application/json")
.header("Content-Type", "application/json")
.json(&payload)
.send()
.await?
.json::<Value>()
.await?;
Ok(response)
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let opt = Opt::from_args();
// Parse JSON strings to Values for validation
let particle: Value = serde_json::from_str(&opt.particle)
.map_err(|e| format!("Error parsing particle: {}", e))?;
// Parse optional movement
let movement: Option<Value> = match opt.movement {
Some(ref m) => {
Some(serde_json::from_str(m).map_err(|e| format!("Error parsing movement: {}", e))?)
}
None => None,
};
// Parse optional world
let world: Option<Value> = match opt.world {
Some(ref w) => {
Some(serde_json::from_str(w).map_err(|e| format!("Error parsing world: {}", e))?)
}
None => None,
};
// Run using API
match make_bellande_particles_request(particle, movement, world, opt.count).await {
Ok(result) => {
println!("{}", serde_json::to_string_pretty(&result)?);
}
Err(e) => {
eprintln!("Error: {}", e);
std::process::exit(1);
}
}
Ok(())
}