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

Put locations.txt in @ROMFS for SITL #16176

Merged
merged 2 commits into from
Jan 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Tools/ardupilotwaf/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,10 @@ def configure_env(self, cfg, env):
for f in os.listdir('Tools/autotest/models'):
if fnmatch.fnmatch(f, "*.json") or fnmatch.fnmatch(f, "*.parm"):
env.ROMFS_FILES += [('models/'+f,'Tools/autotest/models/'+f)]


# include locations.txt so SITL on windows can lookup by name
env.ROMFS_FILES += [('locations.txt','Tools/autotest/locations.txt')]

# embed any scripts from ROMFS/scripts
if os.path.exists('ROMFS/scripts'):
for f in os.listdir('ROMFS/scripts'):
Expand Down
5 changes: 5 additions & 0 deletions libraries/AP_HAL_SITL/SITL_State.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ class HALSITL::SITL_State {
Location &loc,
float &yaw_degrees);

/* lookup a location in locations.txt */
static bool lookup_location(const char *home_str,
Location &loc,
float &yaw_degrees);

private:
void _parse_command_line(int argc, char * const argv[]);
void _set_param_default(const char *parm);
Expand Down
44 changes: 42 additions & 2 deletions libraries/AP_HAL_SITL/SITL_cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <SITL/SIM_Scrimmage.h>
#include <SITL/SIM_Webots.h>
#include <SITL/SIM_JSON.h>
#include <AP_Filesystem/AP_Filesystem.h>

#include <signal.h>
#include <stdio.h>
Expand Down Expand Up @@ -74,7 +75,7 @@ void SITL_State::_usage(void)
"\t--instance|-I N set instance of SITL (adds 10*instance to all port numbers)\n"
// "\t--param|-P NAME=VALUE set some param\n" CURRENTLY BROKEN!
"\t--synthetic-clock|-S set synthetic clock mode\n"
"\t--home|-O HOME set start location (lat,lng,alt,yaw)\n"
"\t--home|-O HOME set start location (lat,lng,alt,yaw) or location name\n"
"\t--model|-M MODEL set simulation model\n"
"\t--config string set additional simulation config string\n"
"\t--fg|-F ADDRESS set Flight Gear view address, defaults to 127.0.0.1\n"
Expand Down Expand Up @@ -435,7 +436,12 @@ void SITL_State::_parse_command_line(int argc, char * const argv[])
if (home_str != nullptr) {
Location home;
float home_yaw;
if (!parse_home(home_str, home, home_yaw)) {
if (strchr(home_str,',') == nullptr) {
if (!lookup_location(home_str, home, home_yaw)) {
::printf("Failed to find location (%s). Should be in locations.txt or LAT,LON,ALT,HDG e.g. 37.4003371,-122.0800351,0,353\n", home_str);
exit(1);
}
} else if (!parse_home(home_str, home, home_yaw)) {
::printf("Failed to parse home string (%s). Should be LAT,LON,ALT,HDG e.g. 37.4003371,-122.0800351,0,353\n", home_str);
exit(1);
}
Expand Down Expand Up @@ -545,4 +551,38 @@ bool SITL_State::parse_home(const char *home_str, Location &loc, float &yaw_degr
return true;
}

/*
lookup a location in locations.txt in ROMFS
*/
bool SITL_State::lookup_location(const char *home_str, Location &loc, float &yaw_degrees)
{
const char *locations = "@ROMFS/locations.txt";
FileData *fd = AP::FS().load_file(locations);
if (fd == nullptr) {
::printf("Missing %s\n", locations);
return false;
}
char *str = strndup((const char *)fd->data, fd->length);
if (!str) {
delete fd;
return false;
}
size_t len = strlen(home_str);
char *saveptr = nullptr;
for (char *s = strtok_r(str, "\r\n", &saveptr);
s;
s=strtok_r(nullptr, "\r\n", &saveptr)) {
if (strncasecmp(s, home_str, len) == 0 && s[len]=='=') {
bool ok = parse_home(&s[len+1], loc, yaw_degrees);
free(str);
delete fd;
return ok;
}
}
free(str);
delete fd;
::printf("Failed to find location '%s'\n", home_str);
return false;
}

#endif