my rust in my webots with my cad :)
This commit is contained in:
parent
3ae1a34c30
commit
2924a36936
6 changed files with 602 additions and 18 deletions
398
simcontroller/Cargo.lock
generated
Normal file
398
simcontroller/Cargo.lock
generated
Normal file
|
@ -0,0 +1,398 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bindgen"
|
||||
version = "0.63.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "36d860121800b2a9a94f9b5604b332d5cffb234ce17609ea479d723dbc9d3885"
|
||||
dependencies = [
|
||||
"bitflags 1.3.2",
|
||||
"cexpr",
|
||||
"clang-sys",
|
||||
"lazy_static",
|
||||
"lazycell",
|
||||
"log",
|
||||
"peeking_take_while",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"regex",
|
||||
"rustc-hash",
|
||||
"shlex",
|
||||
"syn 1.0.109",
|
||||
"which",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||
|
||||
[[package]]
|
||||
name = "cexpr"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
|
||||
dependencies = [
|
||||
"nom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "clang-sys"
|
||||
version = "1.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4"
|
||||
dependencies = [
|
||||
"glob",
|
||||
"libc",
|
||||
"libloading",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
||||
|
||||
[[package]]
|
||||
name = "home"
|
||||
version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
|
||||
[[package]]
|
||||
name = "lazycell"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.158"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439"
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.22"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "7.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.19.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
|
||||
|
||||
[[package]]
|
||||
name = "peeking_take_while"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.86"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.37"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
|
||||
|
||||
[[package]]
|
||||
name = "rustc-hash"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.36"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "simcontroller"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
"webots",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.109"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.77"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.63"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.63"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.77",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
|
||||
|
||||
[[package]]
|
||||
name = "webots"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/katharostech/webots-rust#6becd69d86b3468d4f2311b5b6474b4dc5f57b2d"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "which"
|
||||
version = "4.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7"
|
||||
dependencies = [
|
||||
"either",
|
||||
"home",
|
||||
"once_cell",
|
||||
"rustix",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
8
simcontroller/Cargo.toml
Normal file
8
simcontroller/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "simcontroller"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
thiserror = "1.0.63"
|
||||
webots = { git = "https://github.com/katharostech/webots-rust" }
|
122
simcontroller/src/camera.rs
Normal file
122
simcontroller/src/camera.rs
Normal file
|
@ -0,0 +1,122 @@
|
|||
// MIT from HULKs
|
||||
// https://github.com/HULKs/webots-rs/blob/5c4c36012c8cc0f0fe53f67b19294605a6867649/src/camera.rs
|
||||
|
||||
use std::{ffi::CString, slice::from_raw_parts};
|
||||
|
||||
use thiserror::Error;
|
||||
use webots::{robot::Device, sys::{
|
||||
wb_camera_disable, wb_camera_enable, wb_camera_get_exposure, wb_camera_get_focal_distance,
|
||||
wb_camera_get_focal_length, wb_camera_get_fov, wb_camera_get_height, wb_camera_get_image,
|
||||
wb_camera_get_max_focal_distance, wb_camera_get_max_fov, wb_camera_get_min_focal_distance,
|
||||
wb_camera_get_min_fov, wb_camera_get_near, wb_camera_get_sampling_period, wb_camera_get_width,
|
||||
wb_camera_has_recognition, wb_camera_save_image, wb_camera_set_exposure,
|
||||
wb_camera_set_focal_distance, wb_camera_set_fov, wb_device_get_node_type, WbDeviceTag,
|
||||
WbNodeType_WB_NODE_CAMERA,
|
||||
}};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum CameraError {
|
||||
#[error("failed to get image: image data is NULL")]
|
||||
ImageDataIsNull,
|
||||
}
|
||||
|
||||
pub struct Camera(WbDeviceTag);
|
||||
|
||||
impl Camera {
|
||||
pub(crate) fn new(device: &str) -> Self {
|
||||
let device = Device::new(device).tag;
|
||||
assert_eq!(WbNodeType_WB_NODE_CAMERA, unsafe {
|
||||
wb_device_get_node_type(device)
|
||||
});
|
||||
Self(device)
|
||||
}
|
||||
|
||||
pub fn enable(&self, sampling_period: i32) {
|
||||
unsafe { wb_camera_enable(self.0, sampling_period) }
|
||||
}
|
||||
|
||||
pub fn disable(&self) {
|
||||
unsafe { wb_camera_disable(self.0) }
|
||||
}
|
||||
|
||||
pub fn get_sampling_period(&self) -> i32 {
|
||||
unsafe { wb_camera_get_sampling_period(self.0) }
|
||||
}
|
||||
|
||||
pub fn get_image(&self) -> Result<&[u8], CameraError> {
|
||||
let width = self.get_width();
|
||||
let height = self.get_height();
|
||||
unsafe {
|
||||
let image = wb_camera_get_image(self.0);
|
||||
if image.is_null() {
|
||||
return Err(CameraError::ImageDataIsNull);
|
||||
}
|
||||
Ok(from_raw_parts(image, (width * height * 4) as usize))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_width(&self) -> i32 {
|
||||
unsafe { wb_camera_get_width(self.0) }
|
||||
}
|
||||
|
||||
pub fn get_height(&self) -> i32 {
|
||||
unsafe { wb_camera_get_height(self.0) }
|
||||
}
|
||||
|
||||
pub fn get_fov(&self) -> f64 {
|
||||
unsafe { wb_camera_get_fov(self.0) }
|
||||
}
|
||||
|
||||
pub fn get_max_fov(&self) -> f64 {
|
||||
unsafe { wb_camera_get_max_fov(self.0) }
|
||||
}
|
||||
|
||||
pub fn get_min_fov(&self) -> f64 {
|
||||
unsafe { wb_camera_get_min_fov(self.0) }
|
||||
}
|
||||
|
||||
pub fn set_fov(&self, fov: f64) {
|
||||
unsafe { wb_camera_set_fov(self.0, fov) }
|
||||
}
|
||||
|
||||
pub fn get_exposure(&self) -> f64 {
|
||||
unsafe { wb_camera_get_exposure(self.0) }
|
||||
}
|
||||
|
||||
pub fn set_exposure(&self, exposure: f64) {
|
||||
unsafe { wb_camera_set_exposure(self.0, exposure) }
|
||||
}
|
||||
|
||||
pub fn get_focal_length(&self) -> f64 {
|
||||
unsafe { wb_camera_get_focal_length(self.0) }
|
||||
}
|
||||
|
||||
pub fn get_focal_distance(&self) -> f64 {
|
||||
unsafe { wb_camera_get_focal_distance(self.0) }
|
||||
}
|
||||
|
||||
pub fn get_max_focal_distance(&self) -> f64 {
|
||||
unsafe { wb_camera_get_max_focal_distance(self.0) }
|
||||
}
|
||||
|
||||
pub fn get_min_focal_distance(&self) -> f64 {
|
||||
unsafe { wb_camera_get_min_focal_distance(self.0) }
|
||||
}
|
||||
|
||||
pub fn set_focal_distance(&self, focal_distance: f64) {
|
||||
unsafe { wb_camera_set_focal_distance(self.0, focal_distance) }
|
||||
}
|
||||
|
||||
pub fn get_near(&self) -> f64 {
|
||||
unsafe { wb_camera_get_near(self.0) }
|
||||
}
|
||||
|
||||
pub fn save_image(&self, filename: &str, quality: i32) -> i32 {
|
||||
let filename = CString::new(filename).expect("CString::new failed");
|
||||
unsafe { wb_camera_save_image(self.0, filename.as_ptr(), quality) }
|
||||
}
|
||||
|
||||
pub fn has_recognition(&self) -> bool {
|
||||
unsafe { wb_camera_has_recognition(self.0) != 0 }
|
||||
}
|
||||
}
|
54
simcontroller/src/main.rs
Normal file
54
simcontroller/src/main.rs
Normal file
|
@ -0,0 +1,54 @@
|
|||
use camera::Camera;
|
||||
use webots::prelude::*;
|
||||
use std::{f64::consts::TAU, time::Duration};
|
||||
mod camera;
|
||||
|
||||
const TIME_STEP: Duration = Duration::from_millis(20);
|
||||
const MAX_SPEED: f64 = TAU;
|
||||
|
||||
struct MyRobot {
|
||||
camera: Camera,
|
||||
left_motor: Motor,
|
||||
right_motor: Motor,
|
||||
}
|
||||
|
||||
impl Robot for MyRobot {
|
||||
fn time_step(&self) -> Duration {
|
||||
TIME_STEP
|
||||
}
|
||||
|
||||
fn init() -> Self {
|
||||
let camera = Camera::new("camera7");
|
||||
|
||||
let left_motor = Motor::new("motorl");
|
||||
let right_motor = Motor::new("motorr");
|
||||
|
||||
left_motor.set_position(f64::INFINITY);
|
||||
right_motor.set_position(f64::INFINITY);
|
||||
left_motor.set_velocity(0.1 * MAX_SPEED);
|
||||
right_motor.set_velocity(0.1 * MAX_SPEED);
|
||||
|
||||
Self {
|
||||
camera,
|
||||
left_motor,
|
||||
right_motor,
|
||||
}
|
||||
}
|
||||
|
||||
fn step(&mut self, _time: StepTime) {
|
||||
|
||||
self.camera.enable(20);
|
||||
|
||||
// initialize motor speeds at 50% of MAX_SPEED.
|
||||
let mut left_speed = 0.5 * MAX_SPEED;
|
||||
let mut right_speed = 0.5 * MAX_SPEED;
|
||||
|
||||
self.left_motor.set_velocity(left_speed);
|
||||
self.right_motor.set_velocity(right_speed);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("Rust controller has started");
|
||||
webots::run_robot::<MyRobot>();
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
Webots Project File version R2023b
|
||||
perspectives: 000000ff00000000fd0000000300000000000001ca0000039ffc0200000001fb00000012005300630065006e0065005400720065006501000000000000039f00000000000000000000000100000075000003a6fc0200000001fb0000001400540065007800740045006400690074006f00720100000016000003a60000003f00ffffff000000030000076c00000039fc0100000002fb0000000e0043006f006e0073006f006c0065010000000000000a010000000000000000fb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c01000000000000076c0000006900ffffff000006f5000003a600000004000000040000000100000008fc00000000
|
||||
simulationViewPerspectives: 000000ff00000001000000020000014d000003550100000002010000000101
|
||||
sceneTreePerspectives: 000000ff00000001000000030000001f0000024d000000fa0100000002010000000201
|
||||
perspectives: 000000ff00000000fd0000000300000000000001ca0000039ffc0200000001fb00000012005300630065006e0065005400720065006501000000000000039f000000000000000000000001000001f3000003e1fc0200000001fb0000001400540065007800740045006400690074006f00720000000016000003e10000003f00ffffff000000030000076c00000110fc0100000002fb0000000e0043006f006e0073006f006c0065010000000000000a010000000000000000fb0000001a0043006f006e0073006f006c00650041006c006c0041006c006c01000000000000076c0000000000000000000007800000040c00000004000000040000000100000008fc00000000
|
||||
simulationViewPerspectives: 000000ff000000010000000200000100000002af0100000002010000000101
|
||||
sceneTreePerspectives: 000000ff00000001000000030000001f000000c0000000fa0100000002010000000201
|
||||
maximizedDockId: -1
|
||||
centralWidgetVisible: 1
|
||||
renderingMode: PLAIN
|
||||
orthographicViewHeight: 1
|
||||
textFiles: -1
|
||||
consoles: Console:All:All
|
||||
renderingDevicePerspectives: robot:camera7;1;0.15;0;0
|
||||
renderingDevicePerspectives: robot:camera7;0;0.133333;0;0.119402;1920;1080;1128;752;0
|
||||
|
|
|
@ -12,8 +12,8 @@ WorldInfo {
|
|||
basicTimeStep 16
|
||||
}
|
||||
Viewpoint {
|
||||
orientation 0.005373553293139983 -0.5150879002726926 0.8571205165655963 5.779758402826299
|
||||
position -2.481287100883719 1.1754982535361718 0.8184941756963482
|
||||
orientation -0.20252767285431608 -0.0674248654048158 0.9769526238530493 3.4959887657000683
|
||||
position 2.9865434559469093 0.7208082034535581 1.392316514841507
|
||||
followType "Pan and Tilt Shot"
|
||||
}
|
||||
TexturedBackground {
|
||||
|
@ -21,12 +21,12 @@ TexturedBackground {
|
|||
TexturedBackgroundLight {
|
||||
}
|
||||
Robot {
|
||||
translation 0.601627781577624 0.3310424902905001 0.09097176702440847
|
||||
rotation -0.07117315016156012 -0.006014052836253844 0.9974458450786 -2.973138225661935
|
||||
translation 0.4259829256496424 0.6130076483711184 0.09121779991306146
|
||||
rotation -0.07132084831144353 -0.05983736629860717 0.9956569821934573 -1.7556638990412452
|
||||
children [
|
||||
HingeJoint {
|
||||
jointParameters HingeJointParameters {
|
||||
position 1.4523620848631533e-05
|
||||
position 1.452387894238653e-05
|
||||
axis 0 1 0
|
||||
minStop -1.7
|
||||
}
|
||||
|
@ -38,8 +38,8 @@ Robot {
|
|||
}
|
||||
]
|
||||
endPoint Solid {
|
||||
translation 0.20999536585258985 -6.60630822546525e-08 -0.0001466143078223891
|
||||
rotation 0.00818412898038644 0.9998859644401825 -0.012691656643578396 1.4463555563889593e-05
|
||||
translation 0.20999536585255046 -6.606308225465158e-08 -0.0001466143620208815
|
||||
rotation 0.00818361643944395 0.9998859787237327 -0.012690861816878403 1.4463801193914388e-05
|
||||
children [
|
||||
Shape {
|
||||
appearance DamascusSteel {
|
||||
|
@ -67,12 +67,13 @@ Robot {
|
|||
}
|
||||
]
|
||||
name "camera7"
|
||||
fieldOfView 1.0856
|
||||
width 320
|
||||
height 240
|
||||
}
|
||||
HingeJoint {
|
||||
jointParameters HingeJointParameters {
|
||||
position 255.74933007077615
|
||||
position 255.23737744608914
|
||||
axis 0 1 0
|
||||
}
|
||||
device [
|
||||
|
@ -81,8 +82,8 @@ Robot {
|
|||
}
|
||||
]
|
||||
endPoint Solid {
|
||||
translation -4.7705786756717797e-05 0.3496188333737429 0.0001312094398698585
|
||||
rotation 0.4654921954528252 -0.6251558035816978 0.6264959993652238 2.268904614112613
|
||||
translation -0.00010586635003879364 0.3496188333737463 9.10168947531339e-05
|
||||
rotation 0.2742044798475611 -0.6794935439895432 0.6805148248995456 2.6043433955761808
|
||||
children [
|
||||
DEF wheel-l Shape {
|
||||
appearance TireRubber {
|
||||
|
@ -101,7 +102,7 @@ Robot {
|
|||
}
|
||||
HingeJoint {
|
||||
jointParameters HingeJointParameters {
|
||||
position -30.019721658991458
|
||||
position -21.122075062215625
|
||||
axis 0 1 0
|
||||
}
|
||||
device [
|
||||
|
@ -110,8 +111,8 @@ Robot {
|
|||
}
|
||||
]
|
||||
endPoint DEF wheel Solid {
|
||||
translation 0.00031435994125281755 -0.34981416744574356 0.00019375228355231422
|
||||
rotation 0.6432373535723704 0.542298500072152 -0.5405164602384536 1.9939183181133648
|
||||
translation -0.00017421846075908173 -0.3498141674457398 -0.00032559184261425796
|
||||
rotation 0.3117156454776022 -0.6734193996637559 0.6703280305350422 2.535812857851766
|
||||
children [
|
||||
DEF wheel-s Shape {
|
||||
appearance GenericTireAppearance {
|
||||
|
@ -154,6 +155,7 @@ Robot {
|
|||
}
|
||||
physics Physics {
|
||||
}
|
||||
controller "cruise"
|
||||
}
|
||||
Solid {
|
||||
children [
|
||||
|
|
Loading…
Reference in a new issue