Crates.io | bluerobotics-ping |
lib.rs | bluerobotics-ping |
version | 0.3.3 |
source | src |
created_at | 2024-04-24 17:17:42.433291 |
updated_at | 2024-10-21 17:10:38.23237 |
description | This crate serves as the entry point for embedding applications using Rust on Blue Robotics's Ping devices family |
homepage | https://bluerobotics.com/store/sonars/echosounders/ping-sonar-r2-rp/ |
repository | https://github.com/bluerobotics/ping-rs |
max_upload_size | |
id | 1219327 |
size | 208,668 |
SONARs, or Sound Navigation And Ranging devices, transmit sound waves and measure their reflections to detect surrounding obstacles and objects.
Sonars and other acoustic devices can be crucial for marine robotics (ROVs, AUVs, boats, etc), as they can provide obstacle detection and distance estimates when the visual field is limited. Building robots with these capabilities enables precise navigation, target identification, and a considerably more efficient exploration of underwater environments.
The open source Ping Protocol allows precise control of sonar devices like those from Blue Robotics, enabling easy integration in your custom applications.
This library provides access to all capabilities of ping family devices, with all the benefits of the Rust development ecosystem!
Here is a minimal example:
use bluerobotics_ping::{
device::{Ping1D, PingDevice},
error::PingError,
};
use tokio_serial::{SerialPort, SerialPortBuilderExt};
#[tokio::main]
async fn main() -> Result<(), PingError> {
let port = tokio_serial::new("/dev/ttyUSB0", 115200).open_native_async()?;
port.clear(tokio_serial::ClearBuffer::All)?;
let ping1d = Ping1D::new(port);
println!("{:#?}", ping1d.device_information().await?);
println!("{:#?}", ping1d.general_info().await?);
println!("{:#?}", ping1d.distance().await?);
Ok(())
}
Try ping today!
To harness the capabilities of a Ping1D or Ping360 type device, instantiate the corresponding object provided by this library.
Ping has the capability to work with any kind of layer that implements asynchronous I/O traits. The current examples are focused on serial and UDP, which are the connection methods with official support from Blue Robotics.
Both device types have their own set of methods, as defined by the Ping Protocol specification.
Check the complete set of methods:
cargo run --example ping_1d -- --serial-port /dev/ttyUSB0
Parsing user provided values...
Creating your Ping 1D device
Testing set/get device id: 9
Testing set/get device id: 8
Testing set/get device id: 7
Testing set/get device id: 6
Testing set/get device id: 5
Testing set/get device id: 4
Testing set/get device id: 3
Testing set/get device id: 2
Testing set/get device id: 1
Set gain to auto: true
Test set & get with a new speed of sound: 343.0 m/s
Test set & get with default speed of sound: 1500.0 m/s
Protocol version is: 1.0.0
Device id is: 1
Gain setting is: 6
Processor temperature is: 42.63 °C
Voltage at 5V lane is: 5.006 V
The distance to target is: 4538 mm
Waiting for 30 profiles...
Received 30 profiles
Turning-off the continuous messages stream from Ping1D
For external use via UDP, consider using bridges to share your serial device to the network. Detailed instructions can be found here.
bridges --port /dev/ttyUSB0:3000000 -u 0.0.0.0:8080 --no-udp-disconnection --abr
cargo run --example ping_1d -- --udp-address 192.168.0.191 --udp-port 8080
Enjoy exploring with ping-rs! 🌊