moveit2
The MoveIt Motion Planning Framework for ROS 2.
main.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Dave Coleman */
36 
38 #include <rviz_common/ros_integration/ros_client_abstraction.hpp>
39 #include <QApplication>
40 #include <QMessageBox>
41 #include <boost/program_options.hpp>
42 #include <signal.h>
43 #include <locale.h>
44 
45 static void siginthandler(int /*param*/)
46 {
47  QApplication::quit();
48 }
49 
50 void usage(boost::program_options::options_description& desc, int exit_code)
51 {
52  std::cout << desc << '\n';
53  exit(exit_code);
54 }
55 
56 int main(int argc, char** argv)
57 {
58  std::vector<std::string> remaining_args = rclcpp::remove_ros_arguments(argc, argv);
59  std::vector<char*> clean_argv;
60  clean_argv.reserve(remaining_args.size());
61  for (const std::string& arg : remaining_args)
62  {
63  clean_argv.push_back(const_cast<char*>(arg.c_str()));
64  }
65 
66  // Parse parameters
67  namespace po = boost::program_options;
68 
69  // Declare the supported options
70  // clang-format off
71  po::options_description desc("Allowed options");
72  desc.add_options()("help,h", "Show help message")("debug,g", "Run in debug/test mode")(
73  "urdf_path,u", po::value<std::filesystem::path>(), "Optional, path to URDF file in ROS package")(
74  "config_pkg,c", po::value<std::string>(), "Optional, pass in existing config package to load");
75  // clang-format on
76 
77  // Process options
78  po::variables_map vm;
79  try
80  {
81  po::store(po::parse_command_line(clean_argv.size(), &clean_argv[0], desc), vm);
82  po::notify(vm);
83 
84  if (vm.count("help"))
85  usage(desc, 0);
86  }
87  catch (const std::exception& e)
88  {
89  std::cerr << e.what() << '\n';
90  usage(desc, 1);
91  }
92  // Start ROS Node
93  auto client = std::make_unique<rviz_common::ros_integration::RosClientAbstraction>();
94  auto node = client->init(argc, argv, "moveit_setup_assistant", false);
95 
96  // Create Qt Application
97  QApplication qt_app(argc, argv);
98  // numeric values should always be POSIX
99  setlocale(LC_NUMERIC, "C");
100 
101  // Load Qt Widget
102  moveit_setup::assistant::SetupAssistantWidget saw(node, nullptr, vm);
103  saw.setMinimumWidth(1090);
104  saw.setMinimumHeight(600);
105  // saw.setWindowState( Qt::WindowMaximized );
106 
107  saw.show();
108 
109  signal(SIGINT, siginthandler);
110 
111  // Wait here until Qt App is finished
112  const int result = qt_app.exec();
113 
114  // Shutdown ROS
115  rclcpp::shutdown();
116 
117  return result;
118 }
int main(int argc, char **argv)
Definition: main.cpp:56
void usage(boost::program_options::options_description &desc, int exit_code)
Definition: main.cpp:50