Skip to content

Commit ce5905f

Browse files
authored
Do not update neighbor information when the message goes through breadcrumbs. (#970)
Signed-off-by: Carlos Agüero <[email protected]>
1 parent 5239956 commit ce5905f

File tree

10 files changed

+51
-25
lines changed

10 files changed

+51
-25
lines changed

subt-communication/subt_communication_broker/src/subt_communication_broker.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -216,14 +216,18 @@ void Broker::DispatchMessages()
216216

217217
bool sendPacket;
218218
double rssi;
219-
std::tie(sendPacket, rssi) =
219+
bool usingBreadcrumbs;
220+
std::tie(sendPacket, rssi, usingBreadcrumbs) =
220221
communication_function(txNode->second->radio,
221222
txNode->second->rf_state,
222223
rxNode->second->rf_state,
223224
msg.data().size());
224225

225226
if (sendPacket)
226227
{
228+
// When using a breadcrumb we don't include the rssi
229+
if (usingBreadcrumbs)
230+
rssi = std::numeric_limits<double>::lowest();
227231
msg.set_rssi(rssi);
228232

229233
if (!this->node.Request(client.address, msg))

subt-communication/subt_communication_broker/src/subt_communication_client.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,11 @@ bool CommsClient::OnMessageRos(subt_msgs::DatagramRos::Request &_req,
452452

453453
std::lock_guard<std::mutex> lock(this->mutex);
454454

455-
this->neighbors[_req.src_address] =
456-
std::make_pair(ros::Time::now().toSec(), _req.rssi);
455+
if (_req.rssi > std::numeric_limits<double>::lowest())
456+
{
457+
this->neighbors[_req.src_address] =
458+
std::make_pair(ros::Time::now().toSec(), _req.rssi);
459+
}
457460

458461
for (auto cb : this->callbacks)
459462
{

subt-communication/subt_communication_model/include/subt_communication_model/subt_communication_model.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,18 @@ inline std::ostream& operator<<(std::ostream& oss,
7575
/// @param tx_state Current state of the transmitter (pose)
7676
/// @param rx_state Current state of the receiver (pose)
7777
/// @param num_bytes Size of the packet
78-
/// @return std::tuple<bool, double> reporting if the packet should be
79-
/// delivered and the received signal strength (in dBm)
80-
std::tuple<bool, double>
78+
/// @return std::tuple<bool, double, bool> reporting if the packet should be
79+
/// delivered, the received signal strength (in dBm) and if breadcrumbs were
80+
/// used.
81+
std::tuple<bool, double, bool>
8182
attempt_send(const radio_configuration& radio,
8283
rf_interface::radio_state& tx_state,
8384
rf_interface::radio_state& rx_state,
8485
const uint64_t& num_bytes
8586
);
8687

8788
/// Function signature for the communication model.
88-
typedef std::function<std::tuple<bool, double>(const radio_configuration&,
89+
typedef std::function<std::tuple<bool, double, bool>(const radio_configuration&,
8990
rf_interface::radio_state&,
9091
rf_interface::radio_state&,
9192
const uint64_t&)> communication_function;

subt-communication/subt_communication_model/src/subt_communication_model.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ inline double dbmToPow(double x) { return 0.001 * pow(10., x / 10.); }
3434
inline double QPSKPowerToBER(double P, double N) { return erfc(sqrt(P / N)); }
3535

3636
/////////////////////////////////////////////
37-
std::tuple<bool, double>
37+
std::tuple<bool, double, bool>
3838
attempt_send(const radio_configuration& radio,
3939
rf_interface::radio_state& tx_state,
4040
rf_interface::radio_state& rx_state,
@@ -68,17 +68,19 @@ attempt_send(const radio_configuration& radio,
6868
{
6969
// ignwarn << "Bitrate limited: " << bits_sent << "bits sent (limit: "
7070
// << radio.capacity * epoch_duration.toSec() << std::endl;
71-
return std::make_tuple(false, std::numeric_limits<double>::lowest());
71+
return std::make_tuple(false, std::numeric_limits<double>::lowest(), false);
7272
}
7373

7474
// Record these bytes
7575
tx_state.bytes_sent.push_back(std::make_pair(now, num_bytes));
7676
tx_state.bytes_sent_this_epoch += num_bytes;
7777

7878
// Get the received power based on TX power and position of each node
79+
bool usingBreadcrumbs;
7980
auto rx_power_dist = radio.pathloss_f(radio.default_tx_power,
8081
tx_state,
81-
rx_state);
82+
rx_state,
83+
usingBreadcrumbs);
8284

8385
double rx_power = rx_power_dist.mean;
8486
if(rx_power_dist.variance > 0.0) {
@@ -113,7 +115,7 @@ attempt_send(const radio_configuration& radio,
113115
bool packet_received = rand_draw > packet_drop_prob;
114116

115117
if(!packet_received)
116-
return std::make_tuple(false, std::numeric_limits<double>::lowest());
118+
return std::make_tuple(false, std::numeric_limits<double>::lowest(), false);
117119

118120
// Maintain running window of bytes received over the last epoch, e.g.,
119121
// 1s
@@ -140,14 +142,14 @@ attempt_send(const radio_configuration& radio,
140142
// ignwarn < <"Bitrate limited: " << bits_received
141143
// << "bits received (limit: " << radio.capacity * epoch_duration.toSec()
142144
// << )\n";
143-
return std::make_tuple(false, std::numeric_limits<double>::lowest());
145+
return std::make_tuple(false, std::numeric_limits<double>::lowest(), false);
144146
}
145147

146148
// Record these bytes
147149
rx_state.bytes_received.push_back(std::make_pair(now, num_bytes));
148150
rx_state.bytes_received_this_epoch += num_bytes;
149151

150-
return std::make_tuple(true, rx_power);
152+
return std::make_tuple(true, rx_power, usingBreadcrumbs);
151153
}
152154

153155
}

subt-communication/subt_communication_model/tests/unit_test.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ TEST(range_based, co_located)
5151

5252
bool send_packet;
5353
double rssi;
54-
std::tie(send_packet, rssi) = attempt_send(radio,
55-
tx, // TX state
56-
rx, // RX state
57-
1000); // 1Kb packet
54+
bool usingBreadcrumbs;
55+
std::tie(send_packet, rssi, usingBreadcrumbs) = attempt_send(radio,
56+
tx, // TX state
57+
rx, // RX state
58+
1000); // 1Kb packet
5859

5960
ASSERT_TRUE(send_packet);
6061
}

subt-communication/subt_rf_interface/include/subt_rf_interface/subt_rf_interface.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ struct rf_power
6565
/// Function signature for computing pathloss.
6666
typedef std::function<rf_power(const double&, // tx_power
6767
radio_state&, // tx_state
68-
radio_state& //rx_state
68+
radio_state&, //rx_state
69+
bool& // using breadcumbs?
6970
)> pathloss_function;
7071

7172

subt_ign/include/subt_ign/VisibilityRfModel.hh

+6-4
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,14 @@ namespace subt
8080
/// Compute received power function that will be given to
8181
/// communcation model.
8282
///
83-
/// @param tx_power Transmit power (dBm)
84-
/// @param tx_state Transmitter state
85-
/// @param rx_state Receiver state
83+
/// @param _txPower Transmit power (dBm)
84+
/// @param _txState Transmitter state
85+
/// @param _rxState Receiver state
86+
/// @param _usingBreadCrumbs True if one or more breadcrumbs were used
8687
public: rf_power ComputeReceivedPower(const double &_txPower,
8788
radio_state &_txState,
88-
radio_state &_rxState);
89+
radio_state &_rxState,
90+
bool &_usingBreadcrumbs);
8991

9092
/// \brief Whether the visibility model has been successfully
9193
/// initialized.

subt_ign/src/Common.cc

+7
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ bool FullWorldPath(const std::string &_worldName,
106106
const std::string tunnelPrefix = "tunnel_circuit_";
107107
const std::string urbanPrefix = "urban_circuit_";
108108
const std::string cavePrefix = "cave_circuit_";
109+
const std::string finalPrefix = "final_event_";
109110
if (0 == _worldName.compare(0, tunnelPrefix.size(), tunnelPrefix))
110111
{
111112
std::string suffix = _worldName.substr(tunnelPrefix.size());
@@ -136,6 +137,12 @@ bool FullWorldPath(const std::string &_worldName,
136137
"cave_circuit", suffix);
137138
}
138139
}
140+
else if (_worldName.find(finalPrefix) != std::string::npos)
141+
{
142+
std::string suffix = _worldName.substr(finalPrefix.size());
143+
worldsDirectory = ignition::common::joinPaths(worldsDirectory,
144+
"final_event", suffix);
145+
}
139146
else if (_worldName.find("simple") == std::string::npos &&
140147
_worldName.find("_qual") == std::string::npos &&
141148
_worldName.find("_stix") == std::string::npos &&

subt_ign/src/CommsBrokerPlugin.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ bool CommsBrokerPlugin::Load(const tinyxml2::XMLElement *_elem)
182182
this->visibilityModel.get(),
183183
std::placeholders::_1,
184184
std::placeholders::_2,
185-
std::placeholders::_3);
185+
std::placeholders::_3,
186+
std::placeholders::_4);
186187
}
187188

188189
// Default comms model type is log_normal_range (will always work)

subt_ign/src/VisibilityRfModel.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ bool VisibilityModel::Initialized() const
6666
/////////////////////////////////////////////
6767
rf_power VisibilityModel::ComputeReceivedPower(const double &_txPower,
6868
radio_state &_txState,
69-
radio_state &_rxState)
69+
radio_state &_rxState,
70+
bool &_usingBreadcrumbs)
7071
{
7172
// Use this->visibilityTable.Cost(_txState, _rxState) to compute
7273
// pathloss and thus, received power
@@ -87,11 +88,13 @@ rf_power VisibilityModel::ComputeReceivedPower(const double &_txPower,
8788
if (visibilityCost.route.empty())
8889
{
8990
// No breadcrumbs in the route
91+
_usingBreadcrumbs = false;
9092
range = _txState.pose.Pos().Distance(_rxState.pose.Pos());
9193
}
9294
else
9395
{
9496
// One or more breadcrumbs to cross.
97+
_usingBreadcrumbs = true;
9598
double distSourceToFirstBreadcrumb =
9699
_txState.pose.Pos().Distance(visibilityCost.posFirstBreadcrumb);
97100
double distLastBreadcrumbToDestination =
@@ -235,7 +238,8 @@ bool VisibilityModel::VisualizeVisibility(const ignition::msgs::StringMsg &_req,
235238
// Set and calculate rf power
236239
tx.pose.Set(from.X(), from.Y(), from.Z(), 0, 0, 0);
237240
rx.pose.Set(to.X(), to.Y(), to.Z(), 0, 0, 0);
238-
rf_power rf_pow = ComputeReceivedPower(txPower, tx, rx);
241+
bool usingBreadcrumbs;
242+
rf_power rf_pow = ComputeReceivedPower(txPower, tx, rx, usingBreadcrumbs);
239243
// Based on rx_power, noise value, and modulation, compute the bit error rate (BER)
240244
double ber = QPSKPowerToBER( dbmToPow(rf_pow.mean), dbmToPow(noise_floor) );
241245
int num_bytes = 100; // Hardcoded number of bytes

0 commit comments

Comments
 (0)