randomize height and spawn locations

This commit is contained in:
Jet 2023-06-24 00:44:57 +01:00
parent de391c8df9
commit d3e4067ff5
2 changed files with 17 additions and 13 deletions

View File

@ -13,6 +13,6 @@ void setup() {
void loop() {
for (int i = 0; i < num_spoofers; i++) {
spoofers[i].update();
delay(500 / num_spoofers);
delay(200 / num_spoofers);
}
}

View File

@ -14,7 +14,6 @@ Spoofer::Spoofer() {
// utm things
memset(&utm_parameters,0,sizeof(utm_parameters));
strcpy(utm_parameters.UAS_operator, getID().c_str());
// strcpy(utm_parameters.UAS_operator, "SUKONDEEZ");
utm_parameters.region = 1;
utm_parameters.EU_category = 1;
utm_parameters.EU_class = 5;
@ -22,36 +21,35 @@ Spoofer::Spoofer() {
memset(&utm_data,0,sizeof(utm_data));
// define location
// 52° 24' 24.4404" -1° 29' 36.564"W
// 52° 24' 24.4404" -1° 29' 36.564"W
// plus some noise
lat_d =
utm_data.latitude_d =
utm_data.base_latitude = 52.0 + (24.0 / 60.0) + (24.4404 / 3600.0);
utm_data.base_latitude = 52.0 + (24.0 / 60.0) + (24.4404 / 3600.0) + (float) (rand() % 10 - 5) / 10000.0;
long_d =
utm_data.longitude_d =
utm_data.base_longitude = -1.0 - (29.0 / 60.0) - (36.564 / 3600.0);
utm_data.base_alt_m = 42.0;
utm_data.base_longitude = -1.0 - (29.0 / 60.0) - (36.564 / 3600.0) + (float) (rand() % 10 - 5) / 10000.0;
utm_data.base_alt_m = (float) (rand() % 1000) / 10.0;
utm_data.alt_msl_m = utm_data.base_alt_m + z;
utm_data.alt_agl_m = z;
utm_data.speed_kn = 1;
utm_data.satellites = 8;
utm_data.base_valid = 1;
utm_utils.calc_m_per_deg(lat_d,&m_deg_lat,&m_deg_long);
}
void Spoofer::update() {
// FAA says minimum rate is 1 Hz, we do 2 Hz here
if ((millis() - last_update) < 500) {
if ((millis() - last_update) < 200) {
return;
}
// number of satellites
utm_data.satellites = rand() % 8 + 8;
// randomly update the velocity
utm_data.speed_kn = constrain(utm_data.speed_kn + (rand() % 5) - 2, 1, 20);
speed_m_x = ((float) utm_data.speed_kn) * 0.514444 * 0.2; // Because we update every 200 ms.
// randomly pick a direction to head and update the heading
float ranf = 0.001 * (float) (((int) rand() % 1000) - 500);
float ranf = (float) (rand() % 1000 - 500) / 1000.0;
int dir_change = (int) (max_dir_change * ranf);
utm_data.heading = (utm_data.heading + dir_change + 360) % 360;
@ -60,6 +58,12 @@ void Spoofer::update() {
x += speed_m_x * sin(rads);
y += speed_m_x * cos(rads);
// calculate new height
float climbrate = (float) (rand() % 200 - 100) / 10.0;
z = constrain(z + climbrate, 10.0, 300.0);
utm_data.alt_msl_m = utm_data.base_alt_m + z;
utm_data.alt_agl_m = z;
// update the x, y
utm_data.latitude_d = utm_data.base_latitude + (y / m_deg_lat);
utm_data.longitude_d = utm_data.base_longitude + (x / m_deg_long);