-
Notifications
You must be signed in to change notification settings - Fork 3
/
WifiReceiverPlugin.cc
103 lines (78 loc) · 2.99 KB
/
WifiReceiverPlugin.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "WifiReceiverPlugin.hh"
#include "gazebo/sensors/SensorFactory.hh"
#include "gazebo/sensors/SensorManager.hh"
#include "gazebo/math/Rand.hh"
#include "gazebo/msgs/msgs.hh"
#include "gazebo/transport/Node.hh"
#include "gazebo/transport/Publisher.hh"
#include "gazebo/sensors/WirelessTransmitter.hh"
using namespace gazebo;
using namespace sensors;
GZ_REGISTER_SENSOR_PLUGIN(WifiReceiverPlugin)
WifiReceiverPlugin::WifiReceiverPlugin() : SensorPlugin()
{
}
WifiReceiverPlugin::~WifiReceiverPlugin()
{
}
void WifiReceiverPlugin::Load(sensors::SensorPtr _sensor, sdf::ElementPtr /*_sdf*/)
{
// Get the parent sensor.
this->parentSensor =
std::dynamic_pointer_cast<sensors::WirelessReceiver>(_sensor);
// Make sure the parent sensor is valid.
if (!this->parentSensor)
{
gzerr << "WifiReceiverPlugin requires a Wireless Transmitter Sensor.\n";
return;
}
// Connect to the sensor update event.
this->updateConnection = this->parentSensor->ConnectUpdated(
std::bind(&WifiReceiverPlugin::UpdateImpl, this));
// Make sure the parent sensor is active.
this->parentSensor->SetActive(true);
// this->parentSensor->SetPose(ignition::math::Pose3d (100, 100, 100, 0, 0, 0));
}
bool WifiReceiverPlugin::UpdateImpl()
{
std::string txEssid;
// msgs::WirelessNodes msg;
double rxPower;
double txFreq;
sensors::SensorPtr sensor_ptr;
sensor_ptr = SensorManager::Instance()->GetSensor("wirelessTransmitter");
sensors::WirelessTransmitterPtr transmitSensor;
transmitSensor = std::dynamic_pointer_cast<sensors::WirelessTransmitter>(sensor_ptr);
std::cout << "Connected to: " + transmitSensor->GetESSID() + "\n";
double signal_strength;
signal_strength = transmitSensor->SignalStrength(this->parentSensor->Pose(), this->parentSensor->Gain());
std::cout << "Signal strengh: " << signal_strength << "\n";
math::Pose myPos = this->parentSensor->Pose();
std::cout << "Pose: " << myPos << "\n";
/*for (Sensor_V::iterator it = sensors.begin(); it != sensors.end(); ++it)
{
if ((*it)->GetType() == "wireless_transmitter")
{
sensors::WirelessTransmitterPtr parentSensor;
this->parentSensor = (*it)->GetSensor("wireless_transmitter");
boost::shared_ptr<gazebo::sensors::WirelessTransmitter> transmitter =
boost::static_pointer_cast<WirelessTransmitter>(*it);
txFreq = transmitter->GetFreq();
rxPower = transmitter->GetSignalStrength(myPos, this->GetGain());
// Discard if the frequency received is out of our frequency range,
// or if the received signal strengh is lower than the sensivity
if ((txFreq < this->GetMinFreqFiltered()) ||
(txFreq > this->GetMaxFreqFiltered()) ||
(rxPower < this->GetSensitivity()))
{
continue;
}
txEssid = transmitter->GetESSID();
msgs::WirelessNode *wirelessNode = msg.add_node();
wirelessNode->set_essid(txEssid);
wirelessNode->set_frequency(txFreq);
std::cout << txEssid << "\n";
}
}*/
return true;
}