roboticsatiowa / Rover_Embedded

1 stars 0 forks source link

Tyler pit steppers #11

Open Naitry opened 1 week ago

Naitry commented 1 week ago

fixes #10

Primary Changes

In this I use PITs (Periodic Interrupt Timer) to output pulses for stepper motor control rather than the previous strategy where it continuously checked if the period was up.

This technically limits the steppers to 4 using these specific timers. The timer is setup in the stepper constructor and attached to a function to flip the pulse pin of the stepper.

This allows us to reduce the calls in the main loop to only be the call to parse serial input. and never block the motors, just flip them based on interrupts.

Minor Changes

I also made a few minor stylistic changes.

  1. All header files were changed to .hpp extension vs .h.

    • Reason: Consistency. This is a c++ project, while any extension will work, hpp more effectively highlights that these headers belong to a c++ project.11
    1. Header guard preprocessing statements were changed from #IFDEF style guards to #PRAGMA once
      • Reason: Performs the same task with any modern compiler, harder to cause unintended behavior with preprocessor statements. (Something like an #ENDIF accidentally being deleted)

Status:

built successfully but not tested in practice

image

ethanholter commented 1 week ago

You will have to walk me through the larger chunks of new code. Seems like you reference a lot of mysterious registers which I would like to know their purpose. some comments wouldn't hurt either, especially in cases where the code is not very self explanatory or uses niche info from the datasheet. other than that the code looks good. see if you can make any additional changes now because I'm still new to the built in code review process and would like to see how that works

Naitry commented 1 week ago

-> https://github.com/roboticsatiowa/Rover_Embedded/pull/11#issuecomment-2369965179

My previous implementation directly wrote to the timer control registers for the PIT timers. While I have found several examples of this usage, I could not find it in the official ARM Cortex-M7 docs, so I opted to switch to the interval timer library made for the teensy. I have used this library before and trust it to work well.

Here is what they use to interface with the timers:: https://github.com/PaulStoffregen/cores/blob/master/teensy4/IntervalTimer.h https://github.com/PaulStoffregen/cores/blob/master/teensy4/IntervalTimer.cpp

It's similar to what I was doing, but a little more intricate and flexible.

with commit https://github.com/roboticsatiowa/Rover_Embedded/pull/11/commits/2fb7243c6902b2cc5d13aede30b3e2cb7de3219b I have switched to this IntervalTimer implementation, hopefully clarifying what is happening.

I have also added comments throughout the IntervalTimers.hpp and Steppers.hpp files to explain my changes