Skip to content

Commit

Permalink
Merge pull request #11 from lge-ros2/develop
Browse files Browse the repository at this point in the history
Merge 'develop' branch into 'master
  • Loading branch information
hyunseok-yang authored Jun 29, 2020
2 parents b01bc5d + 887e42a commit b9fdf85
Show file tree
Hide file tree
Showing 56 changed files with 1,464 additions and 572 deletions.
18 changes: 18 additions & 0 deletions Assets/Scenes/MainScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ GameObject:
- component: {fileID: 249819587}
- component: {fileID: 249819588}
- component: {fileID: 249819590}
- component: {fileID: 249819592}
m_Layer: 0
m_Name: Core
m_TagString: Untagged
Expand Down Expand Up @@ -795,6 +796,23 @@ MonoBehaviour:
m_EditorClassIdentifier:
defaultWebSocketAddress: 127.0.0.1
defaultWebSocketPort: 8080
--- !u!114 &249819592
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 249819585}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9e1faa6078eea04e880e038777287f24, type: 3}
m_Name:
m_EditorClassIdentifier:
surfaceType: 0
latitudeReference: 0
longitudeReference: 0
elevationReference: 0
headingOffset: 0
--- !u!1 &333360875
GameObject:
m_ObjectHideFlags: 0
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/Connection/DeviceTransporter.publisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protected bool InitializePublisher(in ushort targetPort)

if (publisherSocket != null)
{
publisherSocket.Options.TcpKeepalive = true;
publisherSocket.Options.SendHighWatermark = highwatermark;
publisherSocket.Options.Linger = new TimeSpan(0);
publisherSocket.Bind(GetAddress(targetPort));
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/Connection/DeviceTransporter.request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected bool InitializeRequester(in ushort targetPort)

if (requestSocket != null)
{
requestSocket.Options.TcpKeepalive = true;
requestSocket.Bind(GetAddress(targetPort));
// Debug.Log("Requester socket connecting... " + targetPort);
initialized = StoreTagIntoDataToSend(hashValueForSend);
Expand Down
1 change: 1 addition & 0 deletions Assets/Scripts/Connection/DeviceTransporter.response.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected bool InitializeResponsor(in ushort targetPort)

if (responseSocket != null)
{
responseSocket.Options.TcpKeepalive = true;
responseSocket.Bind(GetAddress(targetPort));
// Debug.Log("Responsor socket connecting... " + targetPort);
initialized = StoreTagIntoDataToSend(hashValueForReceive);
Expand Down
10 changes: 7 additions & 3 deletions Assets/Scripts/Connection/DeviceTransporter.subscriber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ protected bool InitializeSubscriber(in ushort targetPort)

if (subscriberSocket != null)
{
subscriberSocket.Options.SendHighWatermark = highwatermark;
subscriberSocket.Options.TcpKeepalive = true;
subscriberSocket.Options.ReceiveHighWatermark = highwatermark;
subscriberSocket.Options.Linger = new TimeSpan(0);
subscriberSocket.Bind(GetAddress(targetPort));
// Debug.Log("Subscriber socket connecting... " + targetPort);

if (hashValueForReceive != null)
{
subscriberSocket.Subscribe(hashValueForReceive);
}

subscriberSocket.Bind(GetAddress(targetPort));
// Debug.Log("Subscriber socket connecting... " + targetPort);

initialized = true;
}
Expand Down
16 changes: 8 additions & 8 deletions Assets/Scripts/CustomPlugins/CustomPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class CustomPlugin : DeviceTransporter

private XmlNode pluginData;

private BridgePortManager devicePortManager = null;
private BridgePortManager bridgePortManager = null;

private List<Thread> threadList = null;

Expand All @@ -29,9 +29,7 @@ protected CustomPlugin()

protected abstract void OnAwake();
protected abstract void OnStart();
protected virtual void OnReset() {

}
protected virtual void OnReset() { }

void OnDestroy()
{
Expand All @@ -57,6 +55,7 @@ protected bool AddThread(in ThreadStart function)

return false;
}

private void StartThreads()
{
if (threadList != null)
Expand All @@ -68,6 +67,7 @@ private void StartThreads()
}
}
}

public void SetPluginData(XmlNode node)
{
pluginData = node.SelectSingleNode(".");
Expand Down Expand Up @@ -173,7 +173,7 @@ protected void PrintPluginData()

protected bool PrepareDevice(in string hashKey, out ushort port, out ulong hash)
{
port = devicePortManager.AllocateSensorPort(hashKey);
port = bridgePortManager.AllocateSensorPort(hashKey);
hash = DeviceHelper.GetStringHashCode(hashKey);

if (port == 0)
Expand Down Expand Up @@ -250,10 +250,10 @@ void Awake()
}
else
{
devicePortManager = coreObject.GetComponent<BridgePortManager>();
if (devicePortManager == null)
bridgePortManager = coreObject.GetComponent<BridgePortManager>();
if (bridgePortManager == null)
{
Debug.LogError("Failed to get 'devicePortManager'!!!!");
Debug.LogError("Failed to get 'bridgePortManager'!!!!");
}

if (string.IsNullOrEmpty(modelName))
Expand Down
51 changes: 51 additions & 0 deletions Assets/Scripts/CustomPlugins/GpsPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2020 LG Electronics Inc.
*
* SPDX-License-Identifier: MIT
*/

using UnityEngine;
using Stopwatch = System.Diagnostics.Stopwatch;

public class GpsPlugin : CustomPlugin
{
public string partName = string.Empty;

private SensorDevices.GPS gps = null;

protected override void OnAwake()
{
partName = DeviceHelper.GetPartName(gameObject);

string hashKey = MakeHashKey(partName);
if (!RegisterTxDevice(hashKey))
{
Debug.LogError("Failed to register for GpsPlugin - " + hashKey);
}
}

protected override void OnStart()
{
gps = gameObject.GetComponent<SensorDevices.GPS>();

AddThread(Sender);
}

private void Sender()
{
Stopwatch sw = new Stopwatch();
while (true)
{
if (gps == null)
{
continue;
}

var datastreamToSend = gps.PopData();
sw.Restart();
Publish(datastreamToSend);
sw.Stop();
gps.SetTransportTime((float)sw.Elapsed.TotalSeconds);
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/CustomPlugins/GpsPlugin.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 5 additions & 11 deletions Assets/Scripts/Devices/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ public partial class Camera : Device

public bool runningDeviceWork = true;

protected Camera()
{
// Initialize Gazebo Message
imageStamped = new gazebo.msgs.ImageStamped();
imageStamped.Time = new gazebo.msgs.Time();
imageStamped.Image = new gazebo.msgs.Image();
}

void Awake()
{
cam = gameObject.AddComponent<UnityEngine.Camera>();
Expand All @@ -45,8 +37,6 @@ void Awake()

protected override void OnStart()
{
InitializeMessages();

if (cam)
{
cam.transform.Rotate(Vector3.up, 90.0000000000f);
Expand All @@ -56,8 +46,12 @@ protected override void OnStart()
}
}

private void InitializeMessages()
protected override void InitializeMessages()
{
imageStamped = new gazebo.msgs.ImageStamped();
imageStamped.Time = new gazebo.msgs.Time();
imageStamped.Image = new gazebo.msgs.Image();

var image = imageStamped.Image;
image.Width = (uint)parameters.image_width;
image.Height = (uint)parameters.image_height;
Expand Down
14 changes: 7 additions & 7 deletions Assets/Scripts/Devices/Clock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ public class Clock : Device
private gazebo.msgs.Time simTime = null;
private gazebo.msgs.Time realTime = null;

Clock()
protected override void OnStart()
{
deviceName = "Unity Clock";
SetUpdateRate(updateRate);
}

protected override void InitializeMessages()
{
simTime = new gazebo.msgs.Time();
realTime = new gazebo.msgs.Time();
Expand All @@ -40,12 +46,6 @@ public class Clock : Device
timeInfo.Childrens.Add(realTimeParam);
}

protected override void OnStart()
{
deviceName = "Unity Clock";
SetUpdateRate(updateRate);
}

protected override IEnumerator MainDeviceWorker()
{
var waitForSeconds = new WaitForSeconds(UpdatePeriod);
Expand Down
2 changes: 0 additions & 2 deletions Assets/Scripts/Devices/DepthCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ void OnRenderImage(RenderTexture source, RenderTexture destination)
protected override void OnStart()
{
SetupDepthCamera();

base.OnStart();
}

private void SetupDepthCamera()
Expand Down
10 changes: 10 additions & 0 deletions Assets/Scripts/Devices/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public bool EnableVisualize

void Start()
{
InitializeMessages();

OnStart();

StartCoroutine(MainDeviceWorker());

if (EnableVisualize)
Expand Down Expand Up @@ -188,8 +191,15 @@ protected T GetMessageData<T>()
}
}

protected virtual void InitializeMessages()
{
// do nothing
Debug.Log("Nothing to initialize message: " + name);
}

protected virtual void GenerateMessage()
{
// do nothing
Debug.Log("Need to implement!!");
}

Expand Down
Loading

0 comments on commit b9fdf85

Please sign in to comment.