Skip to content

Commit

Permalink
Code refactoring for Devices
Browse files Browse the repository at this point in the history
- Device
- Contact
- Sonar
  • Loading branch information
hyunseok-yang committed Aug 14, 2020
1 parent 1376bb8 commit 2b25d79
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
8 changes: 1 addition & 7 deletions Assets/Scripts/Devices/Contact.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,7 @@ protected override void OnStart()

protected override IEnumerator OnVisualize()
{
var waitForEndOfFrame = new WaitForEndOfFrame();
var waitForSeconds = new WaitForSeconds(UpdatePeriod);

while (true)
{
yield return waitForSeconds;
}
yield return null;
}

protected override void InitializeMessages()
Expand Down
9 changes: 4 additions & 5 deletions Assets/Scripts/Devices/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@

public abstract class Device : MonoBehaviour
{
private const int maxQueue = 3;

public string deviceName = string.Empty;

private const int maxQueue = 3;
private BlockingCollection<MemoryStream> memoryStreamOutboundQueue;
private BlockingCollection<MemoryStream> memoryStreamOutboundQueue = new BlockingCollection<MemoryStream>(maxQueue);

private MemoryStream memoryStream = null;
private MemoryStream memoryStream = new MemoryStream();

protected const float SEC2MSEC = 1000.0f;

Expand Down Expand Up @@ -60,8 +61,6 @@ public bool EnableVisualize

void Awake()
{
memoryStreamOutboundQueue = new BlockingCollection<MemoryStream>(maxQueue);
memoryStream = new MemoryStream();
ResetDataStream();

OnAwake();
Expand Down
12 changes: 6 additions & 6 deletions Assets/Scripts/Devices/Sonar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ protected override void OnAwake()
deviceName = name;
sonarLink = transform.parent;
waitingPeriodRatio = 0.95f;

var sonar = sonarStamped.Sonar;
sonar.Frame = deviceName;
sonar.Radius = radius;
sonar.RangeMin = rangeMin;
sonar.RangeMax = rangeMax;
}

protected override void OnStart()
Expand Down Expand Up @@ -109,12 +115,6 @@ protected override void InitializeMessages()
sonarStamped.Sonar.WorldPose.Position = new messages.Vector3d();
sonarStamped.Sonar.WorldPose.Orientation = new messages.Quaternion();
sonarStamped.Sonar.Contact = new messages.Vector3d();

var sonar = sonarStamped.Sonar;
sonar.Frame = deviceName;
sonar.Radius = radius;
sonar.RangeMin = rangeMin;
sonar.RangeMax = rangeMax;
}

protected override IEnumerator MainDeviceWorker()
Expand Down

0 comments on commit 2b25d79

Please sign in to comment.