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

Sync libcontroller master #853

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def signal_strength(self) -> float:
return wb.wb_receiver_get_signal_strength(self._tag)

@property
def emitter_direction(self):
return wb.wb_receiver_get_emitter_direction(self._tag)
def emitter_direction(self) -> List[float]:
return wb.wb_receiver_get_emitter_direction(self._tag)[:3]

@property
def channel(self) -> int:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,54 +169,60 @@ static bool get_webots_home() {
// Gets and stores the path to the latest installed version of Matlab on the system.
static bool get_matlab_path() {
struct dirent *directory_entry; // Pointer for directory entry

#ifdef __APPLE__
const char *matlab_directory = "/Applications/";
const char *matlab_version_wc = "MATLAB_R20";
#else
const char *matlab_version_wc = "R20";
#ifdef _WIN32
const char *matlab_exec_suffix = "/bin/matlab";
#elif _WIN32
const char *matlab_directory = "C:\\Program Files\\MATLAB\\";
const char *matlab_version_wc = "R20";
const char *matlab_exec_suffix = "\\bin\\matlab.exe";
#else // __linux__
#elif __linux__
const char *matlab_directory = "/usr/local/MATLAB/";
const char *matlab_version_wc = "R20";
const char *matlab_exec_suffix = "/bin/matlab";
#endif
#else
#error "OS not supported!"
#endif

DIR *directory = opendir(matlab_directory);
#ifndef __APPLE__
if (directory == NULL) {
fprintf(stderr, "No installation of MATLAB available.\n");
#ifdef __APPLE__
fprintf(stderr, "Could not open Applications folder to search for MATLAB installation. Please specify it manually using "
"the option '--matlab-path'.\n");
#else
fprintf(stderr, "No installation of MATLAB found. Please specify it manually using the option '--matlab-path'.\n");
#endif
return false;
}
#endif

// Get latest available Matlab version
char *latest_version = NULL;
while ((directory_entry = readdir(directory)) != NULL) {
const size_t directory_name_size = strlen(directory_entry->d_name) + 1;
if (strncmp(matlab_version_wc, directory_entry->d_name, strlen(matlab_version_wc)) == 0) {
if (!latest_version)
if (!latest_version) {
latest_version = malloc(directory_name_size);
else if (strcmp(latest_version, directory_entry->d_name) < 0)
memset(latest_version, '\0', directory_name_size);
strncpy(latest_version, directory_entry->d_name, directory_name_size);
strncpy(latest_version, directory_entry->d_name, directory_name_size);
} else if (strcmp(latest_version, directory_entry->d_name) < 0) {
char *tmp = realloc(latest_version, directory_name_size);
if (tmp)
latest_version = tmp;
strncpy(latest_version, directory_entry->d_name, directory_name_size);
}
}
}
closedir(directory);
if (!latest_version) {
fprintf(stderr, "No installation of MATLAB available.\n");
fprintf(stderr, "No installation of MATLAB found. Please specify it manually using the option '--matlab-path'.\n");
return false;
}

#ifdef __APPLE__
const size_t matlab_path_size = snprintf(NULL, 0, "%s%s", matlab_directory, latest_version) + 1;
matlab_path = malloc(matlab_path_size);
sprintf(matlab_path, "%s%s", matlab_directory, latest_version);
#else
const size_t matlab_path_size = snprintf(NULL, 0, "%s%s%s", matlab_directory, latest_version, matlab_exec_suffix) + 1;
matlab_path = malloc(matlab_path_size);
sprintf(matlab_path, "%s%s%s", matlab_directory, latest_version, matlab_exec_suffix);
#endif
printf("Using the latest available MATLAB instance: %s\n", matlab_path);

free(latest_version);
return true;
Expand Down