171 lines
4.6 KiB
Markdown
171 lines
4.6 KiB
Markdown
# Auto_Seat
|
|
|
|
Arduino Nano based automatic seat controller.
|
|
|
|
## Hardware
|
|
|
|
- Board: Arduino Nano ATmega328P
|
|
- Up relay: D8, active-low
|
|
- Down relay: D9, active-low
|
|
- Parking raw input: A0
|
|
- IG1 input: D7
|
|
|
|
## Main Behavior
|
|
|
|
- If `IG1 HIGH` and parking signal is OFF, drive mode is confirmed after 80ms.
|
|
- In confirmed drive mode, the seat moves up to the EEPROM saved position.
|
|
- If parking/non-drive mode is confirmed for 250ms, the seat moves down to 0.
|
|
- Down movement is estimated at 1.1x the up movement speed.
|
|
- When the estimated position reaches 0, down relay stays on for an extra 300ms.
|
|
- On IG1 startup, relay output is held off for 1000ms to ignore temporary signal bounce.
|
|
|
|
## Position Setting
|
|
|
|
- Hard limit: `0..6000ms`
|
|
- EEPROM saved position is used as the automatic driving position.
|
|
- EEPROM initializes saved position to `6000ms` if the magic value is missing or invalid.
|
|
- Serial command `p` saves the current estimated position to EEPROM.
|
|
- Calibration command `c` does not change the saved position.
|
|
|
|
## USB / Serial Reset Handling
|
|
|
|
Opening a USB serial connection can reset an Arduino Nano through DTR.
|
|
|
|
If the board boots while `IG1 HIGH` and parking is OFF, the controller assumes the seat is already at the saved driving position:
|
|
|
|
```text
|
|
currentPositionMs = savedPositionMs
|
|
targetPositionMs = savedPositionMs
|
|
relay = OFF
|
|
```
|
|
|
|
This prevents unintended upward movement after USB reconnect while the gear is not in P. If the gear is then moved to P, the controller moves down from the saved position estimate to 0.
|
|
|
|
## Serial Console
|
|
|
|
Serial is quiet by default.
|
|
|
|
1. Open serial at `115200`.
|
|
2. Send an empty Enter once to unlock the console and print help.
|
|
3. After unlock, only one-character commands are accepted.
|
|
|
|
Commands:
|
|
|
|
```text
|
|
s print current status
|
|
u manual up +500ms
|
|
d manual down -500ms
|
|
p save current estimated position to EEPROM
|
|
g start debug output every 1s
|
|
x stop debug mode only
|
|
a return to gear-based automatic target
|
|
c run calibration: up 7s, down 6s, set current position to 0
|
|
r clear 10-use auto calibration counter
|
|
h print help
|
|
```
|
|
|
|
These management commands require parking gear for safety:
|
|
|
|
```text
|
|
a c r
|
|
```
|
|
|
|
If the gear is not P:
|
|
|
|
```text
|
|
ERR: check gear state. Command requires P.
|
|
```
|
|
|
|
While debug mode is active, only `x` is accepted. Other input is ignored.
|
|
|
|
Manual position commands `u`, `d`, and `p` are allowed while driving, as long as the controller is not busy with an in-progress movement.
|
|
|
|
Every status output uses one item per line and includes boot uptime:
|
|
|
|
```text
|
|
[STATUS]
|
|
uptime=0h 2m 13s 457ms
|
|
parkingRawValue=1023
|
|
ignition=true
|
|
parking=true
|
|
rawDriveMode=false
|
|
confirmedDriveMode=false
|
|
```
|
|
|
|
If the use counter reached 10, status/debug output also includes the ignition-off calibration timer:
|
|
|
|
```text
|
|
autoCalibrationOffTimer=elapsed 0h 1m 20s 123ms remaining 0h 3m 39s 877ms
|
|
```
|
|
|
|
If IG1 is still ON:
|
|
|
|
```text
|
|
autoCalibrationOffTimer=waiting_for_ig_off
|
|
```
|
|
|
|
Debug mode prints a readable block every second, one item per line. Boolean values are printed as `true` or `false`:
|
|
|
|
```text
|
|
[DEBUG]
|
|
uptime=0h 0m 5s 123ms
|
|
parkingRawValue=1023
|
|
ignition=true
|
|
parking=true
|
|
rawDriveMode=false
|
|
confirmedDriveMode=false
|
|
currentPositionMs=0
|
|
targetPositionMs=0
|
|
savedPositionMs=6000
|
|
hardLimitPositionMs=6000
|
|
requestedRelayAction=0
|
|
actualRelayAction=0
|
|
manualMode=false
|
|
stabilizing=false
|
|
useCount=0/10
|
|
autoCalibrationPending=false
|
|
forceCalibration=false
|
|
autoCalibrationState=0
|
|
```
|
|
|
|
## Automatic Calibration
|
|
|
|
- Each `IG1 HIGH -> LOW` transition increments the EEPROM use counter.
|
|
- After 10 uses, calibration is scheduled.
|
|
- If IG1 remains OFF for 5 minutes, automatic calibration runs:
|
|
|
|
```text
|
|
up 7000ms
|
|
down 6000ms
|
|
currentPositionMs = 0
|
|
targetPositionMs = 0
|
|
useCount = 0
|
|
```
|
|
|
|
If IG1 turns ON during scheduled calibration, calibration is aborted. Manual `c` calibration is allowed only in P and runs to completion.
|
|
|
|
## Safety Guards
|
|
|
|
- Commands are rejected while the seat is moving or a relay action is pending.
|
|
- Internal position values are clamped to `0..6000ms`.
|
|
- Manual step completion is cancelled if gear state changes before completion.
|
|
- Factory reset command was removed to avoid accidental EEPROM reset.
|
|
|
|
## Build / Upload
|
|
|
|
Compile:
|
|
|
|
```powershell
|
|
& "C:\Program Files\Arduino CLI\arduino-cli.exe" compile --fqbn arduino:avr:nano:cpu=atmega328 --warnings all .
|
|
```
|
|
|
|
Upload:
|
|
|
|
```powershell
|
|
.\upload.ps1 -Port COM3
|
|
```
|
|
|
|
## Notes
|
|
|
|
The controller estimates seat position by time. There is no physical position sensor. If power is cut while IG1 is OFF/P state, the next boot starts from estimated position 0. If the board resets while already in drive mode, it starts from the EEPROM saved driving position to avoid USB reconnect induced upward movement.
|