Compare commits

...

3 Commits

4 changed files with 30 additions and 52 deletions

View File

@ -132,8 +132,10 @@ namespace RoboidControl.Unity {
string extension = core.modelUrl[core.modelUrl.LastIndexOf(".")..]; string extension = core.modelUrl[core.modelUrl.LastIndexOf(".")..];
if (extension == ".jpg" || extension == ".png") if (extension == ".jpg" || extension == ".png")
StartCoroutine(LoadJPG()); StartCoroutine(LoadJPG());
#if GLTF
else if (extension == ".gltf" || extension == ".glb") else if (extension == ".gltf" || extension == ".glb")
ProcessGltfModel(core); ProcessGltfModel(core);
#endif
break; break;
case PoseMsg.Id: case PoseMsg.Id:
Debug.Log($"{this.core.id} Handle Pose"); Debug.Log($"{this.core.id} Handle Pose");
@ -177,9 +179,9 @@ namespace RoboidControl.Unity {
} }
} }
#if GLTF
bool loadingModel = false; bool loadingModel = false;
private async void ProcessGltfModel(RoboidControl.Thing coreThing) { private async void ProcessGltfModel(RoboidControl.Thing coreThing) {
#if GLTF
if (!loadingModel) { if (!loadingModel) {
loadingModel = true; loadingModel = true;
@ -200,21 +202,6 @@ namespace RoboidControl.Unity {
await gltfImport.InstantiateMainSceneAsync(parentTransform); await gltfImport.InstantiateMainSceneAsync(parentTransform);
SkinnedMeshRenderer[] meshRenderers = parentTransform.GetComponentsInChildren<SkinnedMeshRenderer>(); SkinnedMeshRenderer[] meshRenderers = parentTransform.GetComponentsInChildren<SkinnedMeshRenderer>();
#if pHUMANOID4
// if (parentThing.objectType == 7) {
// HumanoidControl hc = parentThing.gameObject.GetComponent<HumanoidControl>();
// if (hc == null)
// hc = parentThing.gameObject.AddComponent<HumanoidControl>();
// foreach (SkinnedMeshRenderer meshRenderer in meshRenderers) {
// if (meshRenderer.rootBone != null) {
// Debug.Log("Found a skinned mesh with bones");
// hc.RetrieveBonesFrom(meshRenderer.rootBone);
// break;
// }
// }
// }
#endif
parentTransform.localScale = Vector3.one; parentTransform.localScale = Vector3.one;
if (meshRenderers.Length > 0) { if (meshRenderers.Length > 0) {
foreach (SkinnedMeshRenderer meshRenderer in meshRenderers) { foreach (SkinnedMeshRenderer meshRenderer in meshRenderers) {
@ -234,8 +221,8 @@ namespace RoboidControl.Unity {
} }
} }
loadingModel = true; loadingModel = true;
#endif
} }
#endif
private void ScanForThings(Transform rootTransform) { private void ScanForThings(Transform rootTransform) {
RoboidControl.Thing[] thingArray = this.core.owner.things.ToArray(); RoboidControl.Thing[] thingArray = this.core.owner.things.ToArray();

View File

@ -45,18 +45,15 @@ namespace RoboidControl {
public static void SendQuat32(byte[] buffer, ref byte ix, SwingTwist s) { public static void SendQuat32(byte[] buffer, ref byte ix, SwingTwist s) {
Quat32 q32 = Quat32.FromSwingTwist(s); Quat32 q32 = Quat32.FromSwingTwist(s);
System.Console.Write($"send q32: {q32.x} {q32.y} {q32.z} {q32.w}");
SendQuat32(buffer, ref ix, q32); SendQuat32(buffer, ref ix, q32);
} }
public static void SendSwingTwist(byte[] buffer, ref byte ix, SwingTwist r) { public static void SendSwingTwist(byte[] buffer, ref byte ix, SwingTwist r) {
System.Console.Write($"send st: {r.swing.horizontal} {r.swing.vertical} {r.twist}");
SendAngle8(buffer, ref ix, r.swing.horizontal); SendAngle8(buffer, ref ix, r.swing.horizontal);
SendAngle8(buffer, ref ix, r.swing.vertical); SendAngle8(buffer, ref ix, r.swing.vertical);
SendAngle8(buffer, ref ix, r.twist); SendAngle8(buffer, ref ix, r.twist);
} }
public static SwingTwist ReceiveSwingTwist(byte[] data, ref byte ix) { public static SwingTwist ReceiveSwingTwist(byte[] data, ref byte ix) {
float horizontal = ReceiveAngle8(data, ref ix); float horizontal = ReceiveAngle8(data, ref ix);
float vertical = ReceiveAngle8(data, ref ix); float vertical = ReceiveAngle8(data, ref ix);

View File

@ -160,7 +160,6 @@ namespace RoboidControl {
if (this.remoteSite == null) if (this.remoteSite == null)
this.Publish(msg); this.Publish(msg);
else else
//this.Send(this.remoteSite, msg);
this.remoteSite.Send(msg); this.remoteSite.Send(msg);
this.nextPublishMe = currentTimeMS + this.publishIntervalMS; this.nextPublishMe = currentTimeMS + this.publishIntervalMS;
@ -242,12 +241,6 @@ namespace RoboidControl {
#region Send #region Send
public void SendThingInfo(Participant owner, Thing thing) { public void SendThingInfo(Participant owner, Thing thing) {
// Console.WriteLine("Send thing info");
// this.Send(owner, new ThingMsg(this.networkId, thing));
// this.Send(owner, new NameMsg(this.networkId, thing));
// this.Send(owner, new ModelUrlMsg(this.networkId, thing));
// this.Send(owner, new PoseMsg(this.networkId, thing));
// this.Send(owner, new BinaryMsg(this.networkId, thing));
owner.Send(new ThingMsg(this.networkId, thing)); owner.Send(new ThingMsg(this.networkId, thing));
owner.Send(new NameMsg(this.networkId, thing)); owner.Send(new NameMsg(this.networkId, thing));
owner.Send(new ModelUrlMsg(this.networkId, thing)); owner.Send(new ModelUrlMsg(this.networkId, thing));
@ -264,23 +257,12 @@ namespace RoboidControl {
this.Publish(new BinaryMsg(this.networkId, thing)); this.Publish(new BinaryMsg(this.networkId, thing));
} }
// public bool Send(Participant owner, IMessage msg) {
// int bufferSize = msg.Serialize(ref this.buffer);
// if (bufferSize <= 0)
// return true;
// IPEndPoint participantEndpoint = new IPEndPoint(IPAddress.Parse(owner.ipAddress), owner.port);
// // Console.WriteLine($"msg to {participantEndpoint.Address.ToString()} {participantEndpoint.Port}");
// this.udpClient?.Send(this.buffer, bufferSize, participantEndpoint);
// return true;
// }
public bool Publish(IMessage msg) { public bool Publish(IMessage msg) {
int bufferSize = msg.Serialize(ref this.buffer); int bufferSize = msg.Serialize(ref this.buffer);
if (bufferSize <= 0) if (bufferSize <= 0)
return true; return true;
// Console.WriteLine($"publish to {broadcastIpAddress.ToString()} {this.port}"); Console.WriteLine($"publish to {broadcastIpAddress.ToString()} {this.port}");
this.udpClient?.Send(this.buffer, bufferSize, this.broadcastIpAddress, this.port); this.udpClient?.Send(this.buffer, bufferSize, this.broadcastIpAddress, this.port);
return true; return true;
} }
@ -291,15 +273,26 @@ namespace RoboidControl {
protected void ReceiveUDP(IAsyncResult result) { protected void ReceiveUDP(IAsyncResult result) {
try { try {
// UnityEngine.Debug.Log("received"); if (this.udpClient == null)
if (this.udpClient == null) // || this.endPoint == null)
return; return;
byte[] data = this.udpClient.EndReceive(result, ref endPoint); byte[] data = { };
try {
data = this.udpClient.EndReceive(result, ref endPoint);
}
catch (SocketException e) {
if (e.ErrorCode != 10054)
throw;
#if DEBUG
else
Console.WriteLine($"No receiver found for the previously sent UDP packet");
#endif
}
// This does not yet take multi-packet messages into account! // This does not yet take multi-packet messages into account!
if (endPoint == null) if (endPoint == null)
return; return;
if (data.Length > 0) {
// We can receive our own publish (broadcast) packages. How do we recognize them???? // We can receive our own publish (broadcast) packages. How do we recognize them????
// It is hard to determine our source port // It is hard to determine our source port
string ipAddress = endPoint.Address.ToString(); string ipAddress = endPoint.Address.ToString();
@ -309,6 +302,7 @@ namespace RoboidControl {
ReceiveData(data, remoteParticipant); ReceiveData(data, remoteParticipant);
} }
}
udpClient.BeginReceive(new AsyncCallback(callbackResult => ReceiveUDP(callbackResult)), null); udpClient.BeginReceive(new AsyncCallback(callbackResult => ReceiveUDP(callbackResult)), null);
} }

View File

@ -50,7 +50,7 @@ namespace RoboidControl {
float pidP = 0.1F; float pidP = 0.1F;
float pidD = 0.0F; float pidD = 0.0F;
float pidI = 0.0F; //float pidI = 0.0F;
public override void Update(ulong currentTimeMs, bool recurse = false) { public override void Update(ulong currentTimeMs, bool recurse = false) {
float actualSpeed = this.encoder.angularSpeed; float actualSpeed = this.encoder.angularSpeed;