114 lines
3.6 KiB
Markdown
114 lines
3.6 KiB
Markdown
# Host Application
|
||
|
||
C++ application running on the LattePanda's Linux side. Handles camera acquisition, serial communication with the Arduino firmware, and MQTT-based remote control.
|
||
|
||
## Dependencies
|
||
|
||
| Library | Purpose |
|
||
|---------|---------|
|
||
| **Vimba SDK** | Camera control (Allied Vision / FLIR) |
|
||
| **Eclipse Paho MQTT C/C++** | MQTT client for telemetry and remote commands |
|
||
| **OpenCV 4** | Image processing and codecs |
|
||
| **libjxl** | JPEG XL image encoding |
|
||
| **Boost** | Program options, ASIO (serial), Spirit (parsing), threading |
|
||
|
||
Install system packages (Debian/Ubuntu):
|
||
```bash
|
||
sudo apt install libboost-all-dev libopencv-dev libjxl-dev libpaho-mqttpp3-dev libpaho-mqtt3-dev
|
||
```
|
||
|
||
Vimba SDK must be installed separately from Allied Vision.
|
||
|
||
## Build
|
||
|
||
```bash
|
||
mkdir build && cd build
|
||
cmake ..
|
||
make -j$(nproc)
|
||
```
|
||
|
||
## Usage
|
||
|
||
```bash
|
||
./FireWatchTower_2axis [options]
|
||
|
||
Options:
|
||
-h, --help Produce help message
|
||
-i, --init [bool] Run gimbal endstop initialization sequence
|
||
-s, --start [bool] Auto-start camera acquisition on launch
|
||
```
|
||
|
||
Example:
|
||
```bash
|
||
./FireWatchTower_2axis --init true --start true
|
||
```
|
||
|
||
## Serial Communication
|
||
|
||
The host communicates with the Arduino firmware over `/dev/ttyACM0` at 115200 baud.
|
||
|
||
### Incoming Telemetry
|
||
|
||
The firmware periodically sends motor status lines prefixed with `$`, semicolon-delimited:
|
||
```
|
||
$Xenc;Xerr;sgt_val;sgt_stat;is_moving;control_status;hdg;deviation_warn;humid;temp;fan_pwm
|
||
```
|
||
|
||
Parsed into `motor_info` struct in [Serial.h](Serial.h).
|
||
|
||
### Outgoing Commands
|
||
|
||
Single-character commands sent via `serial.sendCommand()`:
|
||
- `r` — Reset motor parameters and power on
|
||
- `e` — Reset SGT (step goal threshold)
|
||
- `q` — Run endstop homing sequence
|
||
- `y` — Load heading calibration from EEPROM
|
||
- `ud80` — Set auto-scan step length
|
||
- `p` — Step yaw to next position (trigger after stop)
|
||
- `kd<heading>` — Set target heading (guided mode)
|
||
|
||
## MQTT Integration
|
||
|
||
Connects to broker at `172.16.42.1` (hardcoded; modify [MQTT.cpp](MQTT.cpp) to change). Subscribes to two control topics and publishes status/camera events.
|
||
|
||
### Subscribed Topics
|
||
|
||
| Topic | Payload | Effect |
|
||
|-------|---------|--------|
|
||
| `GGS/FWT/<name>/ControlCode` | `0` or `1` | Switch control mode: 0=free scan, 1=guided heading |
|
||
| `GGS/FWT/<name>/target_HDG` | Float string | Target yaw heading for guided mode |
|
||
|
||
### Published Topics
|
||
|
||
| Topic | Payload | Description |
|
||
|-------|---------|-------------|
|
||
| `GGS/FWT/<name>/StatusCode` | Integer | Current control mode |
|
||
| `GGS/FWT/<name>/CamEvent/RGB` | — | Camera event notifications |
|
||
|
||
## Interactive Commands (stdin)
|
||
|
||
While running, the host accepts commands on stdin parsed by Boost.Spirit:
|
||
|
||
| Command | Description |
|
||
|---------|-------------|
|
||
| `start` | Start camera acquisition |
|
||
| `stop` | Stop camera acquisition |
|
||
| `set camera <option> <value>` | Set camera parameter via Vimba |
|
||
| `set fps <value>` | Change image rate (images/sec) |
|
||
| `set motorctl <command>` | Send raw command to firmware |
|
||
| `debug` | Toggle motor controller info output |
|
||
| `exit` | Shut down |
|
||
|
||
## Source Files
|
||
|
||
| File | Purpose |
|
||
|------|---------|
|
||
| [FWT_host.cpp](FWT_host.cpp) | Main entry point, CLI parsing, main loop |
|
||
| [Camera.h](Camera.h) / [Camera.cpp](Camera.cpp) | Vimba camera handler, image queue, JPEG XL encoding |
|
||
| [MQTT.h](MQTT.h) / [MQTT.cpp](MQTT.cpp) | Paho MQTT client wrapper, callback handling |
|
||
| [Serial.h](Serial.h) | Boost.ASIО serial port, telemetry parser |
|
||
| [Parser.h](Parser.h) | Boost.Spirit stdin command parser |
|
||
| [timing.h](timing.h) | Timer utility class |
|
||
| [Log.h](Log.h) | Logging utilities |
|
||
| [JPEG_XL.h](JPEG_XL.h) | JPEG XL encoding wrapper |
|