3 个不稳定版本
使用旧的 Rust 2015
0.2.1 | 2023年3月10日 |
---|---|
0.2.0 | 2023年3月10日 |
0.1.0 | 2023年3月10日 |
#44 in #cd
5KB
RTIMULib2 的 Rust 绑定
使用 https://rust-lang.github.io/rust-bindgen/ 生成 RTIMULib2 的 Rust 绑定
生成绑定的步骤
- 在 Debian 上
sudo apt install llvm-dev libclang-dev clang
- 克隆并构建 RTIMULib2
cd ~
git clone https://github.com/seandepagnier/RTIMULib2
cd RTIMULib2/RTIMULib
mkdir build && cd build
cmake ..
make
- 将此目录的内容放入 RTIMULib2/Linux/rust/ 下
cd ~
git clone https://github.com/bareboat-necessities/rust-modules
cp -r rust-modules/RTIMULib2/Linux/rust ~/RTIMULib2/Linux/
- cargo build
cd ~/RTIMULib2/Linux/rust
cargo build
find . -name bindings.rs
- cargo test
cd ~/RTIMULib2/Linux/rust
cargo test
Rust 代码
Rust 代码示例
use std::{ptr, thread, time};
use std::ffi::CStr;
use std::mem::MaybeUninit;
use time::Duration;
use rtimulib_rust::{RTFusionKalman4_RTFusionKalman4_destructor, RTIMU, RTIMUMPU925x_IMUGetPollInterval, RTIMUMPU925x_IMUInit, RTIMUMPU925x_IMURead, RTIMUMPU925x_RTIMUMPU925x_destructor, RTIMUSettings, RTIMUSettings_RTIMUSettings, RTMath_displayDegrees};
fn main() {
println!("Hello RTIMULib!");
let mut instance = MaybeUninit::<RTIMUSettings>::uninit();
let settings = instance.as_mut_ptr();
unsafe {
RTIMUSettings_RTIMUSettings(settings,"\0".as_ptr());
(*settings).m_fusionType = 1;
let imu = RTIMU::createIMU(settings);
RTIMUMPU925x_IMUInit(imu as *mut _);
let fusion = (*imu).m_fusion;
(*fusion).m_slerpPower = 0.02;
(*fusion).m_enableGyro = true;
(*fusion).m_enableAccel = true;
(*fusion).m_enableCompass = true;
let poll = RTIMUMPU925x_IMUGetPollInterval(imu as *mut _);
println!("Poll: {}", poll);
thread::sleep(Duration::from_millis((poll * 1000) as _));
RTIMUMPU925x_IMURead(imu as *mut _);
let mut imu_data = (*imu).m_imuData;
let p_pose = ptr::addr_of_mut!(imu_data.fusionPose);
let deg = RTMath_displayDegrees("Deg\0".as_ptr(), p_pose);
println!("{}", CStr::from_ptr(deg).to_str().unwrap().to_owned());
RTFusionKalman4_RTFusionKalman4_destructor(fusion as *mut _);
RTIMUMPU925x_RTIMUMPU925x_destructor(imu as *mut _);
}
}
没有运行时依赖
~0–1.9MB
~37K SLoC