Crates.io | rtimulib-rust |
lib.rs | rtimulib-rust |
version | 0.2.1 |
source | src |
created_at | 2023-03-10 01:54:48.152485 |
updated_at | 2023-03-10 16:12:08.056721 |
description | RTIMULib2 bindings |
homepage | https://github.com/bareboat-necessities/rust-modules/tree/main/RTIMULib2/Linux/rust |
repository | |
max_upload_size | |
id | 806021 |
size | 11,093 |
Rust bindings for RTIMULib2 generated with https://rust-lang.github.io/rust-bindgen/
sudo apt install llvm-dev libclang-dev clang
cd ~
git clone https://github.com/seandepagnier/RTIMULib2
cd RTIMULib2/RTIMULib
mkdir build && cd build
cmake ..
make
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
cd ~/RTIMULib2/Linux/rust
cargo test
The Rust code example:
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 _);
}
}