Skip to content
Snippets Groups Projects
Commit 3aea844c authored by Samuel Tardieu's avatar Samuel Tardieu
Browse files

Use 8 bits of fractional part for PID coefficients

This is needed to set meaningful k_i and k_d coefficients.
parent 839a3815
No related branches found
No related tags found
1 merge request!17Resolve "Set PID coefficients from Python"
......@@ -299,7 +299,7 @@ dependencies = [
[[package]]
name = "controller"
version = "0.6.1"
version = "0.7.0"
dependencies = [
"bootloader-params",
"build-support",
......
......@@ -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
......
......@@ -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
......
......@@ -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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment