Skip to content

Commit

Permalink
added simPrintLogMessage API, #635
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Nov 28, 2017
1 parent a2d81ff commit f0e83c2
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions AirLib/include/api/RpcLibClientBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class RpcLibClientBase {

bool simSetSegmentationObjectID(const std::string& mesh_name, int object_id, bool is_name_regex = false);
int simGetSegmentationObjectID(const std::string& mesh_name);
void simPrintLogMessage(const std::string& message, std::string message_param = "", unsigned char severity = 0);

virtual ~RpcLibClientBase(); //required for pimpl

Expand Down
2 changes: 2 additions & 0 deletions AirLib/include/api/VehicleApiBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class VehicleApiBase {
virtual bool simSetSegmentationObjectID(const std::string& mesh_name, int object_id, bool is_name_regex = false) = 0;
virtual int simGetSegmentationObjectID(const std::string& mesh_name) = 0;

virtual void simPrintLogMessage(const std::string& message, std::string message_param = "", unsigned char severity = 0) = 0;

virtual CollisionInfo getCollisionInfo() = 0;

virtual ~VehicleApiBase() = default;
Expand Down
2 changes: 2 additions & 0 deletions AirLib/include/controllers/VehicleConnectorBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class VehicleConnectorBase : public UpdatableObject
virtual bool setSegmentationObjectID(const std::string& mesh_name, int object_id,
bool is_name_regex = false) = 0;
virtual int getSegmentationObjectID(const std::string& mesh_name) = 0;
virtual void printLogMessage(const std::string& message, std::string message_param = "", unsigned char severity = 0) = 0;

};


Expand Down
5 changes: 5 additions & 0 deletions AirLib/include/vehicles/multirotor/api/DroneApi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ class DroneApi : public VehicleApiBase {
return vector<uint8_t>();
}

virtual void simPrintLogMessage(const std::string& message, std::string message_param, unsigned char severity) override
{
vehicle_->printLogMessage(message, message_param, severity);
}

virtual bool isApiControlEnabled() override
{
return controller_->isApiControlEnabled();
Expand Down
6 changes: 6 additions & 0 deletions AirLib/src/api/RpcLibClientBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ vector<uint8_t> RpcLibClientBase::simGetImage(int camera_id, VehicleCameraBase::
return result;
}

void RpcLibClientBase::simPrintLogMessage(const std::string& message, std::string message_param, unsigned char severity)
{
pimpl_->client.call("simPrintLogMessage", message, message_param, severity);
}


msr::airlib::GeoPoint RpcLibClientBase::getHomeGeoPoint()
{
return pimpl_->client.call("getHomeGeoPoint").as<RpcLibAdapatorsBase::GeoPoint>().to();
Expand Down
4 changes: 4 additions & 0 deletions AirLib/src/api/RpcLibServerBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ RpcLibServerBase::RpcLibServerBase(VehicleApiBase* vehicle, string server_addres
vehicle_->reset();
});

pimpl_->server.bind("simPrintLogMessage", [&](const std::string& message, std::string message_param, unsigned char severity) -> void {
vehicle_->simPrintLogMessage(message, message_param, severity);
});

pimpl_->server.bind("getHomeGeoPoint", [&]() -> RpcLibAdapatorsBase::GeoPoint {
return vehicle_->getHomeGeoPoint();
});
Expand Down
5 changes: 4 additions & 1 deletion PythonClient/AirSimClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ def simSetSegmentationObjectID(self, mesh_name, object_id, is_name_regex = False
return self.client.call('simSetSegmentationObjectID', mesh_name, object_id, is_name_regex)
def simGetSegmentationObjectID(self, mesh_name):
return self.client.call('simGetSegmentationObjectID', mesh_name)

def simPrintLogMessage(self, message, message_param = "", severity = 0):
return self.client.call('simPrintLogMessage', message, message_param, severity)


# camera control
# simGetImage returns compressed png in array of bytes
# image_type uses one of the AirSimImageType members
Expand Down
2 changes: 1 addition & 1 deletion PythonClient/PythonClient.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>e2049e20-b6dd-474e-8bca-1c8dc54725aa</ProjectGuid>
<ProjectHome>.</ProjectHome>
<StartupFile>hello_car.py</StartupFile>
<StartupFile>car_collision.py</StartupFile>
<SearchPath>
</SearchPath>
<WorkingDirectory>.</WorkingDirectory>
Expand Down
2 changes: 2 additions & 0 deletions PythonClient/car_collision.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

client.reset()

client.simPrintLogMessage("Hello", "345", 2)

# go forward
car_controls.throttle = 0.5
car_controls.steering = 0
Expand Down
5 changes: 5 additions & 0 deletions Unreal/Plugins/AirSim/Source/Car/CarPawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class ACarPawn::CarApi : public msr::airlib::CarApiBase {
return success;
}

virtual void simPrintLogMessage(const std::string& message, std::string message_param = "", unsigned char severity = 0) override
{
car_pawn_->getVehiclePawnWrapper()->printLogMessage(message, message_param, severity);
}

virtual int simGetSegmentationObjectID(const std::string& mesh_name) override
{
return UAirBlueprintLib::GetMeshStencilID(mesh_name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ bool MultiRotorConnector::setSegmentationObjectID(const std::string& mesh_name,
return success;
}

void MultiRotorConnector::printLogMessage(const std::string& message, std::string message_param, unsigned char severity)
{
vehicle_pawn_wrapper_->printLogMessage(message, message_param, severity);
}

int MultiRotorConnector::getSegmentationObjectID(const std::string& mesh_name)
{
return UAirBlueprintLib::GetMeshStencilID(mesh_name);
Expand Down
3 changes: 3 additions & 0 deletions Unreal/Plugins/AirSim/Source/Multirotor/MultiRotorConnector.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class MultiRotorConnector : public msr::airlib::VehicleConnectorBase

virtual msr::airlib::VehicleCameraBase* getCamera(unsigned int index = 0) override;

virtual void printLogMessage(const std::string& message, std::string message_param = "", unsigned char severity = 0) override;


private:
void detectUsbRc();
static float joyStickToRC(int16_t val);
Expand Down
5 changes: 5 additions & 0 deletions Unreal/Plugins/AirSim/Source/VehiclePawnWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ void VehiclePawnWrapper::plot(std::istream& s, FColor color, const Vector3r& off

}

void VehiclePawnWrapper::printLogMessage(const std::string& message, std::string message_param, unsigned char severity)
{
UAirBlueprintLib::LogMessageString(message, message_param, static_cast<LogDebugLevel>(severity));
}

//parameters in NED frame
VehiclePawnWrapper::Pose VehiclePawnWrapper::getPose() const
{
Expand Down
3 changes: 3 additions & 0 deletions Unreal/Plugins/AirSim/Source/VehiclePawnWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class VehiclePawnWrapper
void setLogLine(std::string line);
std::string getLogLine();

void printLogMessage(const std::string& message, std::string message_param = "", unsigned char severity = 0);


protected:
UPROPERTY(VisibleAnywhere)
UParticleSystem* collision_display_template;
Expand Down
1 change: 1 addition & 0 deletions docs/apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ You can find a ready to run project in HelloCar folder in the repository.
* `enableApiControl`: For safety reasons, by default API control for autonomous vehicle is not enabled and human operator has full control (usually via RC or joystick in simulator). The client must make this call to request control via API. It is likely that human operator of vehicle might have disallowed API control which would mean that enableApiControl has no effect. This can be checked by `isApiControlEnabled`.
* `isApiControlEnabled`: Returns true if API control is established. If false (which is default) then API calls would be ignored. After a successful call to `enableApiControl`, the `isApiControlEnabled` should return true.
* `ping`: If connection is established then this call will return true otherwise it will be blocked until timeout.
* `simPrintLogMessage`: Prints the specified message in the simulator's window. If message_param is also supplied then its printed next to the message and in that case if this API is called with same message value but different message_param again then previous line is overwritten with new line (instead of API creating new line on display). For example, `simPrintLogMessage("Iteration: ", to_string(i))` keeps updating same line on display when API is called with different values of i. The valid values of severity parameter is 0 to 3 inclusive that corresponds to different colors.

### Coordinate System
All AirSim API uses NED coordinate system, i.e., +X is North, +Y is East and +Z is Down. All units are in SI system. Please note that this is different from coordinate system used internally by Unreal Engine. In Unreal Engine, +Z is up instead of down and length unit is in centimeters instead of meters. AirSim APIs takes care of the appropriate conversions. The starting point of the vehicle is always coordinates (0, 0, 0) in NED system. Thus when converting from Unreal coordinates to NED, we first subtract the starting offset and then scale by 100 for cm to m conversion.
Expand Down

0 comments on commit f0e83c2

Please sign in to comment.