Tested motor control
This commit is contained in:
parent
b4b07b505c
commit
86a33b97a9
|
@ -18,4 +18,45 @@ rb = "run --bin"
|
||||||
rrb = "run --release --bin"
|
rrb = "run --release --bin"
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
DEFMT_LOG = "debug"
|
DEFMT_LOG = "debug"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# cargo build/run
|
||||||
|
[profile.dev]
|
||||||
|
codegen-units = 1
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = true # <-
|
||||||
|
incremental = false
|
||||||
|
opt-level = 'z' # <-
|
||||||
|
overflow-checks = true # <-
|
||||||
|
|
||||||
|
# cargo test
|
||||||
|
[profile.test]
|
||||||
|
codegen-units = 1
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = true # <-
|
||||||
|
incremental = false
|
||||||
|
opt-level = 3 # <-
|
||||||
|
overflow-checks = true # <-
|
||||||
|
|
||||||
|
# cargo build/run --release
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false # <-
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 3 # <-
|
||||||
|
overflow-checks = false # <-
|
||||||
|
|
||||||
|
# cargo test --release
|
||||||
|
[profile.bench]
|
||||||
|
codegen-units = 1
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false # <-
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 3 # <-
|
||||||
|
overflow-checks = false # <-
|
||||||
|
|
||||||
|
|
|
@ -32,50 +32,3 @@ defmt-debug = []
|
||||||
defmt-info = []
|
defmt-info = []
|
||||||
defmt-warn = []
|
defmt-warn = []
|
||||||
defmt-error = []
|
defmt-error = []
|
||||||
|
|
||||||
# cargo build/run
|
|
||||||
[profile.dev]
|
|
||||||
codegen-units = 1
|
|
||||||
debug = 2
|
|
||||||
debug-assertions = true # <-
|
|
||||||
incremental = false
|
|
||||||
opt-level = 'z' # <-
|
|
||||||
overflow-checks = true # <-
|
|
||||||
|
|
||||||
# cargo test
|
|
||||||
[profile.test]
|
|
||||||
codegen-units = 1
|
|
||||||
debug = 2
|
|
||||||
debug-assertions = true # <-
|
|
||||||
incremental = false
|
|
||||||
opt-level = 3 # <-
|
|
||||||
overflow-checks = true # <-
|
|
||||||
|
|
||||||
# cargo build/run --release
|
|
||||||
[profile.release]
|
|
||||||
codegen-units = 1
|
|
||||||
debug = 2
|
|
||||||
debug-assertions = false # <-
|
|
||||||
incremental = false
|
|
||||||
lto = 'fat'
|
|
||||||
opt-level = 3 # <-
|
|
||||||
overflow-checks = false # <-
|
|
||||||
|
|
||||||
# cargo test --release
|
|
||||||
[profile.bench]
|
|
||||||
codegen-units = 1
|
|
||||||
debug = 2
|
|
||||||
debug-assertions = false # <-
|
|
||||||
incremental = false
|
|
||||||
lto = 'fat'
|
|
||||||
opt-level = 3 # <-
|
|
||||||
overflow-checks = false # <-
|
|
||||||
|
|
||||||
|
|
||||||
# uncomment this to switch from the crates.io version of defmt to its git version
|
|
||||||
# check app-template's README for instructions
|
|
||||||
# [patch.crates-io]
|
|
||||||
# defmt = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" }
|
|
||||||
# defmt-rtt = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" }
|
|
||||||
# defmt-test = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" }
|
|
||||||
# panic-probe = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" }
|
|
||||||
|
|
|
@ -13,17 +13,14 @@ fn panic() -> ! {
|
||||||
cortex_m::asm::udf()
|
cortex_m::asm::udf()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[rtic::app(
|
#[rtic::app(
|
||||||
device = stm32f4xx_hal::pac,
|
device = stm32f4xx_hal::pac,
|
||||||
dispatchers = [SPI3]
|
dispatchers = [SPI3]
|
||||||
)]
|
)]
|
||||||
mod app {
|
mod app {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
use as5048a::AS5048A;
|
use as5048a::AS5048A;
|
||||||
|
|
||||||
use stm32f4xx_hal::{
|
use stm32f4xx_hal::{
|
||||||
gpio::{gpioa, gpiob, gpioc, Output, PushPull},
|
gpio::{gpioa, gpiob, gpioc, Output, PushPull},
|
||||||
i2c,
|
i2c,
|
||||||
|
@ -40,12 +37,13 @@ mod app {
|
||||||
|
|
||||||
use rtic_monotonics::systick::prelude::*;
|
use rtic_monotonics::systick::prelude::*;
|
||||||
|
|
||||||
systick_monotonic!(Mono, 1000);
|
systick_monotonic!(Mono, 4000);
|
||||||
|
|
||||||
// Shared resources go here
|
// Shared resources go here
|
||||||
#[shared]
|
#[shared]
|
||||||
struct Shared {
|
struct Shared {
|
||||||
az_angle: i32,
|
az_angle: i32,
|
||||||
|
az_compass: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Local resources go here
|
// Local resources go here
|
||||||
|
@ -136,7 +134,7 @@ mod app {
|
||||||
(sck, poci, pico),
|
(sck, poci, pico),
|
||||||
spi::Mode {
|
spi::Mode {
|
||||||
polarity: spi::Polarity::IdleLow,
|
polarity: spi::Polarity::IdleLow,
|
||||||
phase: spi::Phase::CaptureOnFirstTransition,
|
phase: spi::Phase::CaptureOnSecondTransition,
|
||||||
},
|
},
|
||||||
8.MHz(),
|
8.MHz(),
|
||||||
&clocks,
|
&clocks,
|
||||||
|
@ -144,11 +142,13 @@ mod app {
|
||||||
|
|
||||||
defmt::info!("SPI Setup done");
|
defmt::info!("SPI Setup done");
|
||||||
|
|
||||||
let az_enable = gpioa.pa12.into_push_pull_output();
|
let mut az_enable = gpioa.pa12.into_push_pull_output();
|
||||||
|
az_enable.set_high();
|
||||||
let az_dir = gpioa.pa15.into_push_pull_output();
|
let az_dir = gpioa.pa15.into_push_pull_output();
|
||||||
let az_step = gpiob.pb3.into_push_pull_output();
|
let az_step = gpiob.pb3.into_push_pull_output();
|
||||||
|
|
||||||
let el_enable = gpiob.pb4.into_push_pull_output();
|
let mut el_enable = gpiob.pb4.into_push_pull_output();
|
||||||
|
el_enable.set_high();
|
||||||
let el_dir = gpioa.pa8.into_push_pull_output();
|
let el_dir = gpioa.pa8.into_push_pull_output();
|
||||||
let el_step = gpioa.pa9.into_push_pull_output();
|
let el_step = gpioa.pa9.into_push_pull_output();
|
||||||
|
|
||||||
|
@ -156,9 +156,13 @@ mod app {
|
||||||
|
|
||||||
poll_i2c::spawn().ok();
|
poll_i2c::spawn().ok();
|
||||||
poll_spi::spawn().ok();
|
poll_spi::spawn().ok();
|
||||||
|
move_az::spawn().ok();
|
||||||
|
|
||||||
(
|
(
|
||||||
Shared { az_angle: 0 },
|
Shared {
|
||||||
|
az_angle: 0,
|
||||||
|
az_compass: 0,
|
||||||
|
},
|
||||||
Local {
|
Local {
|
||||||
i2cmux,
|
i2cmux,
|
||||||
board_led,
|
board_led,
|
||||||
|
@ -179,8 +183,8 @@ mod app {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(local = [i2cmux, board_led])]
|
#[task(local = [i2cmux, board_led], shared = [az_compass])]
|
||||||
async fn poll_i2c(cx: poll_i2c::Context) {
|
async fn poll_i2c(mut cx: poll_i2c::Context) {
|
||||||
let i2cmux = cx.local.i2cmux;
|
let i2cmux = cx.local.i2cmux;
|
||||||
let board_led = cx.local.board_led;
|
let board_led = cx.local.board_led;
|
||||||
|
|
||||||
|
@ -212,6 +216,11 @@ mod app {
|
||||||
heading -= 2.0 * f32::PI();
|
heading -= 2.0 * f32::PI();
|
||||||
}
|
}
|
||||||
let heading_degrees = heading * 180.0 / f32::PI();
|
let heading_degrees = heading * 180.0 / f32::PI();
|
||||||
|
|
||||||
|
cx.shared.az_compass.lock(|az_compass| {
|
||||||
|
*az_compass = heading_degrees as i32 * 10;
|
||||||
|
});
|
||||||
|
|
||||||
defmt::info!("Heading1 {}", heading_degrees);
|
defmt::info!("Heading1 {}", heading_degrees);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -276,32 +285,34 @@ mod app {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(local = [az_enable, az_dir, az_step], shared = [az_angle])]
|
#[task(local = [az_enable, az_dir, az_step], shared = [az_angle, az_compass])]
|
||||||
async fn move_az(mut cx: move_az::Context) {
|
async fn move_az(mut cx: move_az::Context) {
|
||||||
let az_enable = cx.local.az_enable;
|
let az_enable = cx.local.az_enable;
|
||||||
let az_dir = cx.local.az_dir;
|
let az_dir = cx.local.az_dir;
|
||||||
let az_step = cx.local.az_step;
|
let az_step = cx.local.az_step;
|
||||||
|
|
||||||
let az_target = 42i32;
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
let az_target = cx.shared.az_compass.lock(|az_compass| *az_compass);
|
||||||
|
|
||||||
let az_angle = cx.shared.az_angle.lock(|az_angle| *az_angle);
|
let az_angle = cx.shared.az_angle.lock(|az_angle| *az_angle);
|
||||||
let diff = az_angle - az_target;
|
let diff = az_angle - az_target;
|
||||||
if diff.abs() > 2 {
|
|
||||||
az_enable.set_high();
|
|
||||||
|
|
||||||
|
defmt::info!("angle diff: {:?}", diff);
|
||||||
|
|
||||||
|
if diff.abs() > 5 {
|
||||||
|
az_enable.set_low();
|
||||||
if diff > 0 {
|
if diff > 0 {
|
||||||
az_dir.set_high();
|
az_dir.set_high();
|
||||||
} else {
|
} else {
|
||||||
az_dir.set_low();
|
az_dir.set_low();
|
||||||
}
|
}
|
||||||
|
|
||||||
az_step.set_high();
|
|
||||||
Mono::delay(250.micros()).await;
|
|
||||||
az_step.set_low();
|
az_step.set_low();
|
||||||
Mono::delay(250.micros()).await;
|
Mono::delay(250.micros()).await;
|
||||||
|
az_step.set_high();
|
||||||
|
Mono::delay(250.micros()).await;
|
||||||
} else {
|
} else {
|
||||||
az_enable.set_low();
|
az_enable.set_high();
|
||||||
Mono::delay(500.micros()).await;
|
Mono::delay(500.micros()).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue