Skip to content

Commit

Permalink
Fixed timestamp retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
WouterJansen committed Jul 17, 2024
1 parent 3437ad5 commit dbb8d73
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
32 changes: 16 additions & 16 deletions Matlab/AirSimClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@

data = obj.rpc_client.call("getImuData", sensorName, obj.vehicle_name);

timestamp = floor(double(double(data{"time_stamp"}))/1e9);
timestamp = double(double(data{"time_stamp"}))/1e9;

imuData.orientation = quatinv(struct2array(struct(data{"orientation"})));
imuData.angularVelocity = obj.nedToRightHandCoordinates(struct2array(struct(data{"angular_velocity"})));
Expand All @@ -165,7 +165,7 @@

data = obj.rpc_client.call("getBarometerData", sensorName, obj.vehicle_name);

timestamp = floor(double(double(data{"time_stamp"}))/1e9);
timestamp = double(double(data{"time_stamp"}))/1e9;
barometerData.altitude = quatinv(struct2array(struct(data{"altitude"})));
barometerData.pressure = obj.nedToRightHandCoordinates(struct2array(struct(data{"pressure"})));
barometerData.qnh = obj.nedToRightHandCoordinates(struct2array(struct(data{"qnh"})));
Expand All @@ -186,7 +186,7 @@

data = obj.rpc_client.call("getMagnetometerData", sensorName, obj.vehicle_name);

timestamp = floor(double(double(data{"time_stamp"}))/1e9);
timestamp = double(double(data{"time_stamp"}))/1e9;
MagnetometerData.magnetic_field_body = obj.nedToRightHandCoordinates(struct2array(struct(data{"magnetic_field_body"})));
MagnetometerData.magnetic_field_covariance = double(data{"magnetic_field_covariance"});
end
Expand All @@ -207,7 +207,7 @@

data = obj.rpc_client.call("getGpsData", sensorName, obj.vehicle_name);

timestamp = floor(double(double(data{"time_stamp"}))/1e9);
timestamp = double(double(data{"time_stamp"}))/1e9;

gnssDataRaw = data{"gnss"};
gnssData.eph = double(gnssDataRaw{"eph"});
Expand All @@ -220,7 +220,7 @@
geopoint.altitude = double(curGeoPointData{"altitude"});
gnssData.geo_point = geopoint;
gnssData.fix_type = double(curGeoPointData{"fix_type"});
gnssData.time_utc = floor(double(double(curGeoPointData{"time_utc"}))/1e9);
gnssData.time_utc = double(double(curGeoPointData{"time_utc"}))/1e9;

isValid = data{"is_valid"};
end
Expand All @@ -240,7 +240,7 @@

data = obj.rpc_client.call("getDistanceSensorData", sensorName, obj.vehicle_name);

timestamp = floor(double(double(data{"time_stamp"}))/1e9);
timestamp = double(double(data{"time_stamp"}))/1e9;
curPoseData = data{"relative_pose"};
DistanceSensorData.relative_pose.position = obj.nedToRightHandCoordinates(struct2array(struct(curPoseData{"position"})));
DistanceSensorData.relative_pose.orientation = quatinv(struct2array(struct(curPoseData{"orientation"})));
Expand Down Expand Up @@ -269,7 +269,7 @@

echoData = obj.rpc_client.call("getEchoData", sensorName, obj.vehicle_name);

timestamp = floor(double(double(echoData{"time_stamp"}))/1e9);
timestamp = double(double(echoData{"time_stamp"}))/1e9;

% Get the sensor pose
sensorPose.position = obj.nedToRightHandCoordinates(struct2array(struct(echoData{"pose"}{"position"})));
Expand Down Expand Up @@ -347,7 +347,7 @@

lidarData = obj.rpc_client.call("getLidarData", sensorName, obj.vehicle_name);

timestamp = floor(double(double(lidarData{"time_stamp"}))/1e9);
timestamp = double(double(lidarData{"time_stamp"}))/1e9;

% Get the sensor pose
sensorPose.position = obj.nedToRightHandCoordinates(struct2array(struct(lidarData{"pose"}{"position"})));
Expand Down Expand Up @@ -386,7 +386,7 @@

lidarData = obj.rpc_client.call("getGPULidarData", sensorName, obj.vehicle_name);

timestamp = floor(double(double(lidarData{"time_stamp"}))/1e9);
timestamp = double(double(lidarData{"time_stamp"}))/1e9;

% Get the sensor pose
sensorPose.position = obj.nedToRightHandCoordinates(struct2array(struct(lidarData{"pose"}{"position"})));
Expand Down Expand Up @@ -456,7 +456,7 @@
image_reshaped = reshape(image_bytes, 3, camera_image.width.int32, camera_image.height.int32);
image = permute(image_reshaped,[3 2 1]);
end
timestamp = floor(double(double(camera_image.time_stamp))/1e9);
timestamp = double(double(camera_image.time_stamp))/1e9;
end

function [images, timestamp] = getCameraImages(obj, sensorName, cameraTypes, annotationLayers)
Expand Down Expand Up @@ -507,7 +507,7 @@
images{i} = rescale(permute(image_reshaped,[3 2 1]));
end
end
timestamp = floor(double(double(camera_image.time_stamp))/1e9);
timestamp = double(double(camera_image.time_stamp))/1e9;
end

function [intrinsics, sensorPose] = getCameraInfo(obj, sensorName)
Expand Down Expand Up @@ -1049,7 +1049,7 @@ function simSetKinematics(obj, position, orientation, linear_velocity, angular_v

collisionData = vehicleStateAirSim{"collision"};
collisionInfo = struct(collisionData);
collisionInfo.time_stamp = floor(double(double(collisionData{"time_stamp"}))/1e9);
collisionInfo.time_stamp = double(double(collisionData{"time_stamp"}))/1e9;
collisionInfo.object_name = string(collisionData{"object_name"});
collisionInfo.object_id = double(collisionData{"object_id"});
collisionInfo.position = struct2array(struct(collisionData{"position"}));
Expand All @@ -1072,7 +1072,7 @@ function simSetKinematics(obj, position, orientation, linear_velocity, angular_v
geopoint.altitude = double(geopointData{"altitude"});
MultirotorState.gps_location = geopoint;

MultirotorState.timestamp = floor(double(double(vehicleStateAirSim{"timestamp"}))/1e9);
MultirotorState.timestamp = double(double(vehicleStateAirSim{"timestamp"}))/1e9;
MultirotorState.landed_state = vehicleStateAirSim{"landed_state"};
MultirotorState.ready = vehicleStateAirSim{"ready"};
MultirotorState.ready_message = string(vehicleStateAirSim{"ready_message"});
Expand Down Expand Up @@ -1101,7 +1101,7 @@ function simSetKinematics(obj, position, orientation, linear_velocity, angular_v

collisionData = vehicleStateAirSim{"collision"};
collisionInfo = struct(collisionData);
collisionInfo.time_stamp = floor(double(double(collisionData{"time_stamp"}))/1e9);
collisionInfo.time_stamp = double(double(collisionData{"time_stamp"}))/1e9;
collisionInfo.object_name = string(collisionData{"object_name"});
collisionInfo.object_id = double(collisionData{"object_id"});
collisionInfo.position = struct2array(struct(collisionData{"position"}));
Expand All @@ -1118,7 +1118,7 @@ function simSetKinematics(obj, position, orientation, linear_velocity, angular_v
kinematicsState.angular_acceleration = obj.nedToRightHandCoordinates(struct2array(struct(kinematicData{"angular_acceleration"})));
CarState.kinematics_estimated = kinematicsState;

CarState.timestamp = floor(double(double(vehicleStateAirSim{"timestamp"}))/1e9);
CarState.timestamp = double(double(vehicleStateAirSim{"timestamp"}))/1e9;
CarState.speed = vehicleStateAirSim{"speed"};
CarState.gear = vehicleStateAirSim{"gear"};
CarState.rpm = vehicleStateAirSim{"rpm"};
Expand Down Expand Up @@ -1291,7 +1291,7 @@ function setWeather(obj, weatherType, weatherValue)

collisionData = obj.rpc_client.call("simGetCollisionInfo", obj.vehicle_name);
collisionInfo = struct(collisionData);
collisionInfo.time_stamp = floor(double(double(collisionData{"time_stamp"}))/1e9);
collisionInfo.time_stamp = double(double(collisionData{"time_stamp"}))/1e9;
collisionInfo.object_name = string(collisionData{"object_name"});
collisionInfo.object_id = double(collisionData{"object_id"});
collisionInfo.position = struct2array(struct(collisionData{"position"}));
Expand Down
Binary file modified Matlab/Cosys-AirSim Matlab API Client.mltbx
Binary file not shown.
7 changes: 4 additions & 3 deletions Matlab/Cosys-AirSim Matlab API Client.prj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<deployment-project plugin="plugin.toolbox" plugin-version="1.0">
<configuration build-checksum="4071223196" file="D:\BigProjects\airsimUpgrade\Matlab\Cosys-AirSim Matlab API Client.prj" location="D:\BigProjects\airsimUpgrade\Matlab" name="Cosys-AirSim Matlab API Client" target="target.toolbox" target-name="Package Toolbox">
<configuration build-checksum="4071223196" file="D:\BigProjects\Cosys-AirSim-Public\Matlab\Cosys-AirSim Matlab API Client.prj" location="D:\BigProjects\Cosys-AirSim-Public\Matlab" name="Cosys-AirSim Matlab API Client" target="target.toolbox" target-name="Package Toolbox">
<param.appname>Cosys-AirSim Matlab API Client</param.appname>
<param.authnamewatermark>Wouter Jansen</param.authnamewatermark>
<param.email>[email protected]</param.email>
Expand All @@ -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.1</param.version>
<param.version>3.0.0.2</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,6 +105,7 @@ 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 All @@ -121,7 +122,7 @@ Do note that at this point not all functions have been tested and most function
<fileset.depfun.excluded />
<fileset.package />
<build-deliverables>
<file location="${PROJECT_ROOT}" name="Cosys-AirSim Matlab API Client.mltbx" optional="false">D:\BigProjects\airsimUpgrade\Matlab\Cosys-AirSim Matlab API Client.mltbx</file>
<file location="${PROJECT_ROOT}" name="Cosys-AirSim Matlab API Client.mltbx" optional="false">D:\BigProjects\Cosys-AirSim-Public\Matlab\Cosys-AirSim Matlab API Client.mltbx</file>
</build-deliverables>
<workflow />
<matlab>
Expand Down

0 comments on commit dbb8d73

Please sign in to comment.