Skip to content

Commit aeabab7

Browse files
committed
Merged in breadcrumb_comms_part2 (pull request #422)
Communication support for breadcrumbs - part 2 Approved-by: Nate Koenig <natekoenig@gmail.com>
2 parents dd2d147 + 0ed9e69 commit aeabab7

File tree

6 files changed

+84
-1
lines changed

6 files changed

+84
-1
lines changed

subt_ign/include/subt_ign/CommsBrokerPlugin.hh

+9
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,13 @@ namespace subt
7373
public: virtual bool Load(const tinyxml2::XMLElement *_elem) override final;
7474

7575
/// \brief Callback for World Update events.
76+
/// \param[in] _msg Vector of entity positions.
7677
private: void OnPose(const ignition::msgs::Pose_V &_msg);
7778

79+
/// \brief Update the visibility table if new breadcrumbs are found.
80+
/// Note that this function doesn't consider breadcrumb removals.
81+
private: void UpdateIfNewBreadcrumbs();
82+
7883
/// \brief Broker instance.
7984
private: subt::communication_broker::Broker broker;
8085

@@ -90,6 +95,10 @@ namespace subt
9095
visibilityModel;
9196

9297
private: ignition::transport::Node node;
98+
99+
/// \brief Names and poses of the breadcrumbs.
100+
/// The key is the breadcrumb name and the value is its pose.
101+
private: std::map<std::string, ignition::math::Pose3d> breadcrumbs;
93102
};
94103
}
95104

subt_ign/include/subt_ign/VisibilityRfModel.hh

+22
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <subt_rf_interface/subt_rf_model.h>
2222

2323
#include <map>
24+
#include <set>
2425
#include <string>
2526

2627
#include <ignition/msgs.hh>
@@ -91,6 +92,27 @@ namespace subt
9192
/// \return True if initialized or false otherwise.
9293
public: bool Initialized() const;
9394

95+
/// \brief Populate the visibility information in memory.
96+
/// \param[in] _relays Set of vertices containing breadcrumb robots.
97+
/// You should call this function when the breadcrumbs are updated.
98+
/// The cost of the best route is computed as follows:
99+
/// * The direct route without taking into account breadcrumbs is
100+
/// computed.
101+
/// * The best indirect route (using one or more relays) is computed.
102+
/// * The cost of a route that has multiple hops is the cost of the
103+
/// hop with bigger cost.
104+
/// * The total cost is the minimum cost between the direct route and
105+
/// the best indirect route.
106+
/// A few examples using A--(1)--B--(2)--BC--(2)--D--2--E
107+
/// Note that BC is a breadcrumb.
108+
/// Cost(A, A): 0
109+
/// Cost(A, B): 1
110+
/// Cost(A, BC): 3
111+
/// Cost(A, D): 3
112+
/// Cost(A, E): 4
113+
public: void PopulateVisibilityInfo(
114+
const std::set<ignition::math::Vector3d> &_relayPoses);
115+
94116
/// Function to visualize visibility cost in Gazebo.
95117
private: bool VisualizeVisibility(const ignition::msgs::StringMsg &_req,
96118
ignition::msgs::Boolean &_rep);

subt_ign/src/CommsBrokerPlugin.cc

+29
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@ void CommsBrokerPlugin::OnPose(const ignition::msgs::Pose_V &_msg)
258258
for (int i = 0; i < _msg.pose_size(); ++i)
259259
this->poses[_msg.pose(i).name()] = ignition::msgs::Convert(_msg.pose(i));
260260

261+
// Update the visibility graph if needed.
262+
this->UpdateIfNewBreadcrumbs();
263+
261264
// double dt = (this->simTime - this->lastROSParameterCheckTime).Double();
262265

263266
// Todo: Remove this line and enable the block below when ROS parameter
@@ -299,3 +302,29 @@ void CommsBrokerPlugin::OnPose(const ignition::msgs::Pose_V &_msg)
299302
// the message according to the communication model.
300303
this->broker.DispatchMessages();
301304
}
305+
306+
/////////////////////////////////////////////////
307+
void CommsBrokerPlugin::UpdateIfNewBreadcrumbs()
308+
{
309+
bool newBreadcrumbFound = false;
310+
for (const auto& [name, pose] : this->poses)
311+
{
312+
// New breadcrumb found.
313+
if (name.find("__breadcrumb__") != std::string::npos &&
314+
this->breadcrumbs.find(name) == this->breadcrumbs.end())
315+
{
316+
this->breadcrumbs[name] = pose;
317+
newBreadcrumbFound = true;
318+
}
319+
}
320+
321+
// Update the comms.
322+
if (newBreadcrumbFound)
323+
{
324+
std::set<ignition::math::Vector3d> breadcrumbPoses;
325+
for (const auto& [name, pose] : this->breadcrumbs)
326+
breadcrumbPoses.insert(pose.Pos());
327+
this->visibilityModel->PopulateVisibilityInfo(breadcrumbPoses);
328+
ignmsg << "New breadcrumb detected, visibility graph updated" << std::endl;
329+
}
330+
}

subt_ign/src/VisibilityRfModel.cc

+7
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ rf_power VisibilityModel::ComputeReceivedPower(const double &_txPower,
8383
return std::move(rx);
8484
}
8585

86+
/////////////////////////////////////////////
87+
void VisibilityModel::PopulateVisibilityInfo(
88+
const std::set<ignition::math::Vector3d> &_relayPoses)
89+
{
90+
this->visibilityTable.PopulateVisibilityInfo(_relayPoses);
91+
}
92+
8693
/////////////////////////////////////////////
8794
bool VisibilityModel::VisualizeVisibility(const ignition::msgs::StringMsg &_req,
8895
ignition::msgs::Boolean &_rep)

subt_ign/src/VisibilityTable.cc

+10-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,16 @@ void VisibilityTable::PopulateVisibilityInfo(
270270
// Convert poses to vertices.
271271
std::set<ignition::math::graph::VertexId> relays;
272272
for (const auto pose : _relayPoses)
273-
relays.insert(this->Index(pose));
273+
{
274+
int32_t x = std::round(pose.X());
275+
int32_t y = std::round(pose.Y());
276+
int32_t z = std::round(pose.Z());
277+
auto vertexId = std::make_tuple(x, y, z);
278+
279+
auto it = this->vertices.find(vertexId);
280+
if (it != this->vertices.end())
281+
relays.insert(it->second);
282+
}
274283

275284
// Compute the cost of all routes without considering relays.
276285
this->PopulateVisibilityInfo();

subt_ros/launch/vehicle_topics.launch

+7
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@
166166
args="/model/$(arg name)/odometry@nav_msgs/Odometry[ignition.msgs.Odometry">
167167
<remap from="/model/$(arg name)/odometry" to="odom"/>
168168
</node>
169+
<node
170+
pkg="ros_ign_bridge"
171+
type="parameter_bridge"
172+
name="ros_ign_bridge_breadcrumbs"
173+
args="/model/$(arg name)/breadcrumb/deploy@std_msgs/Empty]ignition.msgs.Empty">
174+
<remap from="/model/$(arg name)/breadcrumb/deploy" to="breadcrumb/deploy"/>
175+
</node>
169176
</group>
170177

171178
<node

0 commit comments

Comments
 (0)