Add closed-loop simulator sketch + physics library (Router)#16
Open
toprakcelikel wants to merge 3 commits into
Open
Add closed-loop simulator sketch + physics library (Router)#16toprakcelikel wants to merge 3 commits into
toprakcelikel wants to merge 3 commits into
Conversation
Restores the CAN backbone for end-to-end closed-loop testing that PR elcano#14 inadvertently dropped, as a sister sketch alongside simulator_stage1 (refactored only to share the physics engine; runtime behavior unchanged). - New simulator_closed_loop sketch: reads real DBW inputs (throttle, L_TURN, R_TURN), publishes 0x4C0 position, 0x4E0 heading, 0x4F0 speed, and 0x430 SimSteerActual via CAN for Sensor Hub Nav and DBW to close their respective loops. - Shared simulator_physics Arduino library used by both sketches. - LOG_PORT macro with USE_NATIVE_USB switch (default on for Bridge board) so the Native USB port is used and D0/D1 stay quiet for the inter-board UART. - analogWriteResolution(12), PIO_PUDR pull-up disable on L_TURN/R_TURN, MAX_SPEED reduced to 2000 mm/s for waypoint capture turn radius. - README documents the one-time Arduino IDE Sketchbook Location change and the library install copy from the default sketchbook. - .gitignore keeps third-party libraries (due_can, Time, RTClib, etc.) out of the repo while still tracking our own simulator_physics. End-to-end closed loop verified on bench against DBW main (PR elcano#7).
Inferring brake from throttle < MIN_EFFECTIVE_THROTTLE falsely engaged the brake during low-speed PID ramp-up (e.g. Nav speed=100 cm/s), stalling the sim. Read BRAKE_ON_PIN (D48) directly; add BRAKE_ON_ACTIVE_LOW config (default true for Bridge active-low relay wiring) and brake state to the debug line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add closed-loop simulator sketch + shared physics library (Router)
Summary
Router-side closed-loop simulator and the shared integer physics engine, split
out from #15 so the closed-loop sketch can be reviewed and merged on its own.
Restores the CAN backbone that PR #12 (full-sim-loop) introduced and PR #14
(modify stage 1 and 3) inadvertently dropped.
What's included
Non_grapic_simulator/simulator_closed_loop/simulator_closed_loop.ino—Router-side closed-loop variant that reads real DBW inputs (throttle, brake,
steering) and publishes pose / heading / speed / actual wheel angle as CAN
frames (
0x4C0,0x4E0,0x4F0,0x430) for Sensor Hub Nav and DBW'ssteering PID to consume. Closes the Nav → DBW → Router → Nav loop.
Non_grapic_simulator/libraries/simulator_physics/— shared integer-onlyphysics engine extracted into a small in-repo Arduino library
(
computeSpeed,updateAngle,updatePosition,sin1000/cos1000,wheel-pulse + angle-sensor output). Both sketches
#include <simulator_physics.h>so future physics changes happen in one place.
Non_grapic_simulator/README.md— describes the two simulator sketches andthe shared physics engine, plus IDE setup/troubleshooting.
.gitignore— ignore build/IDE artifacts.simulator_stage1.ino— only changes are the#includeline + a SETUPbanner; runtime behavior is identical to PR Fix #define comments and update brake model #14.
Notable changes
Removed the Stage 2 ASCII command pipe and Stage 3 binary telemetry from
the closed-loop sketch. Those were an in-sketch PC→Router command-injection
path; the closed loop is now driven purely by DBW's pins and the CAN bus. All
command-injection/test plumbing is consolidated into the upcoming
test-automation PR (avoids two competing command paths).
Fixed brake detection. Previously the Router inferred the brake from
throttle level:
At low cruise speeds (e.g. Nav commanding ~100 cm/s) DBW's throttle PID can sit
below
MIN_EFFECTIVE_THROTTLEduring ramp-up, which falsely engaged the brakeand stalled the vehicle (~30 s stuck at waypoint 1). The Router now reads DBW's
actual brake wire (DBW D44 → Router D48):
Adds a
BRAKE_ON_ACTIVE_LOWconfig (defaulttruefor the Bridge's active-lowrelay wiring; flip to
falsefor active-high wiring) and aB=field in thedebug line for live visibility.
One-time setup (per developer)
Arduino IDE → File → Preferences → Sketchbook Location → set to
<repo>/Non_grapic_simulator. This lets the IDE find the sharedsimulator_physicslibrary. Full setup + troubleshooting inNon_grapic_simulator/README.md.Verification
cruise speed (previously stalled ~30 s at waypoint 1).
steer output pins, so motion confirms DBW participation.
Out of scope (follow-up PR)
NavigateTestRunnergateway,tools/test_runner.py, test CSVs, and assertiondesign notes.
Simulator.inodesign.
Notes for reviewers
BRAKE_ON_ACTIVE_LOW.30bcffd) → Stage 2/3 removal(
8da87c0, cherry-picked) → Router brake fix.