Skip to content

Commit c861e17

Browse files
committed
fixed monochrome stereo camera publishing
1 parent 9646c8c commit c861e17

File tree

5 files changed

+143
-12
lines changed

5 files changed

+143
-12
lines changed

Runtime/Scripts/ROS/Unity/Publishers/ZOROSStereoImagePublisher.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ protected override void ZOOnDestroy() {
107107
ROSBridgeConnection?.UnAdvertise(ROSTopic);
108108
}
109109

110+
110111
private void Initialize() {
111112
// advertise
112113
ROSBridgeConnection.Advertise(LeftImageROSTopic, _leftImageMessage.MessageType);
@@ -151,7 +152,7 @@ private void UpdateCameraSynchronization() {
151152
// send the messages
152153
ROSBridgeConnection.Publish<ImageMessage>(_leftImageMessage, LeftImageROSTopic, LeftCameraSensor.Name);
153154
ROSBridgeConnection.Publish<CameraInfoMessage>(_leftCameraInfoMessage, LeftCameraInfoROSTopic, LeftCameraSensor.Name);
154-
ROSBridgeConnection.Publish<ImageMessage>(_rightImageMessage, RightImageROSTopic, RightCameraSensor.Name);
155+
ROSBridgeConnection.Publish<ImageMessage>(_rightImageMessage, RightImageROSTopic, RightCameraSensor.Name);
155156
ROSBridgeConnection.Publish<CameraInfoMessage>(_rightCameraInfoMessage, RightCameraInfoROSTopic, RightCameraSensor.Name);
156157
}
157158
_cameraSync++;
@@ -189,7 +190,7 @@ private Task OnPublishLeftRGBImageDelegate(ZORGBCamera rgbCamera, string cameraI
189190
_leftImageMessage.data = rgbData;
190191

191192
if (LeftCameraSensor.IsMonochrome == true) {
192-
_leftImageMessage.step = (uint)width;
193+
_leftImageMessage.step = 1 * (uint)width;
193194
_leftImageMessage.encoding = "mono8";
194195
} else { // RGB
195196
_leftImageMessage.step = 1 * 3 * (uint)width;

Runtime/Scripts/Sensors/RGBCamera/ZORGBCamera.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public float FocalLengthMM {
5959
/// </summary>
6060
/// <value></value>
6161
public float FieldOfViewDegrees {
62-
get { return UnityCamera.fieldOfView; }
62+
get { return UnityCamera.fieldOfView; }
6363
}
6464

6565
/// <summary>
@@ -79,7 +79,7 @@ public bool IsMonochrome {
7979
get { return _isMonochrome; }
8080
}
8181

82-
82+
8383

8484
[Header("Render Parameters")]
8585
[SerializeField]
@@ -134,7 +134,7 @@ protected void Initialize() {
134134
} else { // RGB
135135
_colorPixels24 = new byte[_width * _height * 3];
136136
}
137-
137+
138138

139139
if (IsDebug == true) {
140140
_debugTexture = new Texture2D(_width, _height, TextureFormat.RGB24, false);
@@ -146,7 +146,7 @@ protected void Initialize() {
146146
} else {
147147
Debug.LogWarning("WARNING: NO support for native AsyncGPUReadback. Using 3rd party.");
148148
}
149-
149+
150150

151151
}
152152

@@ -210,8 +210,9 @@ private void DoRenderTextureUpdate() {
210210
_colorPixels24[c3 + 1] = (byte)(rawTextureData[c4 + 2]);
211211
_colorPixels24[c3 + 2] = (byte)(rawTextureData[c4 + 3]);
212212
}
213+
OnPublishRGBImageDelegate(this, Name, _width, _height, _colorPixels24);
214+
213215
}
214-
OnPublishRGBImageDelegate(this, Name, _width, _height, _colorPixels24);
215216
UnityEngine.Profiling.Profiler.EndSample();
216217
} else {
217218
// Debug.Log("skip");
@@ -240,7 +241,7 @@ private void OnGUI() {
240241
}
241242
}
242243

243-
#region ZOSerializationInterface
244+
#region ZOSerializationInterface
244245
public string Type {
245246
get { return "sensor.rgbcamera"; }
246247
}
@@ -304,12 +305,12 @@ public void Deserialize(ZOSimDocumentRoot documentRoot, JObject json) {
304305
UnityCamera.fieldOfView = json.ValueOrDefault("field_of_view", UnityCamera.fieldOfView);
305306
UnityCamera.depth = json.ValueOrDefault("depth", UnityCamera.depth);
306307
UnityCamera.sensorSize = json.ToVector2OrDefault("sensor_size", UnityCamera.sensorSize);
307-
UnityCamera.focalLength = json.ValueOrDefault("focal_length", UnityCamera.focalLength);
308+
UnityCamera.focalLength = json.ValueOrDefault("focal_length", UnityCamera.focalLength);
308309

309310
Initialize();
310311

311312
}
312-
#endregion
313+
#endregion
313314

314315

315316

Samples~/ZeroSimSamples/Scenes/ROSMonochromeImagePublish_test.unity

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,11 @@ PrefabInstance:
815815
m_Modification:
816816
m_TransformParent: {fileID: 0}
817817
m_Modifications:
818+
- target: {fileID: 891913994308376442, guid: a30483e804eeb93d982df3c64361a8ff,
819+
type: 3}
820+
propertyPath: _debug
821+
value: 0
822+
objectReference: {fileID: 0}
818823
- target: {fileID: 891913994308376443, guid: a30483e804eeb93d982df3c64361a8ff,
819824
type: 3}
820825
propertyPath: m_RootOrder

Samples~/ZeroSimSamples/Scenes/ROSStereoCamera_test.unity

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,125 @@ Transform:
291291
m_Father: {fileID: 1868798746}
292292
m_RootOrder: 0
293293
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
294+
--- !u!1001 &246724120
295+
PrefabInstance:
296+
m_ObjectHideFlags: 0
297+
serializedVersion: 2
298+
m_Modification:
299+
m_TransformParent: {fileID: 0}
300+
m_Modifications:
301+
- target: {fileID: 270870987501896691, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
302+
type: 3}
303+
propertyPath: m_Name
304+
value: Left_MonoCamera
305+
objectReference: {fileID: 0}
306+
- target: {fileID: 270870987501896693, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
307+
type: 3}
308+
propertyPath: _debug
309+
value: 0
310+
objectReference: {fileID: 0}
311+
- target: {fileID: 270870987501896693, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
312+
type: 3}
313+
propertyPath: _isMonochrome
314+
value: 1
315+
objectReference: {fileID: 0}
316+
- target: {fileID: 270870987501896693, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
317+
type: 3}
318+
propertyPath: _postProcessMaterial
319+
value:
320+
objectReference: {fileID: 2100000, guid: 2e597e5b56537481a894fb4316ff9bff, type: 2}
321+
- target: {fileID: 270870987501896694, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
322+
type: 3}
323+
propertyPath: m_Enabled
324+
value: 0
325+
objectReference: {fileID: 0}
326+
- target: {fileID: 1530428453377767332, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
327+
type: 3}
328+
propertyPath: m_Name
329+
value: ROSMonoStereoCamera
330+
objectReference: {fileID: 0}
331+
- target: {fileID: 1530428453377767332, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
332+
type: 3}
333+
propertyPath: m_IsActive
334+
value: 1
335+
objectReference: {fileID: 0}
336+
- target: {fileID: 1530428453377767333, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
337+
type: 3}
338+
propertyPath: m_RootOrder
339+
value: 5
340+
objectReference: {fileID: 0}
341+
- target: {fileID: 1530428453377767333, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
342+
type: 3}
343+
propertyPath: m_LocalPosition.x
344+
value: 0
345+
objectReference: {fileID: 0}
346+
- target: {fileID: 1530428453377767333, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
347+
type: 3}
348+
propertyPath: m_LocalPosition.y
349+
value: 2.7600002
350+
objectReference: {fileID: 0}
351+
- target: {fileID: 1530428453377767333, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
352+
type: 3}
353+
propertyPath: m_LocalPosition.z
354+
value: 1.4099998
355+
objectReference: {fileID: 0}
356+
- target: {fileID: 1530428453377767333, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
357+
type: 3}
358+
propertyPath: m_LocalRotation.w
359+
value: -0.7071068
360+
objectReference: {fileID: 0}
361+
- target: {fileID: 1530428453377767333, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
362+
type: 3}
363+
propertyPath: m_LocalRotation.x
364+
value: 0
365+
objectReference: {fileID: 0}
366+
- target: {fileID: 1530428453377767333, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
367+
type: 3}
368+
propertyPath: m_LocalRotation.y
369+
value: 0.7071068
370+
objectReference: {fileID: 0}
371+
- target: {fileID: 1530428453377767333, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
372+
type: 3}
373+
propertyPath: m_LocalRotation.z
374+
value: -0
375+
objectReference: {fileID: 0}
376+
- target: {fileID: 1530428453377767333, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
377+
type: 3}
378+
propertyPath: m_LocalEulerAnglesHint.x
379+
value: 0
380+
objectReference: {fileID: 0}
381+
- target: {fileID: 1530428453377767333, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
382+
type: 3}
383+
propertyPath: m_LocalEulerAnglesHint.y
384+
value: 270
385+
objectReference: {fileID: 0}
386+
- target: {fileID: 1530428453377767333, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
387+
type: 3}
388+
propertyPath: m_LocalEulerAnglesHint.z
389+
value: 0
390+
objectReference: {fileID: 0}
391+
- target: {fileID: 1759282756972031257, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
392+
type: 3}
393+
propertyPath: _isMonochrome
394+
value: 1
395+
objectReference: {fileID: 0}
396+
- target: {fileID: 1759282756972031257, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
397+
type: 3}
398+
propertyPath: _postProcessMaterial
399+
value:
400+
objectReference: {fileID: 2100000, guid: 2e597e5b56537481a894fb4316ff9bff, type: 2}
401+
- target: {fileID: 1759282756972031258, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
402+
type: 3}
403+
propertyPath: m_Enabled
404+
value: 0
405+
objectReference: {fileID: 0}
406+
- target: {fileID: 1759282756972031263, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
407+
type: 3}
408+
propertyPath: m_Name
409+
value: Right_MonoCamera
410+
objectReference: {fileID: 0}
411+
m_RemovedComponents: []
412+
m_SourcePrefab: {fileID: 100100000, guid: 8f56f9469e91f25c8bbc5230cc29a09a, type: 3}
294413
--- !u!1 &445573325
295414
GameObject:
296415
m_ObjectHideFlags: 0
@@ -818,7 +937,12 @@ PrefabInstance:
818937
- target: {fileID: 1530428453377767332, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
819938
type: 3}
820939
propertyPath: m_Name
821-
value: ROSStereoCamera
940+
value: ROSRGBStereoCamera
941+
objectReference: {fileID: 0}
942+
- target: {fileID: 1530428453377767332, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
943+
type: 3}
944+
propertyPath: m_IsActive
945+
value: 0
822946
objectReference: {fileID: 0}
823947
- target: {fileID: 1530428453377767333, guid: 8f56f9469e91f25c8bbc5230cc29a09a,
824948
type: 3}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.fsstudio.zerosim",
3-
"version": "0.0.12",
3+
"version": "0.0.13",
44
"displayName": "ZeroSim",
55
"description": "ZeroSim ROS robotic simulator in Unity.",
66
"unity": "2020.1",

0 commit comments

Comments
 (0)