1
Fork 0

added homing function

This commit is contained in:
Andy Killorin 2024-05-02 11:32:27 -05:00
parent a20817d55f
commit d86e388182
Signed by: ank
GPG key ID: 23F9463ECB67FE8C

View file

@ -2,13 +2,21 @@
#![no_main] #![no_main]
#![feature(abi_avr_interrupt, cell_update)] #![feature(abi_avr_interrupt, cell_update)]
use arduino_hal::pac::tc1::OCR1A; use arduino_hal::{hal::port::PD4, pac::tc1::OCR1A, port::{mode::{Input, PullUp}, Pin}};
use encoder::{rotations, setup_encoder, TICKS_PER_ROT}; use avr_device::interrupt;
use encoder::{rotations, setup_encoder, COUNTS, TICKS_PER_ROT};
use panic_halt as _; use panic_halt as _;
mod servo; mod servo;
use servo::{configure_timer_one, Servo}; use servo::{configure_timer_one, Servo};
mod encoder; mod encoder;
// d1: encoder
// d2: encoder
// d4: limit switch
// d5: lift piston
// d9: carriage
// d10: claw
#[arduino_hal::entry] #[arduino_hal::entry]
fn main() -> ! { fn main() -> ! {
let dp = arduino_hal::Peripherals::take().unwrap(); let dp = arduino_hal::Peripherals::take().unwrap();
@ -22,9 +30,10 @@ fn main() -> ! {
pins.d10.into_output(); // claw pins.d10.into_output(); // claw
let (carriage, claw) = configure_timer_one(&dp.TC1); let (carriage, claw) = configure_timer_one(&dp.TC1);
loop { let switch = pins.d4.into_pull_up_input();
let position = encoder::ticks();
home(&carriage, &switch);
loop {
let gain = rotations(); let gain = rotations();
carriage.set_speed(gain); carriage.set_speed(gain);
@ -67,3 +76,12 @@ fn abs(val:f32) -> f32 {
val val
} }
} }
fn home(carriage: &OCR1A, switch: &Pin<Input<PullUp>, PD4>) {
carriage.set_speed(-0.2);
while switch.is_high() { arduino_hal::delay_us(5) };
carriage.set_speed(0.1);
while switch.is_low() { arduino_hal::delay_us(5) };
interrupt::free(|cs| COUNTS.borrow(cs).set(0));
}