Comments
This commit is contained in:
parent
b80ad9da65
commit
cde00aee39
14
src/main.rs
14
src/main.rs
|
@ -6,6 +6,8 @@ use panic_halt as _;
|
||||||
use avr_device::interrupt;
|
use avr_device::interrupt;
|
||||||
use core::cell::RefCell;
|
use core::cell::RefCell;
|
||||||
|
|
||||||
|
// Serial monitor shit
|
||||||
|
// No idea wtf this does
|
||||||
type Console = arduino_hal::hal::usart::Usart0<arduino_hal::DefaultClock>;
|
type Console = arduino_hal::hal::usart::Usart0<arduino_hal::DefaultClock>;
|
||||||
static CONSOLE: interrupt::Mutex<RefCell<Option<Console>>> =
|
static CONSOLE: interrupt::Mutex<RefCell<Option<Console>>> =
|
||||||
interrupt::Mutex::new(RefCell::new(None));
|
interrupt::Mutex::new(RefCell::new(None));
|
||||||
|
@ -40,9 +42,15 @@ fn put_console(console: Console) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test ratio for converting from angle to servo control pulse
|
||||||
|
// This was a guess and is kinda innacurate
|
||||||
|
// Should do more accurate testing for final version
|
||||||
const ANGLE_PULSE_RATIO: f32 = 10.25;
|
const ANGLE_PULSE_RATIO: f32 = 10.25;
|
||||||
|
|
||||||
fn set_servo_degree(pin: &mut Pin<Output>, degree: f32) {
|
fn set_servo_degree(pin: &mut Pin<Output>, degree: f32) {
|
||||||
|
// Using delays blocks the processor
|
||||||
|
// Cannot work with multiple motors
|
||||||
|
// Embassy async will fix this on pico
|
||||||
let delay = (degree * ANGLE_PULSE_RATIO) as u32;
|
let delay = (degree * ANGLE_PULSE_RATIO) as u32;
|
||||||
pin.set_high();
|
pin.set_high();
|
||||||
arduino_hal::delay_us(delay);
|
arduino_hal::delay_us(delay);
|
||||||
|
@ -52,21 +60,24 @@ fn set_servo_degree(pin: &mut Pin<Output>, degree: f32) {
|
||||||
|
|
||||||
#[arduino_hal::entry]
|
#[arduino_hal::entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
|
/* Setup Pins */
|
||||||
let dp = arduino_hal::Peripherals::take().unwrap();
|
let dp = arduino_hal::Peripherals::take().unwrap();
|
||||||
let pins = arduino_hal::pins!(dp);
|
let pins = arduino_hal::pins!(dp);
|
||||||
let serial = arduino_hal::default_serial!(dp, pins, 57600);
|
let serial = arduino_hal::default_serial!(dp, pins, 57600);
|
||||||
put_console(serial);
|
put_console(serial);
|
||||||
|
|
||||||
let mut servo = pins.d9.into_output().downgrade();
|
let mut servo = pins.d9.into_output().downgrade();
|
||||||
let switch = pins.d10.into_pull_up_input();
|
let switch = pins.d10.into_pull_up_input();
|
||||||
println!("hewwo :3");
|
println!("hewwo :3");
|
||||||
|
|
||||||
|
// Variables for loop-persistent data
|
||||||
let mut switchSmoothed: f32 = 0.0;
|
let mut switchSmoothed: f32 = 0.0;
|
||||||
let mut switchPrev: f32 = 0.0;
|
let mut switchPrev: f32 = 0.0;
|
||||||
let mut switch_count = 0.0;
|
let mut switch_count = 0.0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
/* Get Input */
|
/* Get Input */
|
||||||
|
// This debouncing sucks ass and isn't good - doesn't matter, just for testing
|
||||||
switch_count = match switch.is_low() {
|
switch_count = match switch.is_low() {
|
||||||
true => 1.0,
|
true => 1.0,
|
||||||
false => switch_count - 0.2,
|
false => switch_count - 0.2,
|
||||||
|
@ -79,6 +90,7 @@ fn main() -> ! {
|
||||||
val = 0.0;
|
val = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Move Servos */
|
||||||
switchSmoothed = (switch_count * 0.05) + (switchPrev * 0.95);
|
switchSmoothed = (switch_count * 0.05) + (switchPrev * 0.95);
|
||||||
switchPrev = switchSmoothed;
|
switchPrev = switchSmoothed;
|
||||||
let deg = (190.0 * switchSmoothed) + 25.0;
|
let deg = (190.0 * switchSmoothed) + 25.0;
|
||||||
|
|
Loading…
Reference in New Issue