47 namespace environment {
55 ROS_WARN(
"%s: Tried to collision check an uninitialized BallsInBox.",
61 if (!bound.ContainedWithinBox(position,
lower_,
upper_))
return false;
66 ROS_WARN_THROTTLE(1.0,
67 "%s: Caution! Linear search may be slowing you down.",
71 for (
size_t ii = 0; ii <
centers_.size(); ii++) {
72 if (bound.OverlapsSphere(position,
centers_[ii],
radii_[ii]))
return false;
82 const fastrack_msgs::SensedSpheres::ConstPtr& msg) {
84 if (msg->centers.size() != msg->radii.size())
85 ROS_WARN(
"%s: Malformed SensedSpheres msg.",
name_.c_str());
87 const size_t num_obstacles = std::min(msg->centers.size(), msg->radii.size());
92 ROS_WARN_THROTTLE(1.0,
93 "%s: Caution! Linear search may be slowing you down.",
96 bool any_unique =
false;
97 for (
size_t ii = 0; ii < num_obstacles; ii++) {
98 const Vector3d p(msg->centers[ii].x, msg->centers[ii].y,
100 const double r = msg->radii[ii];
104 for (
size_t jj = 0; jj <
centers_.size(); jj++) {
130 const SphereSensorParams& params)
const {
132 fastrack_msgs::SensedSpheres msg;
133 msg.sensor_position.x = params.position(0);
134 msg.sensor_position.y = params.position(1);
135 msg.sensor_position.z = params.position(2);
136 msg.sensor_radius = params.range;
139 geometry_msgs::Vector3 c;
140 for (
size_t ii = 0; ii <
centers_.size(); ii++) {
141 if ((params.position -
centers_[ii]).norm() < params.range +
radii_[ii]) {
146 msg.centers.push_back(c);
147 msg.radii.push_back(
radii_[ii]);
156 if (
vis_pub_.getNumSubscribers() <= 0)
return;
159 visualization_msgs::Marker cube;
162 cube.header.stamp = ros::Time::now();
164 cube.type = visualization_msgs::Marker::CUBE;
165 cube.action = visualization_msgs::Marker::ADD;
171 geometry_msgs::Point center;
175 center.x =
lower_(0) + 0.5 * cube.scale.x;
178 center.y =
lower_(1) + 0.5 * cube.scale.y;
181 center.z =
lower_(2) + 0.5 * cube.scale.z;
183 cube.pose.position = center;
184 cube.pose.orientation.x = 0.0;
185 cube.pose.orientation.y = 0.0;
186 cube.pose.orientation.z = 0.0;
187 cube.pose.orientation.w = 1.0;
193 for (
size_t ii = 0; ii <
centers_.size(); ii++) {
194 visualization_msgs::Marker sphere;
195 sphere.ns =
"sphere";
197 sphere.header.stamp = ros::Time::now();
198 sphere.id =
static_cast<int>(ii);
199 sphere.type = visualization_msgs::Marker::SPHERE;
200 sphere.action = visualization_msgs::Marker::ADD;
202 sphere.scale.x = 2.0 *
radii_[ii];
203 sphere.scale.y = 2.0 *
radii_[ii];
204 sphere.scale.z = 2.0 *
radii_[ii];
206 sphere.color.a = 0.9;
207 sphere.color.r = 0.7;
208 sphere.color.g = 0.5;
209 sphere.color.b = 0.5;
211 geometry_msgs::Point p;
212 const Vector3d point =
centers_[ii];
217 sphere.pose.position = p;
221 ros::Duration(0.01).sleep();
232 ros::NodeHandle nl(n);
235 std::vector<double> obstacle_xs, obstacle_ys, obstacle_zs, obstacle_rs;
236 if (nl.getParam(
"env/obstacle/xs", obstacle_xs) &&
237 nl.getParam(
"env/obstacle/ys", obstacle_ys) &&
238 nl.getParam(
"env/obstacle/zs", obstacle_zs) &&
239 nl.getParam(
"env/obstacle/rs", obstacle_rs)) {
240 if (obstacle_xs.size() != obstacle_ys.size() ||
241 obstacle_zs.size() != obstacle_rs.size() ||
242 obstacle_ys.size() != obstacle_zs.size()) {
243 ROS_WARN(
"%s: Pre-specified obstacles are malformed.",
name_.c_str());
245 for (
size_t ii = 0; ii < obstacle_xs.size(); ii++) {
247 Vector3d(obstacle_xs[ii], obstacle_ys[ii], obstacle_zs[ii]));
248 radii_.push_back(obstacle_rs[ii]);
253 ROS_INFO(
"%s: No pre-specified obstacles.",
name_.c_str());
258 double min_radius, max_radius;
259 if (!nl.getParam(
"env/num_random_obstacles", num))
return false;
260 if (!nl.getParam(
"env/min_radius", min_radius))
return false;
261 if (!nl.getParam(
"env/max_radius", max_radius))
return false;
265 if (!nl.getParam(
"env/seed", seed))
return false;
275 double max_radius,
unsigned int seed) {
277 std::random_device rd;
278 std::default_random_engine rng(rd());
282 std::uniform_real_distribution<double> unif_x(
lower_(0),
upper_(0));
283 std::uniform_real_distribution<double> unif_y(
lower_(1),
upper_(1));
284 std::uniform_real_distribution<double> unif_z(
lower_(2),
upper_(2));
285 std::uniform_real_distribution<double> unif_r(min_radius, max_radius);
288 for (
size_t ii = 0; ii < num; ii++) {
289 centers_.push_back(Vector3d(unif_x(rng), unif_y(rng), unif_z(rng)));
290 radii_.push_back(unif_r(rng));
bool LoadParameters(const ros::NodeHandle &n)
ros::Publisher updated_pub_
std::vector< Vector3d > centers_
static constexpr double kEpsilon
fastrack_msgs::SensedSpheres SimulateSensor(const SphereSensorParams ¶ms) const
void GenerateObstacles(size_t num, double min_radius, double max_radius, unsigned int seed=0)
std::vector< double > radii_
bool IsValid(const Vector3d &position, const TrackingBound &bound, double time=std::numeric_limits< double >::quiet_NaN()) const
void SensorCallback(const fastrack_msgs::SensedSpheres::ConstPtr &msg)