Skip to content

Commit

Permalink
Added computervisionstate to python and matlab API clients
Browse files Browse the repository at this point in the history
  • Loading branch information
WouterJansen committed Aug 2, 2024
1 parent b22e106 commit 56af506
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 7 deletions.
26 changes: 26 additions & 0 deletions Matlab/AirSimClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,32 @@ function simSetKinematics(obj, position, orientation, linear_velocity, angular_v
CarState.handbrake = vehicleStateAirSim{"handbrake"};
end

function [ComputerVisionState] = getComputerVisionState(obj)
% GETCOMPUTERVISIONSTATE Get the current state of a computerVision vehicle
%
% Description:
% Retrieves and parses the current state of a computer vision vehicle from the AirSim API.
%
% Outputs:
% ComputerVisionState - Struct containing various state information:
% - kinematics_estimated: Estimated kinematic state including position, orientation, velocities,
% and accelerations.
% - timestamp: Timestamp of the state.

vehicleStateAirSim = obj.rpc_client.call("getComputerVisionState", obj.vehicle_name);

kinematicData = vehicleStateAirSim{"kinematics_estimated"};
kinematicsState.position = obj.nedToRightHandCoordinates(struct2array(struct(kinematicData{"position"})));
kinematicsState.orientation = quatinv(struct2array(struct(kinematicData{"orientation"})));
kinematicsState.linear_velocity = obj.nedToRightHandCoordinates(struct2array(struct(kinematicData{"linear_velocity"})));
kinematicsState.angular_velocity = obj.nedToRightHandCoordinates(struct2array(struct(kinematicData{"angular_velocity"})));
kinematicsState.linear_acceleration = obj.nedToRightHandCoordinates(struct2array(struct(kinematicData{"linear_acceleration"})));
kinematicsState.angular_acceleration = obj.nedToRightHandCoordinates(struct2array(struct(kinematicData{"angular_acceleration"})));
ComputerVisionState.kinematics_estimated = kinematicsState;

ComputerVisionState.timestamp = double(double(vehicleStateAirSim{"timestamp"}))/1e9;
end


function reset(obj)
% RESET Reset the simulation environment
Expand Down
Binary file modified Matlab/Cosys-AirSim Matlab API Client.mltbx
Binary file not shown.
3 changes: 1 addition & 2 deletions Matlab/Cosys-AirSim Matlab API Client.prj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<param.description>This a client implementation of the RPC API for Matlab for the Cosys-AirSim simulation framework. A main class AirSimClient is available which implements all API calls.
Do note that at this point not all functions have been tested and most function documentation was auto-generated. This is still a WIP client.</param.description>
<param.screenshot />
<param.version>3.0.0.2</param.version>
<param.version>3.0.1.0</param.version>
<param.output>${PROJECT_ROOT}\Cosys-AirSim Matlab API Client.mltbx</param.output>
<param.products.name>
<item>Aerospace Toolbox</item>
Expand Down Expand Up @@ -105,7 +105,6 @@ Do note that at this point not all functions have been tested and most function
</fileset.rootdir>
<fileset.rootfiles>
<file>${PROJECT_ROOT}\AirSimCameraTypes.m</file>
<file>${PROJECT_ROOT}\AirSimClient.asv</file>
<file>${PROJECT_ROOT}\AirSimClient.m</file>
<file>${PROJECT_ROOT}\AirSimDrivetrainTypes.m</file>
<file>${PROJECT_ROOT}\AirSimGenerateColorMap.m</file>
Expand Down
2 changes: 1 addition & 1 deletion PythonClient/cosysairsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from .utils import *
from .types import *

__version__ = "3.0.0"
__version__ = "3.0.1"
25 changes: 22 additions & 3 deletions PythonClient/cosysairsim/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2268,7 +2268,7 @@ def getMultirotorState(self, vehicle_name=''):
vehicle_name (str, optional): Vehicle to get the state of
Returns:
MultirotorState:
MultirotorState: Struct containing multirotor state values
"""
return MultirotorState.from_msgpack(self.client.call('getMultirotorState', vehicle_name))

Expand Down Expand Up @@ -2313,7 +2313,7 @@ def getCarState(self, vehicle_name=''):
vehicle_name (str, optional): Name of vehicle
Returns:
CarState:
CarState: Struct containing car state values
"""
state_raw = self.client.call('getCarState', vehicle_name)
return CarState.from_msgpack(state_raw)
Expand All @@ -2324,7 +2324,26 @@ def getCarControls(self, vehicle_name=''):
vehicle_name (str, optional): Name of vehicle
Returns:
CarControls:
CarControls: Struct containing control values
"""
controls_raw = self.client.call('getCarControls', vehicle_name)
return CarControls.from_msgpack(controls_raw)


#------------------------------ ComputerVision APIs ---------------------------------------
class ComputerVisionClient(VehicleClient, object):
def __init__(self, ip="", port=41451, timeout_value=3600):
super(ComputerVisionClient, self).__init__(ip, port, timeout_value)

def getComputerVisionState(self, vehicle_name=''):
"""
The position inside the returned ComputerVisionState is in the frame of the vehicle's starting point
Args:
vehicle_name (str, optional): Name of vehicle
Returns:
ComputerVisionState: Struct containing computer vision state values
"""
state_raw = self.client.call('getComputerVisionState', vehicle_name)
return ComputerVisionState.from_msgpack(state_raw)
4 changes: 4 additions & 0 deletions PythonClient/cosysairsim/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ class EnvironmentState(MsgpackMixin):
temperature = 0.0
air_density = 0.0

class ComputerVisionState(MsgpackMixin):
kinematics_estimated = KinematicsState()
timestamp = np.uint64(0)

class CarState(MsgpackMixin):
speed = 0.0
gear = 0
Expand Down
2 changes: 1 addition & 1 deletion PythonClient/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "cosysairsim"
version = "3.0.0"
version = "3.0.1"
description = "This package contains simple Python client for Cosys-AirSim. This integrates most API functions over RPC."
readme = {file = "README.md", content-type = "text/markdown"}
authors = [{ name = "Shital Shah", email = "[email protected]" },
Expand Down

0 comments on commit 56af506

Please sign in to comment.