2021-10-16 00:10:40 -03:00
|
|
|
/*
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
simulate GPS sensors
|
|
|
|
|
|
|
|
Usage example:
|
|
|
|
param set SERIAL5_PROTOCOL 5
|
|
|
|
|
|
|
|
sim_vehicle.py -D --console --map -A --uartB=sim:gps:2
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_HAL/AP_HAL_Boards.h>
|
|
|
|
|
|
|
|
#ifndef HAL_SIM_GPS_ENABLED
|
2021-10-10 22:12:20 -03:00
|
|
|
#define HAL_SIM_GPS_ENABLED (AP_SIM_ENABLED && !defined(HAL_BUILD_AP_PERIPH))
|
2021-10-16 00:10:40 -03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAL_SIM_GPS_ENABLED
|
|
|
|
|
|
|
|
#ifndef HAL_SIM_GPS_EXTERNAL_FIFO_ENABLED
|
2023-02-15 01:25:12 -04:00
|
|
|
#define HAL_SIM_GPS_EXTERNAL_FIFO_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL) && !defined(CYGWIN_BUILD)
|
2021-10-16 00:10:40 -03:00
|
|
|
#endif
|
|
|
|
|
2021-11-01 01:56:39 -03:00
|
|
|
#ifndef AP_SIM_GPS_FILE_ENABLED
|
|
|
|
// really need to use AP_FileSystem for this.
|
|
|
|
#define AP_SIM_GPS_FILE_ENABLED (CONFIG_HAL_BOARD == HAL_BOARD_SITL || CONFIG_HAL_BOARD == HAL_BOARD_LINUX)
|
|
|
|
#endif
|
|
|
|
|
2021-10-16 00:10:40 -03:00
|
|
|
#include "SIM_SerialDevice.h"
|
|
|
|
|
|
|
|
namespace SITL {
|
|
|
|
|
|
|
|
class GPS : public SerialDevice {
|
|
|
|
public:
|
|
|
|
|
2021-11-11 17:30:30 -04:00
|
|
|
CLASS_NO_COPY(GPS);
|
|
|
|
|
2021-10-16 00:10:40 -03:00
|
|
|
enum Type {
|
|
|
|
NONE = 0,
|
|
|
|
UBLOX = 1,
|
|
|
|
NMEA = 5,
|
|
|
|
SBP = 6,
|
2021-11-01 01:56:39 -03:00
|
|
|
#if AP_SIM_GPS_FILE_ENABLED
|
2021-10-16 00:10:40 -03:00
|
|
|
FILE = 7,
|
2021-11-01 01:56:39 -03:00
|
|
|
#endif
|
2021-10-16 00:10:40 -03:00
|
|
|
NOVA = 8,
|
|
|
|
SBP2 = 9,
|
|
|
|
};
|
|
|
|
|
|
|
|
GPS(uint8_t _instance);
|
|
|
|
|
|
|
|
// update state
|
|
|
|
void update();
|
|
|
|
|
|
|
|
ssize_t write_to_autopilot(const char *p, size_t size) const override;
|
|
|
|
|
2022-09-28 07:54:52 -03:00
|
|
|
uint32_t device_baud() const override; // 0 meaning unset
|
|
|
|
|
2021-10-16 00:10:40 -03:00
|
|
|
private:
|
|
|
|
|
|
|
|
uint8_t instance;
|
|
|
|
|
|
|
|
int ext_fifo_fd;
|
|
|
|
|
|
|
|
uint32_t last_update; // milliseconds
|
|
|
|
|
|
|
|
// for delay simulation:
|
|
|
|
struct gps_data {
|
2022-01-05 20:32:55 -04:00
|
|
|
uint32_t timestamp_ms;
|
2021-10-16 00:10:40 -03:00
|
|
|
double latitude;
|
|
|
|
double longitude;
|
|
|
|
float altitude;
|
|
|
|
double speedN;
|
|
|
|
double speedE;
|
|
|
|
double speedD;
|
2021-10-23 06:42:04 -03:00
|
|
|
double yaw_deg;
|
|
|
|
double roll_deg;
|
|
|
|
double pitch_deg;
|
2021-10-16 00:10:40 -03:00
|
|
|
bool have_lock;
|
|
|
|
};
|
2022-01-05 20:32:55 -04:00
|
|
|
// last 20 samples, allowing for up to 20 samples of delay
|
|
|
|
gps_data _gps_history[20];
|
2021-10-16 00:10:40 -03:00
|
|
|
|
|
|
|
|
|
|
|
#if HAL_SIM_GPS_EXTERNAL_FIFO_ENABLED
|
|
|
|
// this will be allocated if needed:
|
|
|
|
char *_gps_fifo;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool _gps_has_basestation_position;
|
|
|
|
gps_data _gps_basestation_data;
|
|
|
|
|
|
|
|
void send_ubx(uint8_t msgid, uint8_t *buf, uint16_t size);
|
|
|
|
void update_ubx(const struct gps_data *d);
|
|
|
|
|
|
|
|
uint8_t nmea_checksum(const char *s);
|
|
|
|
void nmea_printf(const char *fmt, ...);
|
|
|
|
void update_nmea(const struct gps_data *d);
|
|
|
|
|
|
|
|
void sbp_send_message(uint16_t msg_type, uint16_t sender_id, uint8_t len, uint8_t *payload);
|
|
|
|
|
|
|
|
void update_sbp(const struct gps_data *d);
|
|
|
|
void update_sbp2(const struct gps_data *d);
|
|
|
|
|
2021-11-01 01:56:39 -03:00
|
|
|
#if AP_SIM_GPS_FILE_ENABLED
|
2021-10-16 00:10:40 -03:00
|
|
|
void update_file();
|
2021-11-01 01:56:39 -03:00
|
|
|
#endif
|
2021-10-16 00:10:40 -03:00
|
|
|
|
|
|
|
void update_nova(const struct gps_data *d);
|
|
|
|
void nova_send_message(uint8_t *header, uint8_t headerlength, uint8_t *payload, uint8_t payloadlen);
|
|
|
|
uint32_t CRC32Value(uint32_t icrc);
|
|
|
|
uint32_t CalculateBlockCRC32(uint32_t length, uint8_t *buffer, uint32_t crc);
|
2022-01-05 20:32:55 -04:00
|
|
|
|
|
|
|
// get delayed data
|
|
|
|
gps_data interpolate_data(const gps_data &d, uint32_t delay_ms);
|
2021-10-16 00:10:40 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HAL_SIM_GPS_ENABLED
|