diff --git a/Cargo.lock b/Cargo.lock index e0d879437ca40e888bc7b7ac5c2e9d39b1035621..761612592f2a68672de793053ff5f709fd8db3a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -299,7 +299,7 @@ dependencies = [ [[package]] name = "controller" -version = "0.6.1" +version = "0.7.0" dependencies = [ "bootloader-params", "build-support", diff --git a/controller/Cargo.toml b/controller/Cargo.toml index aff2653dbb0387db78017fb7d8851249af101c25..4bbb502c39b06c4fdccd27ed1f6e03252b999795 100644 --- a/controller/Cargo.toml +++ b/controller/Cargo.toml @@ -4,7 +4,7 @@ description = "Firmware for DC Motor Driver Hat DFR0592" authors.workspace = true edition.workspace = true license.workspace = true -version = "0.6.1" # Update in python/controller.py as well +version = "0.7.0" # Update in python/controller.py as well [lints] workspace = true diff --git a/controller/python/controller.py b/controller/python/controller.py index 42fa097f3fa1dd1024ab3159e537311a0f24bf2c..92e6f7542f1da1c9feee53615dbed3276ec38661 100644 --- a/controller/python/controller.py +++ b/controller/python/controller.py @@ -3,7 +3,7 @@ from numbers import Real from typing import Optional # Major and minor version of required firmware -_REQUIRED_FIRMWARE_VERSION = (0, 6) +_REQUIRED_FIRMWARE_VERSION = (0, 7) class FirmwareVersionMismatch(Exception): @@ -34,7 +34,7 @@ class Controller: DEVICE_ID = 0xF0 FIRMWARE_CAPABILITIES = 0xFE - PID_COEFFICIENTS_FACTOR = 1 << 4 + PID_COEFFICIENTS_FACTOR = 1 << 8 def __init__(self, i2c_bus=8): import smbus diff --git a/controller/src/logic/pid_control.rs b/controller/src/logic/pid_control.rs index 3eda827f9710a4bd6af167f93c5681d172d67db4..6677e350625b21e354f52db41c51bbbbbc7207dd 100644 --- a/controller/src/logic/pid_control.rs +++ b/controller/src/logic/pid_control.rs @@ -4,7 +4,12 @@ use core::sync::atomic::{AtomicBool, AtomicI16, AtomicI32, Ordering}; use embassy_time::{Duration, Ticker}; use pid::{Fixed, Pid}; -pub static K_P: AtomicI32 = AtomicI32::new(4); +type PidUnit = Fixed<8>; + +// Those coefficients are to be intepreted as `PidUnit` values. +// For example, if `PidUnit` is `Fixed<8>`, a value of 0x40 is +// in fact 0x40 ÷ (1 << 8) = 0.25. +pub static K_P: AtomicI32 = AtomicI32::new(0x40); pub static K_I: AtomicI32 = AtomicI32::new(0); pub static K_D: AtomicI32 = AtomicI32::new(0); @@ -12,8 +17,6 @@ static CONTROLLED_MODE: AtomicBool = AtomicBool::new(false); static LEFT_SPEED: AtomicI16 = AtomicI16::new(0); static RIGHT_SPEED: AtomicI16 = AtomicI16::new(0); -type PidUnit = Fixed<4>; - pub fn disable_controlled_mode() { CONTROLLED_MODE.store(false, Ordering::Relaxed); }