exploration_cart_node.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * BSD 3-Clause License
3  *
4  * Copyright (c) 2020 Northwestern University
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 are met:
9  *
10  * * Redistributions of source code must retain the above copyright notice, this
11  * list of conditions and the following disclaimer.
12  *
13  * * Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived from
19  * this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *********************************************************************/
81 #include <iostream>
82 
85 
86 using arma::mat;
87 using arma::vec;
88 
96 
97 constexpr char LOGNAME[] = "cart exploration";
98 
99 int main(int argc, char** argv)
100 {
101  ROS_INFO_STREAM_NAMED(LOGNAME, "Starting exploration");
102  ros::init(argc, argv, "exploration");
103  ros::NodeHandle nh;
104  ros::NodeHandle pnh("~");
105 
107  spinner.start();
108 
109  arma::arma_rng::set_seed_random();
110 
111  // TODO: Add noise to motion model
112  // motion model
113  const SimpleCart cart;
114 
116  const auto map_frame_id = pnh.param<std::string>("map_frame_id", "map");
117  const auto base_frame_id = pnh.param<std::string>("base_frame_id", "base_link");
118 
119  // publish on cmd_vel at a constant frequency
120  const double frequency = pnh.param("frequency", 10.0);
121  // EC validation
122  const double val_dt = pnh.param("val_dt", 0.1);
123  const double val_horizon = pnh.param("val_horizon", 0.5);
124 
125  const double max_vel_x = pnh.param("max_vel_x", 1.0);
126  const double max_rot_vel = pnh.param("max_rot_vel", 1.0);
127 
128  const double min_vel_x = pnh.param("min_vel_x", -1.0);
129  const double min_rot_vel = pnh.param("min_rot_vel", -1.0);
130 
131  const double acc_lim_x = pnh.param("acc_lim_x", 1.0);
132  const double acc_lim_th = pnh.param("acc_lim_th", 1.0);
133 
134  const vec umin = { min_vel_x, 0.0, min_rot_vel };
135  const vec umax = { max_vel_x, 0.0, max_rot_vel };
136 
137  // collision
138  const double boundary_radius = pnh.param("boundary_radius", 0.7);
139  const double search_radius = pnh.param("search_radius", 1.0);
140  const double obstacle_threshold = pnh.param("obstacle_threshold", 0.2);
141  const double occupied_threshold = pnh.param("occupied_threshold", 0.8);
142 
143  // ergodic control
144  const double ec_dt = pnh.param("ec_dt", 0.1);
145  const double ec_horizon = pnh.param("ec_horizon", 2.0);
146  const double target_resolution = pnh.param("target_resolution", 0.1);
147  const double expl_weight = pnh.param("expl_weight", 1.0);
148  const unsigned int num_basis = pnh.param("num_basis", 10);
149  const unsigned int buffer_size = pnh.param("buffer_size", 1e6);
150  const unsigned int batch_size = pnh.param("batch_size", 100);
151 
152  std::vector<double> control_weights = { 1.0, 1.0 };
153  pnh.getParam("control_weights", control_weights);
154 
155  // this is technically not the inverse but the penalty for vy is not used
156  mat Rinv(3, 3, arma::fill::zeros);
157  Rinv(0, 0) = 1.0 / control_weights.at(0);
158  Rinv(1, 1) = 0.0;
159  Rinv(2, 2) = 1.0 / control_weights.at(1);
160 
161  // dwa
162  const double dwa_dt = pnh.param("dwa_dt", 0.1);
163  const double dwa_horizon = pnh.param("dwa_horizon", 1.0);
164  const double acc_dt = pnh.param("acc_dt", 0.2);
165  const unsigned int vx_samples = pnh.param("vx_samples", 3);
166  const unsigned int vth_samples = pnh.param("vth_samples", 5);
167 
168  if (dwa_horizon > ec_horizon)
169  {
171  LOGNAME, "Dynamic window horizon is greater than the ergodic control horizon");
172  ros::shutdown();
173  }
174 
175  // target
176  XmlRpc::XmlRpcValue means;
177  XmlRpc::XmlRpcValue sigmas;
178  pnh.getParam("means", means);
179  pnh.getParam("sigmas", sigmas);
180  const auto num_targets = static_cast<unsigned int>(means.size());
181 
182  GaussianList gaussians(num_targets);
183  for (unsigned int i = 0; i < num_targets; i++)
184  {
185  gaussians.at(i) = { { means[i][0], means[i][1] }, { sigmas[i][0], sigmas[i][1] } };
186  }
187 
188  const Target target(gaussians);
189 
191  const Collision collision(boundary_radius, search_radius, obstacle_threshold,
192  occupied_threshold);
193 
194  const ErgodicControl ergodic_control(cart, collision, ec_dt, ec_horizon,
195  target_resolution, expl_weight, num_basis,
196  buffer_size, batch_size, Rinv, umin, umax);
197 
198  const DynamicWindow dwa(collision, dwa_dt, dwa_horizon, acc_dt, acc_lim_x, 0.0,
199  acc_lim_th, max_vel_x, min_vel_x, 0.0, 0.0, max_rot_vel,
200  min_rot_vel, vx_samples, 0.0, vth_samples);
201 
202  ergodic_exploration::Exploration<SimpleCart> exploration(nh, ergodic_control, collision,
203  dwa);
204 
205  // start exploring
206  exploration.control(target, map_frame_id, base_frame_id, frequency, val_dt, val_horizon);
207 
209 
210  // ros::waitForShutdown();
211  ROS_INFO_STREAM_NAMED(LOGNAME, "Shutting down.");
212  return 0;
213 }
XmlRpc::XmlRpcValue::size
int size() const
ergodic_exploration::Exploration
Exploration template.
Definition: exploration.hpp:66
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros::NodeHandle::getParam
bool getParam(const std::string &key, bool &b) const
ros::AsyncSpinner
main
int main(int argc, char **argv)
Definition: exploration_cart_node.cpp:99
ros::shutdown
ROSCPP_DECL void shutdown()
cart.hpp
Kinematic cart models control wheel velocities or body twist.
ergodic_exploration::DynamicWindow
Dynamic window approach.
Definition: dynamic_window.hpp:52
spinner
void spinner()
exploration.hpp
Ergodic exploration with a user defined target and dynamic window approach for collision avoidance.
LOGNAME
constexpr char LOGNAME[]
Definition: exploration_cart_node.cpp:97
ergodic_exploration::Target
Target distribution.
Definition: target.hpp:110
ROS_ERROR_STREAM_NAMED
#define ROS_ERROR_STREAM_NAMED(name, args)
ergodic_exploration::Exploration::control
void control(const Target &target, const std::string &map_frame_id, const std::string &base_frame_id, double frequency, double val_dt, double val_horizon)
Executes the exploration stack.
Definition: exploration.hpp:177
ros::NodeHandle::param
T param(const std::string &param_name, const T &default_val) const
ROS_INFO_STREAM_NAMED
#define ROS_INFO_STREAM_NAMED(name, args)
ergodic_exploration::GaussianList
std::vector< Gaussian > GaussianList
Definition: target.hpp:52
ergodic_exploration::models::SimpleCart
Kinematic model of a wheeled differential drive robot.
Definition: cart.hpp:152
ergodic_exploration::ErgodicControl
Receding horizon ergodic trajectory optimization.
Definition: ergodic_control.hpp:73
XmlRpc::XmlRpcValue
ros::NodeHandle
ergodic_exploration::Collision
2D collision detection
Definition: collision.hpp:85


ergodic_exploration
Author(s): bostoncleek
autogenerated on Wed Mar 2 2022 00:17:13