Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SITL: implemented built-in serial receivers support in SITL, implemented FC proxy mode, updated SITL docs #9365

Merged
merged 11 commits into from
Apr 27, 2024

Conversation

RomanLut
Copy link
Contributor

@RomanLut RomanLut commented Oct 12, 2023

Requires Configurator changes iNavFlight/inav-configurator#1849

Tested under

Windows

  • SBUS receiver connected throught inverter to CH340 USB-to-serial
  • ELRS receiver connected to CH340 USB-to-serial
  • Inav 7.0 flight controller with ELRS receiver attached
  • Inav 7.0 flight controller with SBUS receiver attached
  • Betaflight 4.3 AIO FC with Frsky receiver

Linux (Arch, aarch64, riscv64, x86_64; Alpine ia32)

  • CRSF (ELRS) via pl2303 (FTDI clone)
  • IBUS via CP2102
  • FC Proxy (Sbus RX/TX)

FreeBSD (x64_64)

  • IBUS via CP2102
  • CRSF (ELRS) via pl2303 (FDTI clone)

MacOS (x64_86 kvm/qemu)

  • IBUS via CP2102

Please see https://github.com/RomanLut/inav/blob/submit-serial-receiver/docs/SITL/SITL.md for changes.

implemented FC Proxy for SITL
update SITL.md
@RomanLut RomanLut changed the title implemented built-in serial receivers support in SITL, FC proxy mode, upate SITL docs implemented built-in serial receivers support in SITL, FC proxy mode, update SITL docs Oct 12, 2023
@RomanLut RomanLut changed the title implemented built-in serial receivers support in SITL, FC proxy mode, update SITL docs SITL: implemented built-in serial receivers support in SITL, FC proxy mode, update SITL docs Oct 12, 2023
@RomanLut RomanLut marked this pull request as ready for review October 12, 2023 17:18
@RomanLut RomanLut changed the title SITL: implemented built-in serial receivers support in SITL, FC proxy mode, update SITL docs SITL: implemented built-in serial receivers support in SITL, implemented FC proxy mode, update SITL docs Oct 12, 2023
@RomanLut RomanLut changed the title SITL: implemented built-in serial receivers support in SITL, implemented FC proxy mode, update SITL docs SITL: implemented built-in serial receivers support in SITL, implemented FC proxy mode, updated SITL docs Oct 12, 2023
Copy link
Collaborator

@stronnag stronnag left a comment

Choose a reason for hiding this comment

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

NAK: This will not (does not) work in Linux, nor will it work in MacOS.

@stronnag
Copy link
Collaborator

stronnag commented Nov 3, 2023

  1. It does work in FreeBSD, as you can just but the baud rate into the termios structure.
  2. For Linux, you must use termios2 / BOTHER to use non-standard rates (e.g. 400k, 100k). This uses the naive baud rate (vice B_* constants).
  3. For MacOS, you need to use the IOSSIOSPEED, ioctl for non-standard baud rates.

Working example in https://github.com/stronnag/bbl2kml/tree/master/tools/ser2tcp/eg_c or I can make a PR to your repo (let me know if you'd prefer that option).

@stronnag
Copy link
Collaborator

stronnag commented Nov 3, 2023

Is it intentional that both the serial device node ( dev/cuaU0) and TCP [::]:5762 are connected to UART3 below?

~/inav-dev/_sitl]$ ./inav_7.0.0_SITL --path ~/sitl-eeproms/crsf-eeprom.bin --serialuart=3 --serialport /dev/cuaU0 --baudrate 400000 --simip '[::]'
INAV 7.0.0 SITL (d5f7241b)
[SYSTEM] Init...
[SIM] No interface specified. Configurator only.
[SERIALPROXY] Connected /dev/cuaU0 to UART3
[EEPROM] Loaded '/home/jrh/sitl-eeproms/crsf-eeprom.bin' (32768 of 32768 bytes)
[SOCKET] Bind TCP [::]:5760 to UART1
[SOCKET] Bind TCP [::]:5761 to UART2
[SOCKET] Bind TCP [::]:5762 to UART3
[SOCKET] [xxxx:xxxx:xxxx:0:18b0:85ff:zzzz:zzzz]:46868 connected to UART1
[SOCKET] [xxxx:xxxx:xxxx:0:18b0:85ff:zzzz:zzzz]:46868 disconnected from UART1

@RomanLut
Copy link
Contributor Author

RomanLut commented Nov 3, 2023

I can make a PR to your repo (let me know if you'd prefer that option).

This is what I actually was hoping for. I am not Linux/MasOs user and will not be able to test it. Please make a PR.

@stronnag
Copy link
Collaborator

stronnag commented Nov 3, 2023

I can make a PR to your repo (let me know if you'd prefer that option).

This is what I actually was hoping for. I am not Linux/MasOs user and will not be able to test it. Please make a PR.

OK, I'll try and get something done this weekend.

@RomanLut
Copy link
Contributor Author

RomanLut commented Nov 3, 2023

Is it intentional that both the serial device node ( dev/cuaU0) and TCP [::]:5762 are connected to UART3 below?

Yes, why not? User can use TCP Port or COM port without changing configuration, both will work.

@RomanLut
Copy link
Contributor Author

RomanLut commented Nov 4, 2023

OK, I'll try and get something done this weekend.

Merged pull request RomanLut#12 to branch RomanLut:submit-serial-receiver.
Retested on Windows with SBUS receiver and INAV FC Proxy - all works.

Copy link
Collaborator

@stronnag stronnag left a comment

Choose a reason for hiding this comment

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

I'm content. Nice to get rid of the external serial bridge for physical RX.

@stronnag
Copy link
Collaborator

stronnag commented Nov 4, 2023

@DzikuVx apropos testing, in addition to @RomanLut 's Windows testing:

Test Status

Linux (Arch, aarch64, riscv64, x86_64; Alpine ia32)

CRSF (ELRS)

via pl2303 (FTDI clone)

$ ./inav_7.0.0_SITL --path ~/sitl-eeproms/crsf-eeprom.bin --serialuart=3 --serialport /dev/ttyUSB0 --baudrate 400000
INAV 7.0.0 SITL (5a785a44)
[SYSTEM] Init...
[SIM] No interface specified. Configurator only.
[SERIALPROXY] Connected /dev/ttyUSB0 to UART3
[EEPROM] Loaded '/home/jrh/sitl-eeproms/crsf-eeprom.bin' (32768 of 32768 bytes)
[SOCKET] Bind TCP [::]:5760 to UART1
[SOCKET] Bind TCP [::]:5761 to UART2
[SOCKET] Bind TCP [::]:5762 to UART3
[SOCKET] [::1]:40896 connected to UART1
[SOCKET] [::1]:40896 disconnected from UART1

IBUS

via CP2102

$ ./inav_7.0.0_SITL --path ~/sitl-eeproms/ibus-eeprom.bin --serialuart=3 --serialport /dev/ttyUSB0 --baudrate 115200
INAV 7.0.0 SITL (5a785a44)
[SYSTEM] Init...
[SIM] No interface specified. Configurator only.
[SERIALPROXY] Connected /dev/ttyUSB0 to UART3
[EEPROM] Loaded '/home/jrh/sitl-eeproms/ibus-eeprom.bin' (32768 of 32768 bytes)
[SOCKET] Bind TCP [::]:5760 to UART1
[SOCKET] Bind TCP [::]:5761 to UART2
[SOCKET] Bind TCP [::]:5762 to UART3
[SOCKET] [::1]:37446 connected to UART1
[SOCKET] [::1]:37446 disconnected from UART1

FC Proxy (Sbus TX)

$ ./inav_7.0.0_SITL --path ~/sitl-eeproms/sim-eeprom.bin --serialport /dev/ttyACM0 --fcproxy
INAV 7.0.0 SITL (5a785a44)
[SYSTEM] Init...
[SIM] No interface specified. Configurator only.
[SERIALPROXY] Using proxy flight controller on /dev/ttyACM0
[EEPROM] Loaded '/home/jrh/sitl-eeproms/sim-eeprom.bin' (32768 of 32768 bytes)
[SOCKET] Bind TCP [::]:5760 to UART1
[SOCKET] Bind TCP [::]:5761 to UART2
[SERIALPROXY] Requesting RX config from proxy FC...
[SERIALPROXY] Setting RX config on proxy FC...

Correct movement of sticks etc. seen in Configurator.

FreeBSD (x64_64)

IBUS

via CP2102

$ ./inav_7.0.0_SITL --path ~/sitl-eeproms/ibus-eeprom.bin --serialuart=3 --serialport /dev/cuaU0 --baudrate 115200
INAV 7.0.0 SITL (5a785a44)
[SYSTEM] Init...
[SIM] No interface specified. Configurator only.
[SERIALPROXY] Connected /dev/cuaU0 to UART3
[EEPROM] Loaded '/home/jrh/sitl-eeproms/ibus-eeprom.bin' (32768 of 32768 bytes)
[SOCKET] Bind TCP [::]:5760 to UART1
[SOCKET] Bind TCP [::]:5761 to UART2
[SOCKET] Bind TCP [::]:5762 to UART3
[SOCKET] [xxxx:xxxx:xxxx:0:18b0:85ff:zzzz:zzzz]:36908 connected to UART1
[SOCKET] [xxxx:xxxx:xxxx:0:18b0:85ff:zzzz:zzzz]:36908 disconnected from UART1

CRSF (ELRS)

via pl2303 (FDTI clone)

./inav_7.0.0_SITL --path ~/sitl-eeproms/crsf-eeprom.bin --serialuart=3 --serialport /dev/cuaU0 --baudrate 400000
INAV 7.0.0 SITL (5a785a44)
[SYSTEM] Init...
[SIM] No interface specified. Configurator only.
[SERIALPROXY] Connected /dev/cuaU0 to UART3
[EEPROM] Loaded '/home/jrh/sitl-eeproms/crsf-eeprom.bin' (32768 of 32768 bytes)
[SOCKET] Bind TCP [::]:5760 to UART1
[SOCKET] Bind TCP [::]:5761 to UART2
[SOCKET] Bind TCP [::]:5762 to UART3
[SOCKET] [xxxx:xxxx:xxxx:0:18b0:85ff:zzzz:zzzz]:59058 connected to UART1
[SOCKET] [xxxx:xxxx:xxxx:0:18b0:85ff:zzzz:zzzz]:59058 disconnected from UART1

Correct movement of sticks etc. seen in Configurator.

MacOS (x64_86 kvm/qemu)

IBUS

via CP2102

$ ./inav_7.0.0_SITL --path ~/sitl-eeproms/ibus-eeprom.bin --serialuart=3 --serialport /dev/cu.usbserial-0001 --baudrate 115200
INAV 7.0.0 SITL (5a785a44)
[SYSTEM] Init...
[SIM] No interface specified. Configurator only.
[SERIALPROXY] Connected /dev/cu.usbserial-0001 to UART3
[EEPROM] Loaded '/Users/jrh/sitl-eeproms/ibus-eeprom.bin' (32768 of 32768 bytes)
[SOCKET] Bind TCP [::]:5760 to UART1
[SOCKET] Bind TCP [::]:5761 to UART2
[SOCKET] Bind TCP [::]:5762 to UART3
[SOCKET] [::ffff:172.31.0.244]:51594 connected to UART1
[SOCKET] [::ffff:172.31.0.244]:51594 disconnected from UART1

Correct movement of sticks etc. seen in Configurator.

CRSF not tested as environment does support pl2303/400000 baud (however, stty reports correct tty settings after SITL started with --serialuart=3 --serialport /dev/cu.usbserial-5D20 --baudrate 400000

$ stty < /dev/cu.usbserial-5D20
speed 400000 baud;
lflags: -icanon -isig -iexten -echo
iflags: -icrnl -ixon -ixany -imaxbel -brkint
oflags: -opost -onlcr -oxtabs
cflags: cs8 -parenb clocal
min
0

@RobertoD91
Copy link
Contributor

Just wanted to say thanks for writing:

Please note that 100000(SBUS) and 420000(CRSF) are non-standart baud rates which may not be supported by some USB-to-serial adapters. FDTI and CH340 should work. CP2102/9 does not work.

It saved me from a big headache.

@stronnag
Copy link
Collaborator

Retested on Linux ... time to merge.

@stronnag stronnag merged commit e92337a into iNavFlight:master Apr 27, 2024
14 checks passed
JulianTiller pushed a commit to JulianTiller/inav that referenced this pull request Oct 18, 2024
…ted FC proxy mode, updated SITL docs (iNavFlight#9365)

* implemented built-in serial receivers support in SITL
implemented FC Proxy for SITL
update SITL.md

* Update SITL.md

* Update SITL.md

* Update SITL.md

* Update SITL.md

* [SITL] update POSIX serial functions to support non-standard baud rates

* disable xon/hof on serial port (SITL serial_proxy)

---------

Co-authored-by: Jonathan Hudson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants