Skip to content

Commit 00fa002

Browse files
Merge pull request #161 from FS-Online/ground-speed-sensor
Ground speed sensor
2 parents 9b2465e + 7e1d816 commit 00fa002

18 files changed

Lines changed: 221 additions & 5 deletions

AirSim/AirLib/AirLib.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@
9494
<ClInclude Include="include\sensors\imu\ImuBase.hpp" />
9595
<ClInclude Include="include\sensors\imu\ImuSimple.hpp" />
9696
<ClInclude Include="include\sensors\imu\ImuSimpleParams.hpp" />
97+
<ClInclude Include="include\sensors\gss\GSSSimple.hpp" />
98+
9799
<ClInclude Include="include\sensors\SensorBase.hpp" />
98100
<ClInclude Include="include\sensors\SensorCollection.hpp" />
99101
</ItemGroup>

AirSim/AirLib/include/api/RpcLibAdapatorsBase.hpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,32 @@ class RpcLibAdapatorsBase {
655655
}
656656
};
657657

658+
struct GSSData {
659+
660+
msr::airlib::TTimePoint time_stamp;
661+
Vector3r linear_velocity;
662+
663+
MSGPACK_DEFINE_MAP(time_stamp, linear_velocity);
664+
665+
GSSData()
666+
{}
667+
668+
GSSData(const msr::airlib::GSSSimple::Output& o)
669+
{
670+
time_stamp = o.time_stamp;
671+
linear_velocity = o.linear_velocity;
672+
}
673+
674+
msr::airlib::GSSSimple::Output to() const
675+
{
676+
msr::airlib::GSSSimple::Output s;
677+
s.linear_velocity = linear_velocity.to();
678+
s.time_stamp = time_stamp;
679+
680+
return s;
681+
}
682+
};
683+
658684

659685
};
660686

AirSim/AirLib/include/api/RpcLibClientBase.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class RpcLibClientBase {
7777
msr::airlib::ImuBase::Output getImuData(const std::string& imu_name = "", const std::string& vehicle_name = "") const;
7878
msr::airlib::GpsBase::Output getGpsData(const std::string& gps_name = "", const std::string& vehicle_name = "") const;
7979
msr::airlib::DistanceBase::Output getDistanceSensorData(const std::string& distance_sensor_name = "", const std::string& vehicle_name = "") const;
80+
msr::airlib::GSSSimple::Output getGroundSpeedSensorData(const std::string& vehicle_name = "") const;
8081

8182
// sensor omniscient APIs
8283
vector<int> simGetLidarSegmentation(const std::string& lidar_name = "", const std::string& vehicle_name = "") const;

AirSim/AirLib/include/api/VehicleApiBase.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "sensors/lidar/LidarBase.hpp"
1515
#include "sensors/imu/ImuBase.hpp"
1616
#include "sensors/distance/DistanceBase.hpp"
17+
#include "sensors/gss/GSSSimple.hpp"
1718
#include "sensors/gps/GpsBase.hpp"
1819
#include <exception>
1920
#include <string>
@@ -179,6 +180,21 @@ class VehicleApiBase : public UpdatableObject {
179180
return distance_sensor->getOutput();
180181
}
181182

183+
virtual GSSSimple::Output getGroundSpeedSensorData() const
184+
{
185+
uint count_gss = getSensors().size(SensorBase::SensorType::GSS);
186+
if(count_gss == 0) {
187+
throw VehicleControllerException(Utils::stringf("No ground speed sensor on vehicle"));
188+
}
189+
const GSSSimple* gss = static_cast<const GSSSimple*>(getSensors().getByType(SensorBase::SensorType::GSS, 0));
190+
if (gss == nullptr)
191+
{
192+
throw VehicleControllerException(Utils::stringf("Ground speed sensor nullptr"));
193+
}
194+
195+
return gss->getOutput();
196+
}
197+
182198
virtual ~VehicleApiBase() = default;
183199

184200
//exceptions

AirSim/AirLib/include/common/AirSimSettings.hpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,8 +1019,13 @@ struct AirSimSettings {
10191019
case SensorBase::SensorType::Lidar:
10201020
sensor_setting = std::unique_ptr<SensorSetting>(new LidarSetting());
10211021
break;
1022+
case SensorBase::SensorType::GSS:
1023+
// at this moment the codebase requires every sensor to have settings.
1024+
// However, gss does not have settings... so we just place ImuSettings in here for now.
1025+
sensor_setting = std::unique_ptr<SensorSetting>(new ImuSetting());
1026+
break;
10221027
default:
1023-
throw std::invalid_argument("Unexpected sensor type");
1028+
throw std::invalid_argument("Unexpected sensor type (B)");
10241029
}
10251030

10261031
sensor_setting->sensor_type = sensor_type;
@@ -1047,8 +1052,10 @@ struct AirSimSettings {
10471052
case SensorBase::SensorType::Lidar:
10481053
initializeLidarSetting(*static_cast<LidarSetting*>(sensor_setting), settings_json);
10491054
break;
1055+
case SensorBase::SensorType::GSS:
1056+
break;
10501057
default:
1051-
throw std::invalid_argument("Unexpected sensor type");
1058+
throw std::invalid_argument("Unexpected sensor type (A)");
10521059
}
10531060
}
10541061

AirSim/AirLib/include/sensors/SensorBase.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class SensorBase : public UpdatableObject {
2323
Imu = 2,
2424
Gps = 3,
2525
Distance = 5,
26-
Lidar = 6
26+
Lidar = 6,
27+
GSS = 7,
2728
};
2829

2930
SensorBase(const std::string& sensor_name = "")

AirSim/AirLib/include/sensors/SensorFactory.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ class SensorFactory {
2525
return std::unique_ptr<ImuSimple>(new ImuSimple(*static_cast<const AirSimSettings::ImuSetting*>(sensor_setting)));
2626
case SensorBase::SensorType::Gps:
2727
return std::unique_ptr<GpsSimple>(new GpsSimple(*static_cast<const AirSimSettings::GpsSetting*>(sensor_setting)));
28+
case SensorBase::SensorType::GSS:
29+
return std::unique_ptr<GSSSimple>(new GSSSimple());
2830
default:
29-
throw new std::invalid_argument("Unexpected sensor type");
31+
throw new std::invalid_argument("Unexpected sensor type (C)");
3032
}
3133
}
3234

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef msr_airlib_GSSSimple_hpp
2+
#define msr_airlib_GSSSimple_hpp
3+
4+
5+
#include "sensors/SensorBase.hpp"
6+
7+
8+
namespace msr { namespace airlib {
9+
10+
class GSSSimple : public SensorBase {
11+
public:
12+
// Ground Speed Sensor
13+
GSSSimple(const std::string& sensor_name = "")
14+
: SensorBase(sensor_name)
15+
{}
16+
17+
public:
18+
struct Output {
19+
TTimePoint time_stamp;
20+
Vector3r linear_velocity;
21+
};
22+
23+
public:
24+
virtual void update() override
25+
{
26+
Output output;
27+
const GroundTruth& ground_truth = getGroundTruth();
28+
29+
output.time_stamp = clock()->nowNanos();
30+
output.linear_velocity = Vector3r(std::sqrt(std::pow(ground_truth.kinematics->twist.linear.x(), 2) + std::pow(ground_truth.kinematics->twist.linear.y(), 2)), 0, ground_truth.kinematics->twist.linear.z());
31+
32+
output_ = output;
33+
}
34+
const Output& getOutput() const
35+
{
36+
return output_;
37+
}
38+
39+
virtual ~GSSSimple() = default;
40+
41+
virtual void resetImplementation() override {
42+
43+
}
44+
45+
private:
46+
Output output_;
47+
};
48+
49+
50+
}}
51+
#endif

AirSim/AirLib/src/api/RpcLibClientBase.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ msr::airlib::DistanceBase::Output RpcLibClientBase::getDistanceSensorData(const
175175
return pimpl_->client.call("getDistanceSensorData", distance_sensor_name, vehicle_name).as<RpcLibAdapatorsBase::DistanceSensorData>().to();
176176
}
177177

178+
msr::airlib::GSSSimple::Output RpcLibClientBase::getGroundSpeedSensorData(const std::string& vehicle_name) const
179+
{
180+
return pimpl_->client.call("getGroundSpeedSensorData", vehicle_name).as<RpcLibAdapatorsBase::GSSData>().to();
181+
}
182+
178183
vector<int> RpcLibClientBase::simGetLidarSegmentation(const std::string& lidar_name, const std::string& vehicle_name) const
179184
{
180185
return pimpl_->client.call("simGetLidarSegmentation", lidar_name, vehicle_name).as<vector<int>>();

AirSim/AirLib/src/api/RpcLibServerBase.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ RpcLibServerBase::RpcLibServerBase(ApiProvider* api_provider, const std::string&
213213
return RpcLibAdapatorsBase::DistanceSensorData(distance_sensor_data);
214214
});
215215

216+
pimpl_->server.bind("getGroundSpeedSensorData", [&](const std::string& vehicle_name) -> RpcLibAdapatorsBase::GSSData {
217+
const auto& gss_data = getVehicleApi(vehicle_name)->getGroundSpeedSensorData();
218+
return RpcLibAdapatorsBase::GSSData(gss_data);
219+
});
220+
216221
pimpl_->server.bind("simGetCameraInfo", [&](const std::string& camera_name, const std::string& vehicle_name) -> RpcLibAdapatorsBase::CameraInfo {
217222
const auto& camera_info = getVehicleSimApi(vehicle_name)->getCameraInfo(camera_name);
218223
return RpcLibAdapatorsBase::CameraInfo(camera_info);

0 commit comments

Comments
 (0)