Skip to content

Commit

Permalink
posix: add option to use the startup config directory and name for th…
Browse files Browse the repository at this point in the history
…e working directory
  • Loading branch information
lamping7 committed Mar 16, 2018
1 parent 7607c71 commit 03776e3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion launch/single_vehicle_spawn.launch
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<arg name="cmd" default="$(find xacro)/xacro $(find px4)/Tools/sitl_gazebo/models/rotors_description/urdf/$(arg vehicle)_base.xacro rotors_description_dir:=$(find px4)/Tools/sitl_gazebo/models/rotors_description mavlink_udp_port:=$(arg mavlink_udp_port) --inorder"/>
<param command="$(arg cmd)" name="rotors_description"/>
<!-- PX4 SITL -->
<node name="sitl_$(arg ID)" pkg="px4" type="px4" output="screen" args="$(find px4) $(arg rcS)">
<node name="sitl_$(arg ID)" pkg="px4" type="px4" output="screen" args="-w $(find px4) $(arg rcS)">
</node>
<!-- spawn vehicle -->
<node name="$(arg vehicle)_$(arg ID)_spawn" output="screen" pkg="gazebo_ros" type="spawn_model" args="-urdf -param rotors_description -model $(arg vehicle)_$(arg ID) -package_to_model -x $(arg x) -y $(arg y) -z $(arg z) -R $(arg R) -P $(arg P) -Y $(arg Y)"/>
Expand Down
33 changes: 31 additions & 2 deletions platforms/posix/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,10 @@ static void run_cmd(const vector<string> &appargs, bool exit_on_fail, bool silen
static void usage()
{

cout << "./px4 [-d] [data_directory] startup_config [-h]" << endl;
cout << " -d - Optional flag to run the app in daemon mode and does not listen for user input." <<
cout << "./px4 [-d] [-w] [data_directory] startup_config [-h]" << endl;
cout << " -d - Optional flag to run the app in daemon mode and does not listen for user input" <<
endl;
cout << " -w - Use the startup_config location and name as the working directory for rootfs" <<
endl;
cout << " This is needed if px4 is intended to be run as a upstart job on linux" << endl;
cout << "<data_directory> - directory where ROMFS and posix-configs are located (if not given, CWD is used)" << endl;
Expand Down Expand Up @@ -296,6 +298,7 @@ int main(int argc, char **argv)
{
bool daemon_mode = false;
bool chroot_on = false;
bool change_working_dir = false;

tcgetattr(0, &orig_term);
atexit(restore_term);
Expand Down Expand Up @@ -331,6 +334,9 @@ int main(int argc, char **argv)
if (strncmp(argv[index], "-d", 2) == 0) {
daemon_mode = true;

} else if (strncmp(argv[index], "-w", 2) == 0) {
change_working_dir = true;

} else if (strncmp(argv[index], "-h", 2) == 0) {
usage();
return 0;
Expand Down Expand Up @@ -397,6 +403,29 @@ int main(int argc, char **argv)
return -1;
}

if (change_working_dir) {
char rootfs_path[path_max_len];

strcpy(rootfs_path, commands_file.c_str());
strcat(rootfs_path, "_wd");

// check if there is an existing path to working directory, or make it
if (!dirExists(rootfs_path)) {
if (mkpath(rootfs_path, S_IRUSR | S_IWUSR | S_IXUSR) == -1) {
PX4_ERR("Error making rootfs path %s", rootfs_path);
return -1;
}
}

// change current working directory
if (chdir(rootfs_path) == -1) {
PX4_ERR("Error changing to rootfs path %s", rootfs_path);
return -1;
}

cout << "working directory: " << pwd() << endl;
}

// create sym-links
if (symlinks_needed) {
vector<string> path_sym_links;
Expand Down

0 comments on commit 03776e3

Please sign in to comment.