set max linvel
This commit is contained in:
parent
ac12715471
commit
3504bc4790
|
|
@ -21,7 +21,7 @@ set(RUST_STATIC_LIBRARY "${RUST_TARGET_DIR}/${CARGO_TARGET}/${CARGO_BUILD_TYPE}/
|
||||||
|
|
||||||
idf_component_register(
|
idf_component_register(
|
||||||
SRCS "placeholder.c"
|
SRCS "placeholder.c"
|
||||||
INCLUDE_DIRS "" "${RUST_INCLUDE_DIR}"
|
INCLUDE_DIRS ""
|
||||||
PRIV_REQUIRES "${RUST_DEPS}"
|
PRIV_REQUIRES "${RUST_DEPS}"
|
||||||
)
|
)
|
||||||
idf_build_get_property(sdkconfig SDKCONFIG)
|
idf_build_get_property(sdkconfig SDKCONFIG)
|
||||||
|
|
|
||||||
25
src/ccont.rs
25
src/ccont.rs
|
|
@ -53,6 +53,17 @@ pub extern "C" fn set_input(ptr: *mut StackedController, inp: Input) {
|
||||||
controller.set_input(inp);
|
controller.set_input(inp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn set_max_linvel(ptr: *mut StackedController, max_linvel: f32) {
|
||||||
|
let controller = unsafe {
|
||||||
|
assert!(!ptr.is_null());
|
||||||
|
&mut *ptr
|
||||||
|
};
|
||||||
|
|
||||||
|
controller.set_max_linvel(max_linvel);
|
||||||
|
}
|
||||||
|
|
||||||
#[unsafe(no_mangle)]
|
#[unsafe(no_mangle)]
|
||||||
pub extern "C" fn set_cur_rot(ptr: *mut StackedController, rot: QuatC) {
|
pub extern "C" fn set_cur_rot(ptr: *mut StackedController, rot: QuatC) {
|
||||||
let controller = unsafe {
|
let controller = unsafe {
|
||||||
|
|
@ -92,3 +103,17 @@ pub extern "C" fn set_cur_pos(ptr: *mut StackedController, pos: Vec3C) {
|
||||||
|
|
||||||
controller.set_pos(pos.into());
|
controller.set_pos(pos.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn reset_pid_states(ptr: *mut StackedController){
|
||||||
|
let controller = unsafe {
|
||||||
|
assert!(!ptr.is_null());
|
||||||
|
&mut *ptr
|
||||||
|
};
|
||||||
|
controller.angvel_rt.module.pid.reset_state();
|
||||||
|
controller.rotation_rt.module.pid.reset_state();
|
||||||
|
// controller.linaccel_rt.module.pid.reset_state();
|
||||||
|
controller.linvel_rt.module.pid.reset_state();
|
||||||
|
controller.position_rt.module.pid.reset_state();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ pub struct ControllerStackConfig {
|
||||||
pub struct ControllerConfig {
|
pub struct ControllerConfig {
|
||||||
pub stack: ControllerStackConfig,
|
pub stack: ControllerStackConfig,
|
||||||
|
|
||||||
// For each motor, [Pitch, Roll, Yaw] (Rotation around x,y,z)
|
// For each motor, [Roll, Pitch, Yaw] (Rotation around x,y,z)
|
||||||
pub motor_map: [[f32; 3]; 4],
|
pub motor_map: [[f32; 3]; 4],
|
||||||
|
|
||||||
pub mass: f32,
|
pub mass: f32,
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,9 @@ pub struct StackedController {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StackedController {
|
impl StackedController {
|
||||||
|
pub fn set_max_linvel(&mut self, max_linvel: f32) {
|
||||||
|
self.position_rt.module.max_linvel = max_linvel;
|
||||||
|
}
|
||||||
pub fn new(config: ControllerConfig) -> Self {
|
pub fn new(config: ControllerConfig) -> Self {
|
||||||
let min_throttle = 0.0;
|
let min_throttle = 0.0;
|
||||||
let max_throttle = 1.0;
|
let max_throttle = 1.0;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::DroneState;
|
use crate::DroneState;
|
||||||
use crate::PidConfig;
|
use crate::PidConfig;
|
||||||
use nalgebra as na;
|
use nalgebra as na;
|
||||||
|
use nalgebra::zero;
|
||||||
|
|
||||||
pub mod acceleration;
|
pub mod acceleration;
|
||||||
pub mod angular_rate;
|
pub mod angular_rate;
|
||||||
|
|
@ -101,6 +102,12 @@ impl PidProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn reset_state(&mut self) {
|
||||||
|
self.integral = na::Vector3::<f32>::zeros();
|
||||||
|
self.last_error = na::Vector3::<f32>::zeros();
|
||||||
|
// self.last_error = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn update(
|
pub fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
target: na::Vector3<f32>,
|
target: na::Vector3<f32>,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::stacked::modules::*;
|
use crate::stacked::modules::*;
|
||||||
|
|
||||||
pub struct AngularRateController {
|
pub struct AngularRateController {
|
||||||
pid: PidProcessor,
|
pub pid: PidProcessor,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AngularRateController {
|
impl AngularRateController {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::stacked::modules::*;
|
use crate::stacked::modules::*;
|
||||||
|
|
||||||
pub struct PositionController {
|
pub struct PositionController {
|
||||||
pid: PidProcessor,
|
pub pid: PidProcessor,
|
||||||
max_linvel: f32,
|
pub max_linvel: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PositionController {
|
impl PositionController {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use nalgebra::UnitQuaternion;
|
||||||
use crate::stacked::modules::*;
|
use crate::stacked::modules::*;
|
||||||
|
|
||||||
pub struct RotationController {
|
pub struct RotationController {
|
||||||
pid: PidProcessor,
|
pub pid: PidProcessor,
|
||||||
}
|
}
|
||||||
impl RotationController {
|
impl RotationController {
|
||||||
pub fn new(pid: PidProcessor) -> Self {
|
pub fn new(pid: PidProcessor) -> Self {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::stacked::modules::*;
|
use crate::stacked::modules::*;
|
||||||
|
|
||||||
pub struct VelocityController {
|
pub struct VelocityController {
|
||||||
pid: PidProcessor,
|
pub pid: PidProcessor,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VelocityController {
|
impl VelocityController {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue