Merge commit '148ef23664f12f2907d0f1294bab9225d23275d4'
This commit is contained in:
commit
432f5b0b6e
@ -19,6 +19,17 @@ namespace RoboidControl.Unity {
|
|||||||
|
|
||||||
private void HandleUpdateEvent(RoboidControl.Participant.UpdateEvent e) {
|
private void HandleUpdateEvent(RoboidControl.Participant.UpdateEvent e) {
|
||||||
switch (e.messageId) {
|
switch (e.messageId) {
|
||||||
|
case ParticipantMsg.Id:
|
||||||
|
GameObject remoteParticipant = new GameObject("RemoteParticipant");
|
||||||
|
Participant participant = remoteParticipant.AddComponent<Participant>();
|
||||||
|
participant.coreParticipant = e.participant;
|
||||||
|
participant.coreParticipant.component = participant;
|
||||||
|
if (participant.coreParticipant is ParticipantUDP participantUDP) {
|
||||||
|
participant.ipAddress = participantUDP.ipAddress;
|
||||||
|
participant.port = participantUDP.port;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
case ThingMsg.id:
|
case ThingMsg.id:
|
||||||
HandleThingEvent(e);
|
HandleThingEvent(e);
|
||||||
break;
|
break;
|
||||||
@ -38,7 +49,7 @@ namespace RoboidControl.Unity {
|
|||||||
DifferentialDrive differentialDrive = DifferentialDrive.Create(coreDrive);
|
DifferentialDrive differentialDrive = DifferentialDrive.Create(coreDrive);
|
||||||
coreDrive.component = differentialDrive;
|
coreDrive.component = differentialDrive;
|
||||||
break;
|
break;
|
||||||
case RoboidControl.Motor coreMotor:
|
case RoboidControl.Motor coreMotor:
|
||||||
Motor wheel = Motor.Create(coreMotor);
|
Motor wheel = Motor.Create(coreMotor);
|
||||||
coreMotor.component = wheel;
|
coreMotor.component = wheel;
|
||||||
// We need to know the details (though a binary msg)
|
// We need to know the details (though a binary msg)
|
||||||
@ -49,6 +60,7 @@ namespace RoboidControl.Unity {
|
|||||||
Thing[] things = FindObjectsByType<Thing>(FindObjectsSortMode.None);
|
Thing[] things = FindObjectsByType<Thing>(FindObjectsSortMode.None);
|
||||||
// Debug.Log(things.Length);
|
// Debug.Log(things.Length);
|
||||||
Thing thing = things.FirstOrDefault(t =>
|
Thing thing = things.FirstOrDefault(t =>
|
||||||
|
t != null &&
|
||||||
t.core != null &&
|
t.core != null &&
|
||||||
t.core.owner.networkId == coreThing.owner.networkId &&
|
t.core.owner.networkId == coreThing.owner.networkId &&
|
||||||
t.core.id == coreThing.id
|
t.core.id == coreThing.id
|
||||||
|
@ -201,11 +201,11 @@ MonoBehaviour:
|
|||||||
m_GameObject: {fileID: 3377575892836316963}
|
m_GameObject: {fileID: 3377575892836316963}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: ddd5065d5e866894cbcb569c3a898ccb, type: 3}
|
m_Script: {fileID: 11500000, guid: d47256d84ddc6fc4b95bed051f75f267, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
owner: {fileID: 0}
|
owner: {fileID: 0}
|
||||||
wheelRadius: 0.025
|
wheelRadius: 0
|
||||||
--- !u!135 &3720747953092717687
|
--- !u!135 &3720747953092717687
|
||||||
SphereCollider:
|
SphereCollider:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -273,15 +273,15 @@ MonoBehaviour:
|
|||||||
m_GameObject: {fileID: 4326386140118987503}
|
m_GameObject: {fileID: 4326386140118987503}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: 5c80bc2fd1d8aa14facb1ad4b6ccf7b3, type: 3}
|
m_Script: {fileID: 11500000, guid: d93f04a0dd496484c86f546a73574309, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
owner: {fileID: 0}
|
owner: {fileID: 0}
|
||||||
leftMotor: {fileID: 0}
|
leftMotor: {fileID: 0}
|
||||||
rightMotor: {fileID: 0}
|
rightMotor: {fileID: 0}
|
||||||
leftWheel: {fileID: 6773972788910618332}
|
leftWheel: {fileID: 0}
|
||||||
rightWheel: {fileID: 7425139233737877139}
|
rightWheel: {fileID: 0}
|
||||||
casterWheel: {fileID: 894333789048616995}
|
casterWheel: {fileID: 0}
|
||||||
--- !u!54 &4118868690347991998
|
--- !u!54 &4118868690347991998
|
||||||
Rigidbody:
|
Rigidbody:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@ -435,11 +435,11 @@ MonoBehaviour:
|
|||||||
m_GameObject: {fileID: 5122915782100933114}
|
m_GameObject: {fileID: 5122915782100933114}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: ddd5065d5e866894cbcb569c3a898ccb, type: 3}
|
m_Script: {fileID: 11500000, guid: d47256d84ddc6fc4b95bed051f75f267, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
owner: {fileID: 0}
|
owner: {fileID: 0}
|
||||||
wheelRadius: 0.025
|
wheelRadius: 0
|
||||||
--- !u!135 &8150853676422519226
|
--- !u!135 &8150853676422519226
|
||||||
SphereCollider:
|
SphereCollider:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -127,20 +127,11 @@ MonoBehaviour:
|
|||||||
m_GameObject: {fileID: 6521541507066528382}
|
m_GameObject: {fileID: 6521541507066528382}
|
||||||
m_Enabled: 1
|
m_Enabled: 1
|
||||||
m_EditorHideFlags: 0
|
m_EditorHideFlags: 0
|
||||||
m_Script: {fileID: 11500000, guid: ab969221c3007d441b18dd7387cf22d4, type: 3}
|
m_Script: {fileID: 11500000, guid: 74fd22179b1a3ac4186b7dc083d24e06, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
<core>k__BackingField:
|
owner: {fileID: 0}
|
||||||
terminate: 0
|
touchedSomething: 0
|
||||||
id: 4
|
|
||||||
type: 5
|
|
||||||
nameChanged: 1
|
|
||||||
hierarchyChanged: 1
|
|
||||||
positionUpdated: 0
|
|
||||||
orientationUpdated: 0
|
|
||||||
linearVelocityUpdated: 0
|
|
||||||
angularVelocityUpdated: 0
|
|
||||||
participant: {fileID: 0}
|
|
||||||
--- !u!54 &5295705618145761524
|
--- !u!54 &5295705618145761524
|
||||||
Rigidbody:
|
Rigidbody:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
|
@ -51,7 +51,8 @@ namespace RoboidControl.Unity {
|
|||||||
gameObj.transform.parent = parent;
|
gameObj.transform.parent = parent;
|
||||||
Wheel component = gameObj.AddComponent<Wheel>();
|
Wheel component = gameObj.AddComponent<Wheel>();
|
||||||
SiteServer participant = FindAnyObjectByType<SiteServer>();
|
SiteServer participant = FindAnyObjectByType<SiteServer>();
|
||||||
RoboidControl.Thing core = participant.coreParticipant.Get(thingId);
|
RoboidControl.Participant owner = participant.coreParticipant;
|
||||||
|
RoboidControl.Thing core = owner.Get(owner.networkId, thingId);
|
||||||
if (core == null) {
|
if (core == null) {
|
||||||
core = new(participant.coreParticipant.root) {
|
core = new(participant.coreParticipant.root) {
|
||||||
id = thingId,
|
id = thingId,
|
||||||
|
@ -20,7 +20,7 @@ namespace RoboidControl {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a generic participant
|
/// Create a generic participant
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private Participant() {
|
public Participant() {
|
||||||
Thing.CreateRoot(this);
|
Thing.CreateRoot(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,8 +80,8 @@ namespace RoboidControl {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public byte networkId = 0;
|
public byte networkId = 0;
|
||||||
|
|
||||||
public bool isRemote = false;
|
public bool isRemote = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The root thing for this participant
|
/// The root thing for this participant
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -97,6 +97,7 @@ namespace RoboidControl {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="thingId">The ID of the thing</param>
|
/// <param name="thingId">The ID of the thing</param>
|
||||||
/// <returns>The thing when it is found, null in other cases.</returns>
|
/// <returns>The thing when it is found, null in other cases.</returns>
|
||||||
|
/*
|
||||||
public Thing Get(byte thingId) {
|
public Thing Get(byte thingId) {
|
||||||
Thing thing = things.Find(aThing => aThing.id == thingId);
|
Thing thing = things.Find(aThing => aThing.id == thingId);
|
||||||
//Thing thing = things.Find(aThing => Thing.IsThing(aThing, networkId, thingId));
|
//Thing thing = things.Find(aThing => Thing.IsThing(aThing, networkId, thingId));
|
||||||
@ -104,6 +105,17 @@ namespace RoboidControl {
|
|||||||
// Console.WriteLine($"Could not find thing {ipAddress}:{port}[{networkId}/{thingId}]");
|
// Console.WriteLine($"Could not find thing {ipAddress}:{port}[{networkId}/{thingId}]");
|
||||||
return thing;
|
return thing;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
public Thing Get(byte networkId, byte thingId) {
|
||||||
|
Thing thing = things.Find(aThing =>
|
||||||
|
aThing.owner.networkId == networkId &&
|
||||||
|
aThing.id == thingId
|
||||||
|
);
|
||||||
|
//Thing thing = things.Find(aThing => Thing.IsThing(aThing, networkId, thingId));
|
||||||
|
if (thing == null)
|
||||||
|
Console.WriteLine($"Could not find thing {this.networkId} [{networkId}/{thingId}]");
|
||||||
|
return thing;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add a new thing for this participant
|
/// Add a new thing for this participant
|
||||||
@ -111,14 +123,17 @@ namespace RoboidControl {
|
|||||||
/// <param name="thing">The thing to add</param>
|
/// <param name="thing">The thing to add</param>
|
||||||
/// <param name="checkId">If true, the thing.id is regenerated if it is zero
|
/// <param name="checkId">If true, the thing.id is regenerated if it is zero
|
||||||
public void Add(Thing thing, bool checkId = true) {
|
public void Add(Thing thing, bool checkId = true) {
|
||||||
|
Console.WriteLine("Add Thing to participant");
|
||||||
if (checkId && thing.id == 0) {
|
if (checkId && thing.id == 0) {
|
||||||
thing.id = (byte)(this.things.Count + 1);
|
thing.id = (byte)(this.things.Count + 1);
|
||||||
this.things.Add(thing);
|
this.things.Add(thing);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Thing foundThing = Get(thing.id);
|
Thing foundThing = Get(thing.owner.networkId, thing.id);
|
||||||
if (foundThing == null)
|
if (foundThing == null) {
|
||||||
|
Console.WriteLine($"Added Thing to participant {this.networkId} [{thing.owner.networkId}/{thing.id}]");
|
||||||
this.things.Add(thing);
|
this.things.Add(thing);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -447,11 +447,24 @@ namespace RoboidControl {
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
Console.WriteLine($"{this.name}: Process ThingMsg [{msg.networkId}/{msg.thingId}] {msg.thingType} {msg.parentId}");
|
Console.WriteLine($"{this.name}: Process ThingMsg [{msg.networkId}/{msg.thingId}] {msg.thingType} {msg.parentId}");
|
||||||
#endif
|
#endif
|
||||||
Thing thing = sender.Get(msg.thingId);
|
Participant owner = GetParticipant(msg.networkId);
|
||||||
thing ??= ProcessNewThing(sender, msg);
|
if (owner == null) {
|
||||||
|
owner = new() {
|
||||||
|
networkId = msg.networkId
|
||||||
|
};
|
||||||
|
AddParticipant(owner);
|
||||||
|
UpdateEvent e = new() {
|
||||||
|
messageId = ParticipantMsg.Id,
|
||||||
|
participant = owner
|
||||||
|
};
|
||||||
|
this.updateQueue.Enqueue(e);
|
||||||
|
Console.WriteLine("Added Participant");
|
||||||
|
}
|
||||||
|
Thing thing = owner.Get(msg.networkId, msg.thingId);
|
||||||
|
thing ??= ProcessNewThing(owner, msg);
|
||||||
|
|
||||||
if (msg.parentId != 0) {
|
if (msg.parentId != 0) {
|
||||||
thing.parent = sender.Get(msg.parentId);
|
thing.parent = owner.Get(msg.networkId, msg.parentId);
|
||||||
if (thing.parent == null)
|
if (thing.parent == null)
|
||||||
Console.WriteLine($"Could not find parent [{msg.networkId}/{msg.parentId}]");
|
Console.WriteLine($"Could not find parent [{msg.networkId}/{msg.parentId}]");
|
||||||
}
|
}
|
||||||
@ -463,11 +476,12 @@ namespace RoboidControl {
|
|||||||
ForwardMessage(sender, msg);
|
ForwardMessage(sender, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual Thing ProcessNewThing(Participant sender, ThingMsg msg) {
|
protected virtual Thing ProcessNewThing(Participant owner, ThingMsg msg) {
|
||||||
|
Console.WriteLine("--- New Thing");
|
||||||
Thing newThing = msg.thingType switch {
|
Thing newThing = msg.thingType switch {
|
||||||
Thing.Type.TouchSensor => new TouchSensor(sender.root),
|
Thing.Type.TouchSensor => new TouchSensor(owner.root),
|
||||||
Thing.Type.DifferentialDrive => new DifferentialDrive(sender.root),
|
Thing.Type.DifferentialDrive => new DifferentialDrive(owner.root),
|
||||||
_ => new Thing(sender.root)
|
_ => new Thing(owner.root)
|
||||||
};
|
};
|
||||||
newThing.id = msg.thingId;
|
newThing.id = msg.thingId;
|
||||||
newThing.type = msg.thingType;
|
newThing.type = msg.thingType;
|
||||||
@ -479,7 +493,8 @@ namespace RoboidControl {
|
|||||||
Console.WriteLine($"{this.name}: Process NameMsg [{msg.networkId}/{msg.thingId}] {msg.nameLength} {msg.name}");
|
Console.WriteLine($"{this.name}: Process NameMsg [{msg.networkId}/{msg.thingId}] {msg.nameLength} {msg.name}");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Thing thing = sender.Get(msg.thingId);
|
Participant owner = GetParticipant(msg.networkId);
|
||||||
|
Thing thing = owner.Get(msg.networkId, msg.thingId);
|
||||||
if (thing != null)
|
if (thing != null)
|
||||||
thing.name = msg.name;
|
thing.name = msg.name;
|
||||||
|
|
||||||
@ -491,7 +506,7 @@ namespace RoboidControl {
|
|||||||
Console.WriteLine($"{this.name}: Process ModelUrlMsg [{msg.networkId}/{msg.thingId}] {msg.urlLength} {msg.url}");
|
Console.WriteLine($"{this.name}: Process ModelUrlMsg [{msg.networkId}/{msg.thingId}] {msg.urlLength} {msg.url}");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Thing thing = sender.Get(msg.thingId);
|
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
||||||
if (thing != null)
|
if (thing != null)
|
||||||
thing.modelUrl = msg.url;
|
thing.modelUrl = msg.url;
|
||||||
|
|
||||||
@ -506,7 +521,7 @@ namespace RoboidControl {
|
|||||||
if (owner == null)
|
if (owner == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Thing thing = owner.Get(msg.thingId);
|
Thing thing = owner.Get(msg.networkId, msg.thingId);
|
||||||
if (thing == null)
|
if (thing == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -526,7 +541,7 @@ namespace RoboidControl {
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
// Console.WriteLine($"{this.name}: Process BinaryMsg [{msg.networkId}/{msg.thingId}] {msg.dataLength}");
|
// Console.WriteLine($"{this.name}: Process BinaryMsg [{msg.networkId}/{msg.thingId}] {msg.dataLength}");
|
||||||
#endif
|
#endif
|
||||||
Thing thing = sender.Get(msg.thingId);
|
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
||||||
thing?.ProcessBinary(msg.data);
|
thing?.ProcessBinary(msg.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,7 +556,7 @@ namespace RoboidControl {
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
Console.WriteLine($"Participant: Process Destroy Msg [{msg.networkId}/{msg.thingId}]");
|
Console.WriteLine($"Participant: Process Destroy Msg [{msg.networkId}/{msg.thingId}]");
|
||||||
#endif
|
#endif
|
||||||
Thing thing = sender.Get(msg.thingId);
|
Thing thing = sender.Get(msg.networkId, msg.thingId);
|
||||||
if (thing != null)
|
if (thing != null)
|
||||||
this.Remove(thing);
|
this.Remove(thing);
|
||||||
#if UNITY_5_3_OR_NEWER
|
#if UNITY_5_3_OR_NEWER
|
||||||
@ -554,7 +569,7 @@ namespace RoboidControl {
|
|||||||
if (participant == this || participant == sender)
|
if (participant == this || participant == sender)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Console.WriteLine($"---> {participant.networkId}");
|
// Console.WriteLine($"---> {participant.networkId}");
|
||||||
participant.Send(msg);
|
participant.Send(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,11 +138,11 @@ namespace RoboidControl {
|
|||||||
public override void ProcessBinary(byte[] data) {
|
public override void ProcessBinary(byte[] data) {
|
||||||
byte ix = 0;
|
byte ix = 0;
|
||||||
byte leftWheelId = data[ix++];
|
byte leftWheelId = data[ix++];
|
||||||
this.leftWheel = this.owner.Get(leftWheelId) as Motor;
|
this.leftWheel = this.owner.Get(this.owner.networkId, leftWheelId) as Motor;
|
||||||
this.leftWheel ??= new Motor(this) { id = leftWheelId };
|
this.leftWheel ??= new Motor(this) { id = leftWheelId };
|
||||||
|
|
||||||
byte rightWheelId = data[ix++];
|
byte rightWheelId = data[ix++];
|
||||||
this.rightWheel = this.owner.Get(rightWheelId) as Motor;
|
this.rightWheel = this.owner.Get(this.owner.networkId, rightWheelId) as Motor;
|
||||||
this.rightWheel ??= new Motor(this) { id = rightWheelId };
|
this.rightWheel ??= new Motor(this) { id = rightWheelId };
|
||||||
|
|
||||||
this._wheelRadius = LowLevelMessages.ReceiveFloat16(data, ref ix);
|
this._wheelRadius = LowLevelMessages.ReceiveFloat16(data, ref ix);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user