Skip to content

Autonomous Distro/Control Board code#6

Open
LelsersLasers wants to merge 56 commits intomainfrom
millan/AutonomousControlBoard
Open

Autonomous Distro/Control Board code#6
LelsersLasers wants to merge 56 commits intomainfrom
millan/AutonomousControlBoard

Conversation

@LelsersLasers
Copy link
Copy Markdown
Contributor

@LelsersLasers LelsersLasers commented Mar 23, 2026

No description provided.

PLLM = 8
PLLN = 240
PLLP = 2
PLLQ = 5

=>
VCO input = 8 / 8 = 1 MHz
VCO output = 1 × 240 = 240 MHz
SYSCLK = 240 / 2 = 120 MHz
BS1 = 12 TQ
BS2 = 2 TQ
Prescaler = 4
APB1 = 30 MHz
APB2TimFreq_Value=120000000 ??
if estop is thrown:
- lift precharge and main coil
- wait for estop to not be thrown
- wait a bit more
- restart precharge sequence
rising debounce
falling debounce
accumulating debounce
- On contactor lifted modes: throttle pwm is disabled
- On un-estopping, there is no delay
- Better pre-state machine logic flow
- Improved updating the RC mode debounce controller
- Output PWMs live in state instead of in loop
- Estop modes set steering straight
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces core firmware logic for the Autonomous Control/Distro Board, including RC (iBUS) input parsing, CAN-based autonomous command handling, and a precharge/contactor safety state machine integrated into the STM32CubeMX project.

Changes:

  • Add new application modules: state machine (logic.*), CAN protocol handling (can.*), iBUS DMA parser (ibus.*), and shared utilities (util.*).
  • Update MCU configuration to support CAN2 RX interrupts, USART3 RX DMA (circular), and PWM defaults/timing.
  • Expand README with board pin definitions and CAN message format documentation.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
README.md Documents board rename, adds GPIO and CAN message definitions.
AutonomousDistroBoard/compile_commands.json Adds a compile database artifact for tooling.
AutonomousDistroBoard/Core/Src/util.c Implements time/util helpers, option type, and debounce controller.
AutonomousDistroBoard/Core/Src/stm32f4xx_it.c Adds DMA1 Stream1 and CAN2 RX0 IRQ handlers + externs.
AutonomousDistroBoard/Core/Src/stm32f4xx_hal_msp.c Enables CAN2 RX IRQ; configures USART3 RX DMA and deinit.
AutonomousDistroBoard/Core/Src/main.c Wires in logic init/run loop, starts PWM, enables DMA clock/IRQ, updates clocks and peripheral timings.
AutonomousDistroBoard/Core/Src/logic.c Implements precharge/contactor state machine, RC/autonomous mode selection, PWM output, CAN status TX.
AutonomousDistroBoard/Core/Src/ibus.c Implements circular-DMA iBUS frame parser.
AutonomousDistroBoard/Core/Src/can.c Implements CAN RX callback handling + status TX packing.
AutonomousDistroBoard/Core/Inc/util.h Declares util helpers, Option, and debounce controller API.
AutonomousDistroBoard/Core/Inc/stm32f4xx_it.h Declares the new IRQ handlers.
AutonomousDistroBoard/Core/Inc/stm32f4xx_hal_conf.h Updates HSE_VALUE to 8 MHz.
AutonomousDistroBoard/Core/Inc/main.h Adds labeled GPIO pin defines (coil/precharge/LED/CAN_S).
AutonomousDistroBoard/Core/Inc/logic.h Declares logic state machine API and system constants.
AutonomousDistroBoard/Core/Inc/ibus.h Declares iBUS parser API/data structures.
AutonomousDistroBoard/Core/Inc/can.h Declares CAN message formats and helper APIs.
AutonomousDistroBoard/AutonomousDistroBoard.ioc CubeMX updates for CAN timing, DMA, NVIC, PWM parameters, and HSE.
AutonomousDistroBoard/.mxproject CubeMX metadata update.
AutonomousDistroBoard/.gitignore Ignores .cache/ directory.
Comments suppressed due to low confidence (1)

AutonomousDistroBoard/Core/Src/main.c:215

  • CAN is initialized but never brought online: there’s no CAN filter configuration, no HAL_CAN_Start(), and no HAL_CAN_ActivateNotification(..., CAN_IT_RX_FIFO0_MSG_PENDING). Without these, CAN2_RX0_IRQn won’t fire (so control commands won’t be received) and HAL_CAN_AddTxMessage will fail because the peripheral isn’t started. Configure at least one filter bank to accept the control/status IDs (or a mask), start CAN, and enable RX FIFO0 notifications in the CAN init/user-code section.
static void MX_CAN2_Init(void)
{

  /* USER CODE BEGIN CAN2_Init 0 */

  /* USER CODE END CAN2_Init 0 */

  /* USER CODE BEGIN CAN2_Init 1 */

  /* USER CODE END CAN2_Init 1 */
  hcan2.Instance = CAN2;
  hcan2.Init.Prescaler = 4;
  hcan2.Init.Mode = CAN_MODE_NORMAL;
  hcan2.Init.SyncJumpWidth = CAN_SJW_1TQ;
  hcan2.Init.TimeSeg1 = CAN_BS1_12TQ;
  hcan2.Init.TimeSeg2 = CAN_BS2_2TQ;
  hcan2.Init.TimeTriggeredMode = DISABLE;
  hcan2.Init.AutoBusOff = DISABLE;
  hcan2.Init.AutoWakeUp = DISABLE;
  hcan2.Init.AutoRetransmission = DISABLE;
  hcan2.Init.ReceiveFifoLocked = DISABLE;
  hcan2.Init.TransmitFifoPriority = DISABLE;
  if (HAL_CAN_Init(&hcan2) != HAL_OK)
  {
    Error_Handler();
  }
  /* USER CODE BEGIN CAN2_Init 2 */

  /* USER CODE END CAN2_Init 2 */

}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@LelsersLasers LelsersLasers marked this pull request as ready for review March 27, 2026 02:13
@LelsersLasers LelsersLasers requested a review from Copilot March 27, 2026 02:23
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

LelsersLasers and others added 8 commits March 26, 2026 20:06
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Explicit CAN_S low
Setting CAN filter (accept all)
Starting CAN
Starting FIFO0 interrupt message
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe let this file go into main with this PR so we can debug on the kart easier, but when we have a sec, replace this with something that generates this

Shriya: i probably dont understand the state machine as much as i should, but is there a chance that precharge fires even if rc estop is pressed on recconnect? ex: rc disconnect -> rc estop pressed -> rc reconnect then 300 ms debounce window so rc estop is not considered pressed and then 200 ms for precharge start.

Fix:
*some state* -> error happens -> *error state* (estopped, rc dropped, etc) -> error fixed -> *recovering state* -> medium delay (2 sec?) -> *starting state*
that way it will at worst bounce/return from recovering state and not precharging

+ LED blink times improved
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.

4 participants