Skip to content

Commit

Permalink
reorganized AutonomyLib C++ code
Browse files Browse the repository at this point in the history
  • Loading branch information
admercs committed Apr 25, 2024
1 parent 37bfa77 commit 3dfb1a8
Show file tree
Hide file tree
Showing 161 changed files with 10,147 additions and 7,321 deletions.
14 changes: 8 additions & 6 deletions AutonomyLib/include/api/ApiProvider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@
#include "VehicleSimApiBase.hpp"
#include "WorldSimApiBase.hpp"
#include "common/utils/UniqueValueMap.hpp"

#include <map>

namespace nervosys {
namespace autonomylib {

class ApiProvider {

private:
WorldSimApiBase *world_sim_api_;

common_utils::UniqueValueMap<std::string, VehicleApiBase *> vehicle_apis_;
common_utils::UniqueValueMap<std::string, VehicleSimApiBase *> vehicle_sim_apis_;

public:
ApiProvider(WorldSimApiBase *world_sim_api) : world_sim_api_(world_sim_api) {}
virtual ~ApiProvider() = default;
Expand Down Expand Up @@ -54,12 +62,6 @@ class ApiProvider {
vehicle_apis_.insert_or_assign("", vehicle_apis_.at(vehicle_name));
vehicle_sim_apis_.insert_or_assign("", vehicle_sim_apis_.at(vehicle_name));
}

private:
WorldSimApiBase *world_sim_api_;

common_utils::UniqueValueMap<std::string, VehicleApiBase *> vehicle_apis_;
common_utils::UniqueValueMap<std::string, VehicleSimApiBase *> vehicle_sim_apis_;
};

} // namespace autonomylib
Expand Down
2 changes: 2 additions & 0 deletions AutonomyLib/include/api/ApiServerBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
#define autonomylib_api_ApiServerBase_hpp

#include "common/Common.hpp"

#include <functional>

namespace nervosys {
namespace autonomylib {

class ApiServerBase {

public:
virtual void start(bool block, std::size_t thread_count) = 0;
virtual void stop() = 0;
Expand Down
8 changes: 4 additions & 4 deletions AutonomyLib/include/api/RpcLibAdaptorsBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
#include "common/Common.hpp"
#include "common/CommonStructs.hpp"
#include "common/ImageCaptureBase.hpp"
#include "physics/Environment.hpp"
#include "physics/Kinematics.hpp"
#include "safety/SafetyEval.hpp"

#include "common/utils/WindowsApisCommonPost.hpp"
#include "common/utils/WindowsApisCommonPre.hpp"
#include "physics/Environment.hpp"
#include "physics/Kinematics.hpp"
#include "rpc/msgpack.hpp"
#include "safety/SafetyEval.hpp"

namespace nervosys {
namespace autonomylib_rpclib {

class RpcLibAdaptorsBase {

public:
template <typename TSrc, typename TDest> static void to(const std::vector<TSrc> &s, std::vector<TDest> &d) {
d.clear();
Expand Down
18 changes: 9 additions & 9 deletions AutonomyLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ namespace autonomylib {

// common methods for RCP clients of different vehicles
class RpcLibClientBase {

private:
struct impl;
std::unique_ptr<impl> pimpl_;

protected:
void *getClient();
const void *getClient() const;

public:
enum class ConnectionState : uint { Initial = 0, Connected, Disconnected, Reset, Unknown };

public:
RpcLibClientBase(const string &ip_address = "localhost", uint16_t port = RpcLibPort, float timeout_sec = 60);
virtual ~RpcLibClientBase(); // required for pimpl

Expand Down Expand Up @@ -208,14 +216,6 @@ class RpcLibClientBase {
std::string getSettingsString() const;

std::vector<std::string> simListAssets() const;

protected:
void *getClient();
const void *getClient() const;

private:
struct impl;
std::unique_ptr<impl> pimpl_;
};

} // namespace autonomylib
Expand Down
27 changes: 14 additions & 13 deletions AutonomyLib/include/api/RpcLibServerBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ namespace nervosys {
namespace autonomylib {

class RpcLibServerBase : public ApiServerBase {
public:
RpcLibServerBase(ApiProvider *api_provider, const std::string &server_address, uint16_t port = RpcLibPort);
virtual ~RpcLibServerBase() override;

virtual void start(bool block, std::size_t thread_count) override;
virtual void stop() override;
private:
ApiProvider *api_provider_;

class ApiNotSupported : public std::runtime_error {
public:
ApiNotSupported(const std::string &message) : std::runtime_error(message) {}
};
struct impl;
std::unique_ptr<impl> pimpl_;

protected:
void *getServer() const;
Expand Down Expand Up @@ -54,11 +49,17 @@ class RpcLibServerBase : public ApiServerBase {
"' is not available. This could be because this is not a simulation");
}

private:
ApiProvider *api_provider_;
public:
RpcLibServerBase(ApiProvider *api_provider, const std::string &server_address, uint16_t port = RpcLibPort);
virtual ~RpcLibServerBase() override;

struct impl;
std::unique_ptr<impl> pimpl_;
virtual void start(bool block, std::size_t thread_count) override;
virtual void stop() override;

class ApiNotSupported : public std::runtime_error {
public:
ApiNotSupported(const std::string &message) : std::runtime_error(message) {}
};
};

} // namespace autonomylib
Expand Down
38 changes: 20 additions & 18 deletions AutonomyLib/include/api/VehicleApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "sensors/imu/ImuBase.hpp"
#include "sensors/lidar/LidarBase.hpp"
#include "sensors/magnetometer/MagnetometerBase.hpp"

#include <exception>
#include <string>

Expand All @@ -31,6 +32,25 @@ The base class defines usually available methods that all vehicle controllers ma
Some methods may not be applicable to specific vehicle in which case an exception may be raised or call may be ignored.
*/
class VehicleApiBase : public UpdatableObject {

private:
const SensorBase *findSensorByName(const std::string &sensor_name, const SensorBase::SensorType type) const {
const SensorBase *sensor = nullptr;

// Find sensor with the given name (for empty input name, return the first one found)
// Not efficient but should suffice given small number of sensors
uint count_sensors = getSensors().size(type);
for (uint i = 0; i < count_sensors; i++) {
const SensorBase *current_sensor = getSensors().getByType(type, i);
if (current_sensor != nullptr && (current_sensor->getName() == sensor_name || sensor_name == "")) {
sensor = current_sensor;
break;
}
}

return sensor;
}

public:
virtual void enableApiControl(bool is_enabled) = 0;
virtual bool isApiControlEnabled() const = 0;
Expand Down Expand Up @@ -173,24 +193,6 @@ class VehicleApiBase : public UpdatableObject {
public:
VehicleMoveException(const std::string &message) : VehicleControllerException(message) {}
};

private:
const SensorBase *findSensorByName(const std::string &sensor_name, const SensorBase::SensorType type) const {
const SensorBase *sensor = nullptr;

// Find sensor with the given name (for empty input name, return the first one found)
// Not efficient but should suffice given small number of sensors
uint count_sensors = getSensors().size(type);
for (uint i = 0; i < count_sensors; i++) {
const SensorBase *current_sensor = getSensors().getByType(type, i);
if (current_sensor != nullptr && (current_sensor->getName() == sensor_name || sensor_name == "")) {
sensor = current_sensor;
break;
}
}

return sensor;
}
};

} // namespace autonomylib
Expand Down
1 change: 1 addition & 0 deletions AutonomyLib/include/api/VehicleSimApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace nervosys {
namespace autonomylib {

class VehicleSimApiBase : public nervosys::autonomylib::UpdatableObject {

public:
virtual ~VehicleSimApiBase() = default;

Expand Down
1 change: 1 addition & 0 deletions AutonomyLib/include/api/WorldSimApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace nervosys {
namespace autonomylib {

class WorldSimApiBase {

public:
enum class WeatherParameter {
Rain = 0,
Expand Down
Loading

0 comments on commit 3dfb1a8

Please sign in to comment.