Skip to content

Kobayashi82/AutoTrim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

WIP Desktop MSFS 2020 PID Controller Arduino Integration C Language

Automatic trim control system for Microsoft Flight Simulator 2020

AutoTrim

README en EspaΓ±ol

AutoTrim is an automatic trim control system that integrates with Microsoft Flight Simulator 2020 via FSUIPC. The program continuously reads trim data from the simulator and uses a PID controller to physically adjust the Honeycomb Bravo trim wheel through an Arduino controlled motor, providing automatic pitch control and vertical speed hold.

Example of auto trim on a Boeing 737

✨ Features

Flexible Configuration

  • Global Configuration: Adjust PID controller parameters, vertical speed, and Arduino communication
  • Profile Management: Save and load different configurations for different aircraft
  • Standalone Mode: Works without hardware

MSFS 2020 Integration

  • FSUIPC Connection: Real-time simulator data reading
  • Low Latency: Fast response to changing flight conditions
  • Input Capture: Captures key and button combinations at simulator level

Trim Autopilot

  • VS Adjustment: Adjust vertical speed in 100 fpm steps (configurable)
  • Hold VS: Set and maintain current vertical speed
  • Auto Level: Set and maintain 0 fpm vertical speed

PID Controller

  • Precise Control: PID algorithm optimized for smooth trim with anti-windup
  • Configurable Parameters: Fine-tuning of P, I, and D constants
  • Adaptive Response: Automatic compensation based on flight conditions

Arduino Hardware

  • USB Serial Communication: Efficient command protocol
  • Motor Control: Continuous or step-based motor adjustment with configurable speed
  • Acceleration Curve: For smooth, precise movements

πŸ–₯️ System Requirements

Software

  • Windows 10/11 (64-bit)
  • Arduino drivers
  • FSUIPC7
  • Microsoft Flight Simulator 2020

Hardware

  • Honeycomb Bravo Throttle Quadrant
  • Arduino Uno R3
  • Nema 17 Step Motor (12V, 2A, 55NΒ·cm bipolar, 1.81)
  • TB6600 Controller (24V, 4A, microstepping up to 1/32), configured at 4A, 1/1
  • Power Supply (15V, 5A)
  • GT2 timing belt with 20-tooth pulleys

πŸ”§ Installation

  • Download and extract AutoTrim from releases
  • Ensure FSUIPC7 and Arduino drivers are installed
  • Upload the Arduino sketch from Arduino/AutoTrim using Arduino IDE
  • Run AutoTrim.exe

βš™οΈ Configuration File

Available Parameters

PID Controller Configuration

Parameter Description Range Default
Kp Proportional constant 0.0 - 10.0 1.5
Ki Integral constant 0.0 - 5.0 0.3
Kd Derivative constant 0.0 - 2.0 0.1
update_rate Update frequency (Hz) 1 - 100 20
max_trim_rate Maximum trim change rate 1 - 100 50

Vertical Speed Configuration

Parameter Description Range Default
vs_increment VS step (fpm) 50 - 500 100
vs_deadband VS deadband (fpm) 0 - 50 10
vs_max Max allowed VS (fpm) 1000 - 5000 2000

Arduino Configuration

Parameter Description Values Default
port Arduino COM port COM1-COM99/AUTO AUTO
baudrate Baud rate 9600-115200 9600
timeout Communication timeout (ms) 100-5000 1000

Key Configuration

Parameter Description Format Default
toggle_key Enable/Disable Ctrl+Alt+Key Ctrl+Alt+T
vs_up_key Increase VS Ctrl+Alt+Key Ctrl+Alt+Up
vs_down_key Decrease VS Ctrl+Alt+Key Ctrl+Alt+Down
hold_vs_key Hold current VS Ctrl+Alt+Key Ctrl+Alt+H
level_key Level aircraft Ctrl+Alt+Key Ctrl+Alt+L

πŸ”Œ Arduino Setup

Wiring Diagram

Arduino Uno R3
β”œβ”€ Pin 8  β†’ Controller ENA
β”œβ”€ Pin 9  β†’ Controller DIR
β”œβ”€ Pin 10 β†’ Controller PUL
└─ GND    β†’ Controller GND

Controller (TB6600)
β”œβ”€ ENA-   β†’ Controller GND
β”œβ”€ ENA+   β†’ Arduino Pin 8
β”œβ”€ DIR-   β†’ Controller GND
β”œβ”€ DIR+   β†’ Arduino Pin 9
β”œβ”€ PUL-   β†’ Controller GND
β”œβ”€ PUL+   β†’ Arduino Pin 10
β”‚
β”œβ”€ B-     β†’ Motor Coil B-
β”œβ”€ B+     β†’ Motor Coil B+
β”œβ”€ A-     β†’ Motor Coil A-
β”œβ”€ A+     β†’ Motor Coil A+
β”‚
β”œβ”€ GND  β†’ Power Supply GND
└─ VCC  β†’ Power Supply VCC (15V)

Honeycomb Bravo
└─ Trim Wheel β†’ Coupled via GT2 belts to the motor

Communication Protocol

The serial protocol between PC and Arduino uses ASCII commands:

Command Format Description
Trim Up Cont. U:[speed] Trim up continuously at X speed
Trim Up Steps US:[steps]:[speed] Trim up N steps at X speed
Trim Down Cont. D:[speed] Trim down continuously at X speed
Trim Down Steps DS:[steps]:[speed] Trim down N steps at X speed
Stop S Stop motor

[steps] is a positive integer value.
[speed] is a value between 100 and 700, representing the delay between steps.

πŸ§ͺ PID Controller

To optimize PID behavior:

  1. Start with conservative values:

    • Kp = 1.0, Ki = 0.0, Kd = 0.0
  2. Adjust Kp (Proportional):

    • Increase until the system responds quickly
    • If it oscillates, reduce slightly
  3. Add Ki (Integral):

    • Increase to eliminate steady-state error
    • Typical values: 0.1 - 0.5
  4. Add Kd (Derivative):

    • Increase to reduce overshoot
    • Typical values: 0.05 - 0.2

Recommended Flight Tests

# Scenario 1: Stable cruise
# - Enable AutoTrim in level flight
# - Observe stability without intervention

# Scenario 2: Speed changes
# - Gradually change power
# - Verify automatic trim adjustment

# Scenario 3: Configuration changes
# - Extend/retract flaps
# - Verify correct compensation

# Scenario 4: Vertical speeds
# - Set VS to +500 fpm
# - Verify VS hold
# - Switch to -500 fpm
# - Repeat for different VS values

πŸ“Š Real-Time Information

Data Flow

MSFS 2020
    ↓ (FSUIPC)
Data Reading (VS, Trim, etc.)
    ↓
Error Calculation (Target VS - Current VS)
    ↓
PID Controller
    ↓
Trim Adjustment Calculation
    ↓
Serial Protocol
    ↓
Arduino
    ↓
Motor Control
    ↓
Physical Trim Wheel Movement
    ↓
Honeycomb Bravo
    ↓
MSFS 2020 (closes the loop)

πŸ”§ Troubleshooting

Program cannot connect to FSUIPC

Error: Unable to connect to FSUIPC
Solution:
1. Verify MSFS 2020 is running
2. Confirm FSUIPC7 is installed and running
3. Run AutoTrim as administrator

Arduino not responding

Error: Arduino not detected or not responding
Solution:
1. Check USB connection
2. Ensure the sketch is correctly uploaded
3. Verify baudrate in config.ini matches Arduino
4. Check the COM port is correct
5. Try another USB cable

Trim oscillates continuously

Problem: Trim moves constantly up and down
Solution:
1. Reduce Kp in config.ini (e.g., from 1.5 to 1.0)
2. Reduce Kd in config.ini
3. Increase vs_deadband (deadband)
4. Verify the motor has no mechanical play

Slow system response

Problem: Trim takes too long to adjust
Solution:
1. Increase Kp in config.ini
2. Increase update_rate (beware of overload)
3. Increase max_trim_rate
4. Check FSUIPC connection latency

Motor makes noise but doesn’t move

Problem: Motor vibrates but does not rotate
Solution:
1. Check motor wiring to driver
2. Check external motor power (9-12V)
3. Verify step sequence in Arduino code
4. Test with motor disconnected from trim wheel
5. Increase motor current (driver adjustment)
6. Review micro-delays in Arduino code

πŸ“š FAQ

Q: Does it work with all MSFS 2020 aircraft?
A: Yes, it works with any aircraft that has pitch trim. Some aircraft may require PID tuning.

Q: Can I use another controller instead of Arduino?
A: Yes, any microcontroller with serial communication can be used by adapting the protocol.

Q: Does it affect manual trim on the Honeycomb Bravo?
A: No, the system detects manual movement and adapts. You can disable AutoTrim at any time.

Q: Does it work in multiplayer?
A: Yes, it works in multiplayer and shared sessions.

Q: How much latency does the system introduce?
A: Total latency is typically <100ms, imperceptible during normal flight.

Q: Do I need programming to use it?
A: Not for basic use. You only need to upload the Arduino sketch and adjust config.ini.

πŸ“„ License

This project is licensed under the WTFPL – Do What the Fuck You Want to Public License.


πŸ›©οΈ Developed by Kobayashi82 πŸ›©οΈ

"Even virtual pilots deserve a break"

About

Autopilot for MSFS 2020 that controls a physical trim wheel connected to Arduino

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors