Skip to content

Commit 2b5eb75

Browse files
committed
setting some sane defaults.
1 parent bbadaf3 commit 2b5eb75

File tree

4 files changed

+52
-8
lines changed

4 files changed

+52
-8
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ protected override void ZOOnDestroy() {
7474
ROSBridgeConnection?.UnAdvertise(ROSTopic);
7575
}
7676

77+
protected override void ZOOnValidate() {
78+
base.ZOOnValidate();
79+
if (RGBCameraSensor == null) {
80+
RGBCameraSensor = GetComponent<ZORGBCamera>();
81+
}
82+
}
83+
7784
private void Initialize() {
7885
// advertise
7986
ROSBridgeConnection.Advertise(ImageROSTopic, _rosImageMessage.MessageType);

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ protected override void ZOStart() {
5454
}
5555
}
5656

57+
protected override void ZOOnValidate() {
58+
base.ZOOnValidate();
59+
if (LIDAR2DSensor == null) {
60+
LIDAR2DSensor = GetComponent<ZOLIDAR2D>();
61+
}
62+
63+
if (ROSTopic == "") {
64+
ROSTopic = "scan";
65+
}
66+
67+
if (UpdateRateHz == 0) {
68+
UpdateRateHz = 10;
69+
}
70+
}
71+
5772
private void Initialize() {
5873
// advertise
5974
ROSBridgeConnection.Advertise(ROSTopic, _rosLaserScanMessage.MessageType);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ protected override void ZOUpdateHzSynchronized() {
5151

5252
}
5353

54+
protected override void ZOOnValidate() {
55+
base.ZOOnValidate();
56+
if (ChildFrameID == "") {
57+
ChildFrameID = Name;
58+
}
59+
if (FrameID == "") {
60+
if (transform.parent) {
61+
FrameID = transform.parent.name;
62+
}
63+
}
64+
if (UpdateRateHz == 0) {
65+
UpdateRateHz = 10;
66+
}
67+
}
5468

5569
public override string Type {
5670
get { return "ros.publisher.transform"; }

Runtime/Scripts/Sensors/RGBCamera/ZORGBCamera.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public Vector2 SensorSizeMM {
116116

117117

118118
protected override void ZOOnValidate() {
119-
119+
base.ZOOnValidate();
120120
// if camera is not assigned see if we have a camera component on this game object
121121
if (_camera == null) {
122122
_camera = this.GetComponent<Camera>();
@@ -131,6 +131,14 @@ protected override void ZOOnValidate() {
131131
#endif // UNITY_EDITOR
132132
}
133133

134+
if (UpdateRateHz == 0) {
135+
UpdateRateHz = 30;
136+
}
137+
138+
if (Name == "") {
139+
Name = gameObject.name + "_camera";
140+
}
141+
134142

135143
}
136144

@@ -155,7 +163,7 @@ protected void Initialize() {
155163
// if (IsMonochrome) {
156164
// _monoPixels8 = new byte[_width * _height];
157165
// } else { // RGB
158-
_colorPixels24 = new byte[_width * _height * 3];
166+
_colorPixels24 = new byte[_width * _height * 3];
159167
// }
160168

161169

@@ -228,12 +236,12 @@ private void DoRenderTextureUpdate() {
228236
// }
229237
// OnPublishRGBImageDelegate(this, Name, _width, _height, _monoPixels8);
230238
// } else { // RBG
231-
for (int i = 0, c3 = 0, c4 = 0; i < _width * _height; i++, c3 += 3, c4 += 4) {
232-
_colorPixels24[c3 + 0] = (byte)(rawTextureData[c4 + 1]);
233-
_colorPixels24[c3 + 1] = (byte)(rawTextureData[c4 + 2]);
234-
_colorPixels24[c3 + 2] = (byte)(rawTextureData[c4 + 3]);
235-
}
236-
OnPublishRGBImageDelegate(this, Name, _width, _height, _colorPixels24);
239+
for (int i = 0, c3 = 0, c4 = 0; i < _width * _height; i++, c3 += 3, c4 += 4) {
240+
_colorPixels24[c3 + 0] = (byte)(rawTextureData[c4 + 1]);
241+
_colorPixels24[c3 + 1] = (byte)(rawTextureData[c4 + 2]);
242+
_colorPixels24[c3 + 2] = (byte)(rawTextureData[c4 + 3]);
243+
}
244+
OnPublishRGBImageDelegate(this, Name, _width, _height, _colorPixels24);
237245

238246
// }
239247
UnityEngine.Profiling.Profiler.EndSample();

0 commit comments

Comments
 (0)