Merge pull request #588 from thomasgubler/fake_gps

Fake gps
This commit is contained in:
Lorenz Meier 2014-01-10 16:18:22 -08:00
commit 42268347d4
1 changed files with 132 additions and 88 deletions

View File

@ -85,7 +85,7 @@ static const int ERROR = -1;
class GPS : public device::CDev
{
public:
GPS(const char *uart_path);
GPS(const char *uart_path, bool fake_gps);
virtual ~GPS();
virtual int init();
@ -112,6 +112,7 @@ private:
struct vehicle_gps_position_s _report; ///< uORB topic for gps position
orb_advert_t _report_pub; ///< uORB pub for gps position
float _rate; ///< position update rate
bool _fake_gps; ///< fake gps output
/**
@ -156,7 +157,7 @@ GPS *g_dev;
}
GPS::GPS(const char *uart_path) :
GPS::GPS(const char *uart_path, bool fake_gps) :
CDev("gps", GPS_DEVICE_PATH),
_task_should_exit(false),
_healthy(false),
@ -164,7 +165,8 @@ GPS::GPS(const char *uart_path) :
_mode(GPS_DRIVER_MODE_UBX),
_Helper(nullptr),
_report_pub(-1),
_rate(0.0f)
_rate(0.0f),
_fake_gps(fake_gps)
{
/* store port name */
strncpy(_port, uart_path, sizeof(_port));
@ -264,6 +266,40 @@ GPS::task_main()
/* loop handling received serial bytes and also configuring in between */
while (!_task_should_exit) {
if (_fake_gps) {
_report.timestamp_position = hrt_absolute_time();
_report.lat = (int32_t)47.378301e7f;
_report.lon = (int32_t)8.538777e7f;
_report.alt = (int32_t)400e3f;
_report.timestamp_variance = hrt_absolute_time();
_report.s_variance_m_s = 10.0f;
_report.p_variance_m = 10.0f;
_report.c_variance_rad = 0.1f;
_report.fix_type = 3;
_report.eph_m = 10.0f;
_report.epv_m = 10.0f;
_report.timestamp_velocity = hrt_absolute_time();
_report.vel_n_m_s = 0.0f;
_report.vel_e_m_s = 0.0f;
_report.vel_d_m_s = 0.0f;
_report.vel_m_s = sqrtf(_report.vel_n_m_s * _report.vel_n_m_s + _report.vel_e_m_s * _report.vel_e_m_s + _report.vel_d_m_s * _report.vel_d_m_s);
_report.cog_rad = 0.0f;
_report.vel_ned_valid = true;
//no time and satellite information simulated
if (_report_pub > 0) {
orb_publish(ORB_ID(vehicle_gps_position), _report_pub, &_report);
} else {
_report_pub = orb_advertise(ORB_ID(vehicle_gps_position), &_report);
}
usleep(2e5);
} else {
if (_Helper != nullptr) {
delete(_Helper);
/* set to zero to ensure parser is not used while not instantiated */
@ -292,7 +328,7 @@ GPS::task_main()
_Helper->reset_update_rates();
while (_Helper->receive(TIMEOUT_5HZ) > 0 && !_task_should_exit) {
// lock();
// lock();
/* opportunistic publishing - else invalid data would end up on the bus */
if (_report_pub > 0) {
orb_publish(ORB_ID(vehicle_gps_position), _report_pub, &_report);
@ -357,6 +393,7 @@ GPS::task_main()
default:
break;
}
}
}
@ -417,7 +454,7 @@ namespace gps
GPS *g_dev;
void start(const char *uart_path);
void start(const char *uart_path, bool fake_gps);
void stop();
void test();
void reset();
@ -427,7 +464,7 @@ void info();
* Start the driver.
*/
void
start(const char *uart_path)
start(const char *uart_path, bool fake_gps)
{
int fd;
@ -435,7 +472,7 @@ start(const char *uart_path)
errx(1, "already started");
/* create the driver */
g_dev = new GPS(uart_path);
g_dev = new GPS(uart_path, fake_gps);
if (g_dev == nullptr)
goto fail;
@ -527,6 +564,7 @@ gps_main(int argc, char *argv[])
/* set to default */
char *device_name = GPS_DEFAULT_UART_PORT;
bool fake_gps = false;
/*
* Start/load the driver.
@ -542,7 +580,13 @@ gps_main(int argc, char *argv[])
}
}
gps::start(device_name);
/* Detect fake gps option */
for (int i = 2; i < argc; i++) {
if (!strcmp(argv[i], "-f"))
fake_gps = true;
}
gps::start(device_name, fake_gps);
}
if (!strcmp(argv[1], "stop"))
@ -567,5 +611,5 @@ gps_main(int argc, char *argv[])
gps::info();
out:
errx(1, "unrecognized command, try 'start', 'stop', 'test', 'reset' or 'status' [-d /dev/ttyS0-n]");
errx(1, "unrecognized command, try 'start', 'stop', 'test', 'reset' or 'status' [-d /dev/ttyS0-n][-f]");
}