Skip to content

Non Blocking Sensors - #195

Draft
ericv555 wants to merge 70 commits into
mainfrom
blocking_sensors
Draft

Non Blocking Sensors#195
ericv555 wants to merge 70 commits into
mainfrom
blocking_sensors

Conversation

@ericv555

@ericv555 ericv555 commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

The purpose of this PR is to convert the ET16S, ICM IMU, and buffencoders from blocking sensor reads to non-blocking sensor reads. Previously, when the read function for any of these objects was called, the teensy would halt (block) and wait to receive the data. After it had waited for all the data to come in, it would do whatever it needed to with it. This PR changes that, so when one of these objects' read statement is called, it already has the data in its buffer, and it can immediately process it. This is achieved using DMA transfers that are built into the Teensy but have been unused until now. This had to be done in 3 different ways for the 3 different objects that I worked on, so I will go through them one at a time.

  • ET16S DMA Implementation
    The eDMA channel is set up in the init, where an interrupt is attached that triggers whenever a full ET16S frame has been sent over the wire. This interrupt calls the ET16S interrupt service routine (ISR) function, which sets the buffer that has just been filled to the active buffer that can be read in the read function. The ISR then sets a second buffer as the new target buffer, which immediately begins filling via the DMA channel. These two ping pong buffers trade back and forth whenever one of them fills.
  • ICM IMU DMA Implementation
    Requires a request_read function in sensor_manager that is called in the main loop. request_read starts an SPI transfer and continues on while the transfer takes place. An EventResponder object is attached to the SPI transfer that returns true when it is complete. This is checked in the regularly placed read function, where it then sends data to comms if the data transfer has completed. This way, the ICM IMU requires no interrupt.
  • Buff Encoder DMA Implementation
    This one was the hardest to implement since our robots have 3 or 4 encoders on them. When the sensor_manager calls request_read, it kicks off a DMA transfer on a separate SPI bus, then the ICM IMU (the IMU uses SPI1 and the buff encoder uses SPI, so the IMU and the buff encoders can read data at the same time). When the first buff_encoder transfer finishes, it triggers an ISR function that interrupts the main loop, ends the SPI transaction and starts the SPI transaction with the next encoder. It does this until all encoders have completed their transaction, where it then triggers a bool flag for transfer completion.

@ericv555 ericv555 self-assigned this Jun 5, 2026
@github-actions

github-actions Bot commented Jun 5, 2026

Copy link
Copy Markdown

Doxygen warnings output: (if empty, there are no warnings). Please correct any warnings before merging.

  /github/workspace/src/sensors/buff_encoder.hpp:130: warning: Member zero_check_timer (variable) of class BuffEncoder is not documented.
/github/workspace/src/sensors/buff_encoder.hpp:131: warning: Member zero_misalign_count (variable) of class BuffEncoder is not documented.
/github/workspace/src/sensors/buff_encoder.hpp:132: warning: Member cached_zero_pos (variable) of class BuffEncoder is not documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant