Re-organised the repo

This commit is contained in:
Pascal Serrarens 2025-03-07 14:32:18 +01:00
parent f1a550e7f3
commit 6a443e111c
46 changed files with 340 additions and 228 deletions

6
.gitignore vendored
View File

@ -1,7 +1,5 @@
DoxyGen/DoxyWarnLogfile.txt
.vscode/settings.json
test/bin
test/obj
/bin
/obj
**bin
**obj
**.meta

14
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "C#: BB2B Debug",
"type": "dotnet",
"request": "launch",
"projectPath": "${workspaceFolder}/Examples/BB2B/BB2B.csproj"
}
]
}

11
Examples/BB2B/BB2B.csproj Normal file
View File

@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\RoboidControl.csproj" />
</ItemGroup>
</Project>

35
Examples/BB2B/Program.cs Normal file
View File

@ -0,0 +1,35 @@
using System;
using System.Diagnostics;
using System.Threading;
using RoboidControl;
class BB2B {
static void Main() {
// The robot's propulsion is a differential drive
DifferentialDrive bb2b = new DifferentialDrive();
// Is has a touch sensor at the front left of the roboid
TouchSensor touchLeft = new TouchSensor(bb2b);
// and other one on the right
TouchSensor touchRight = new TouchSensor(bb2b);
// Do forever:
while (true) {
Console.Write("A");
// The left wheel turns forward when nothing is touched on the right side
// and turn backward when the roboid hits something on the right
float leftWheelSpeed = (touchRight.touchedSomething) ? -600.0f : 600.0f;
// The right wheel does the same, but instead is controlled by
// touches on the left side
float rightWheelSpeed = (touchLeft.touchedSomething) ? -600.0f : 600.0f;
// When both sides are touching something, both wheels will turn backward
// and the roboid will move backwards
bb2b.SetWheelVelocity(leftWheelSpeed, rightWheelSpeed);
// Update the roboid state
bb2b.Update(true);
// and sleep for 100ms
Thread.Sleep(100);
}
}
}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: ee99a6777ed47f743be8068c6ede98c8

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 9975e4702de32624e8d3deaf84669f2f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 96aa3cf18eaeb574d9265704d68000da
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 33f05ee51ff6f7042b3e22723bcfc4f5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 003a6ec763b101642b0589486f087aef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

39
RoboidControl.sln Normal file
View File

@ -0,0 +1,39 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{B65BB41E-5A93-46FC-BA68-B865F50D57BD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{D6086F71-404B-4D18-BBE9-45947ED33DB2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BB2B", "Examples\BB2B\BB2B.csproj", "{488F28B2-A2CC-4E32-8D3B-7DB4EB1485F9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RoboidControl", "src\RoboidControl.csproj", "{72BFCD03-FA78-4D0B-8B36-32301D60D6DD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B65BB41E-5A93-46FC-BA68-B865F50D57BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B65BB41E-5A93-46FC-BA68-B865F50D57BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B65BB41E-5A93-46FC-BA68-B865F50D57BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B65BB41E-5A93-46FC-BA68-B865F50D57BD}.Release|Any CPU.Build.0 = Release|Any CPU
{488F28B2-A2CC-4E32-8D3B-7DB4EB1485F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{488F28B2-A2CC-4E32-8D3B-7DB4EB1485F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{488F28B2-A2CC-4E32-8D3B-7DB4EB1485F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{488F28B2-A2CC-4E32-8D3B-7DB4EB1485F9}.Release|Any CPU.Build.0 = Release|Any CPU
{72BFCD03-FA78-4D0B-8B36-32301D60D6DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72BFCD03-FA78-4D0B-8B36-32301D60D6DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72BFCD03-FA78-4D0B-8B36-32301D60D6DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72BFCD03-FA78-4D0B-8B36-32301D60D6DD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{488F28B2-A2CC-4E32-8D3B-7DB4EB1485F9} = {D6086F71-404B-4D18-BBE9-45947ED33DB2}
EndGlobalSection
EndGlobal

View File

@ -9,7 +9,7 @@ namespace RoboidControl {
/// <summary>
/// A participant is used for communcation between things
/// </summary>
public class Participant : RemoteParticipant {
public class LocalParticipant : Participant {
public byte[] buffer = new byte[1024];
public ulong publishInterval = 3000; // = 3 seconds
@ -26,7 +26,7 @@ namespace RoboidControl {
/// <summary>
/// Create a porticiapnt
/// </summary>
public Participant() {
public LocalParticipant() {
//senders.Add(this);
}
@ -34,16 +34,16 @@ namespace RoboidControl {
/// Create a participant with the give UDP port
/// </summary>
/// <param name="port">The port number on which to communicate</param>
// public Participant(int port) : this() {
// this.port = port;
// }
public LocalParticipant(int port) : this() {
this.port = port;
}
/// <summary>
/// Create a new participant for a site at the given address and port
/// </summary>
/// <param name="ipAddress">The ip address of the site server</param>
/// <param name="port">The port number of the site server</param>
public Participant(string ipAddress = "0.0.0.0", int port = 7681) : this() {
public LocalParticipant(string ipAddress = "0.0.0.0", int port = 7681) : this() {
this.ipAddress = ipAddress;
this.port = port;
@ -61,35 +61,42 @@ namespace RoboidControl {
/// </summary>
/// <param name="udpClient">UDP client to use for communication</param>
/// <param name="port">The port number on which to communicate</param>
public Participant(UdpClient udpClient, int port) : this() {
public LocalParticipant(UdpClient udpClient, int port) : this() {
this.udpClient = udpClient;
this.port = port;
}
public List<RemoteParticipant> owners = new List<RemoteParticipant>();
private static LocalParticipant isolatedParticipant = null;
public static LocalParticipant Isolated() {
if (isolatedParticipant == null)
isolatedParticipant = new LocalParticipant(0);
return isolatedParticipant;
}
public RemoteParticipant GetParticipant(string ipAddress, int port) {
public List<Participant> owners = new List<Participant>();
public Participant GetParticipant(string ipAddress, int port) {
//Console.WriteLine($"Get Participant {ipAddress}:{port}");
foreach (RemoteParticipant sender in owners) {
foreach (Participant sender in owners) {
if (sender.ipAddress == ipAddress && sender.port == port)
return sender;
}
return null;
}
public RemoteParticipant AddParticipant(string ipAddress, int port) {
public Participant AddParticipant(string ipAddress, int port) {
Console.WriteLine($"New Participant {ipAddress}:{port}");
RemoteParticipant participant = new(ipAddress, port) {
Participant participant = new(ipAddress, port) {
networkId = (byte)(this.owners.Count + 1)
};
owners.Add(participant);
return participant;
}
protected readonly Dictionary<byte, Func<RemoteParticipant, byte, byte, Thing>> thingMsgProcessors = new();
protected readonly Dictionary<byte, Func<Participant, byte, byte, Thing>> thingMsgProcessors = new();
public delegate Thing ThingConstructor(RemoteParticipant sender, byte networkId, byte thingId);
public delegate Thing ThingConstructor(Participant sender, byte networkId, byte thingId);
public void Register(byte thingType, ThingConstructor constr) {
thingMsgProcessors[thingType] = new Func<RemoteParticipant, byte, byte, Thing>(constr);
thingMsgProcessors[thingType] = new Func<Participant, byte, byte, Thing>(constr);
}
public void Register<ThingClass>(Thing.Type thingType) where ThingClass : Thing {
@ -118,7 +125,7 @@ namespace RoboidControl {
// We can receive our own publish (broadcast) packages. How do we recognize them????
// It is hard to determine our source port
string ipAddress = this.endPoint.Address.ToString();
RemoteParticipant remoteParticipant = GetParticipant(ipAddress, this.endPoint.Port);
Participant remoteParticipant = GetParticipant(ipAddress, this.endPoint.Port);
remoteParticipant ??= AddParticipant(ipAddress, this.endPoint.Port);
ReceiveData(data, remoteParticipant);
@ -161,7 +168,7 @@ namespace RoboidControl {
#region Send
public void SendThingInfo(RemoteParticipant remoteParticipant, Thing thing) {
public void SendThingInfo(Participant remoteParticipant, Thing thing) {
Console.WriteLine("Send thing info");
this.Send(remoteParticipant, new ThingMsg(this.networkId, thing));
this.Send(remoteParticipant, new NameMsg(this.networkId, thing));
@ -169,7 +176,7 @@ namespace RoboidControl {
this.Send(remoteParticipant, new BinaryMsg(this.networkId, thing));
}
public bool Send(RemoteParticipant remoteParticipant, IMessage msg) {
public bool Send(Participant remoteParticipant, IMessage msg) {
int bufferSize = msg.Serialize(ref this.buffer);
if (bufferSize <= 0)
return true;
@ -220,7 +227,7 @@ namespace RoboidControl {
#region Receive
public void ReceiveData(byte[] data, RemoteParticipant remoteParticipant) {
public void ReceiveData(byte[] data, Participant remoteParticipant) {
byte msgId = data[0];
if (msgId == 0xFF) {
// Timeout
@ -268,9 +275,9 @@ namespace RoboidControl {
#region Process
protected virtual void Process(RemoteParticipant sender, ParticipantMsg msg) { }
protected virtual void Process(Participant sender, ParticipantMsg msg) { }
protected virtual void Process(RemoteParticipant sender, NetworkIdMsg msg) {
protected virtual void Process(Participant sender, NetworkIdMsg msg) {
Console.WriteLine($"{this.name} receive network id {this.networkId} {msg.networkId}");
if (this.networkId != msg.networkId) {
this.networkId = msg.networkId;
@ -279,27 +286,27 @@ namespace RoboidControl {
}
}
protected virtual void Process(RemoteParticipant sender, InvestigateMsg msg) { }
protected virtual void Process(Participant sender, InvestigateMsg msg) { }
protected virtual void Process(RemoteParticipant sender, ThingMsg msg) {
protected virtual void Process(Participant sender, ThingMsg msg) {
//Console.WriteLine($"Participant: Process thing [{msg.networkId}/{msg.thingId}]");
}
protected virtual void Process(RemoteParticipant sender, NameMsg msg) {
protected virtual void Process(Participant sender, NameMsg msg) {
//Console.WriteLine($"Participant: Process name [{msg.networkId}/{msg.thingId}] {msg.name}");
Thing thing = sender.Get(msg.networkId, msg.thingId);
if (thing != null)
thing.name = msg.name;
}
protected virtual void Process(RemoteParticipant sender, ModelUrlMsg msg) {
protected virtual void Process(Participant sender, ModelUrlMsg msg) {
//Console.WriteLine($"Participant: Process model [{msg.networkId}/{msg.thingId}] {msg.url}");
Thing thing = sender.Get(msg.networkId, msg.thingId);
if (thing != null)
thing.modelUrl = msg.url;
}
protected virtual void Process(RemoteParticipant sender, PoseMsg msg) {
protected virtual void Process(Participant sender, PoseMsg msg) {
//Console.WriteLine($"Participant: Process pose [{msg.networkId}/{msg.thingId}] {msg.poseType}");
Thing thing = sender.Get(msg.networkId, msg.thingId);
if (thing != null) {
@ -320,15 +327,15 @@ namespace RoboidControl {
}
}
protected virtual void Process(RemoteParticipant sender, BinaryMsg msg) {
protected virtual void Process(Participant sender, BinaryMsg msg) {
// Console.WriteLine($"Participant: Process binary [{msg.networkId}/{msg.thingId}]");
Thing thing = sender.Get(msg.networkId, msg.thingId);
thing?.ProcessBinary(msg.bytes);
}
protected virtual void Process(RemoteParticipant sender, TextMsg temsgxt) { }
protected virtual void Process(Participant sender, TextMsg temsgxt) { }
protected virtual void Process(RemoteParticipant sender, DestroyMsg msg) { }
protected virtual void Process(Participant sender, DestroyMsg msg) { }
private void ForwardMessage(IMessage msg) {
// foreach (Participant client in senders) {

View File

@ -6,7 +6,7 @@ namespace RoboidControl {
/// <summary>
/// A reference to a participant, possibly on a remote location
/// </summary>
public class RemoteParticipant {
public class Participant {
/// <summary>
/// The internet address of the participant
/// </summary>
@ -24,13 +24,13 @@ namespace RoboidControl {
/// <summary>
/// Default constructor
/// </summary>
public RemoteParticipant() {}
public Participant() { }
/// <summary>
/// Create a new remote participant
/// </summary>
/// <param name="ipAddress">The IP address of the participant</param>
/// <param name="port">The UDP port of the participant</param>
public RemoteParticipant(string ipAddress, int port) {
public Participant(string ipAddress, int port) {
this.ipAddress = ipAddress;
this.port = port;
}
@ -68,7 +68,8 @@ namespace RoboidControl {
if (invokeEvent)
Thing.InvokeNewThing(thing);
// Console.Write($"Add thing {ipAddress}:{port}[{networkId}/{thing.id}]");
} else {
}
else {
if (thing != foundThing) {
// should be: find first non-existing id...
thing.id = (byte)this.things.Count;

View File

@ -7,7 +7,7 @@ namespace RoboidControl {
/// <summary>
/// A site server is a participant which provides a shared simulated environment
/// </summary>
public class SiteServer : Participant {
public class SiteServer : LocalParticipant {
public SiteServer(int port = 7681) : this("0.0.0.0", port) { }
@ -42,21 +42,21 @@ namespace RoboidControl {
public override void Publish() {
}
protected override void Process(RemoteParticipant remoteParticipant, ParticipantMsg msg) {
protected override void Process(Participant remoteParticipant, ParticipantMsg msg) {
if (msg.networkId == 0) {
Console.WriteLine($"{this.name} received New Client -> {remoteParticipant.networkId}");
this.Send(remoteParticipant, new NetworkIdMsg(remoteParticipant.networkId));
}
}
protected override void Process(RemoteParticipant sender, NetworkIdMsg msg) { }
protected override void Process(Participant sender, NetworkIdMsg msg) { }
protected override void Process(RemoteParticipant sender, ThingMsg msg) {
protected override void Process(Participant sender, ThingMsg msg) {
//Console.WriteLine($"SiteServer: Process thing [{msg.networkId}/{msg.thingId}]");
Thing thing = sender.Get(msg.networkId, msg.thingId);
if (thing == null) {
Thing newThing = null;
if (thingMsgProcessors.TryGetValue(msg.thingType, out Func<RemoteParticipant, byte, byte, Thing> msgProcessor)) {
if (thingMsgProcessors.TryGetValue(msg.thingType, out Func<Participant, byte, byte, Thing> msgProcessor)) {
//Console.WriteLine("Found thing message processor");
if (msgProcessor != null)
newThing = msgProcessor(sender, msg.networkId, msg.thingId);

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Passer.LinearAlgebra;
namespace RoboidControl {
@ -12,28 +13,6 @@ namespace RoboidControl {
#region Types
#endregion Types
#region Properties
public delegate void ChangeHandler();
public delegate void SphericalHandler(Spherical v);
public delegate void ThingHandler(Thing t);
/// <summary>
/// The participant to which this thing belongs
/// </summary>
public RemoteParticipant owner;
/// <summary>
/// The network ID of this thing.
/// </summary>
public byte networkId;
/// <summary>
/// The ID of this thing
/// </summary>
public byte id;
/// <summary>
/// Predefined thing types
/// </summary>
@ -54,6 +33,81 @@ namespace RoboidControl {
Humanoid,
ExternalSensor
};
#endregion Types
#region Init
public Thing(byte thingType = (byte)Type.Undetermined) : this(LocalParticipant.Isolated(), thingType) {
}
public Thing(Participant owner, byte thingType = (byte)Type.Undetermined) {
this.owner = owner;
this.type = thingType;
}
public Thing(Thing parent, byte thingType = (byte)Type.Undetermined) : this(parent.owner, thingType) {
this.parent = parent;
}
/// <summary>
/// Create a new thing for the given participant
/// </summary>
/// <param name="owner">The participant for which this thing is created</param>
/// <param name="invokeEvent">True when a new thing event should be triggered</param>
public Thing(Participant owner, bool invokeEvent = false) {
this.owner = owner;
//owner.Add(this);
if (invokeEvent)
InvokeNewThing(this);
}
/// <summary>
/// Create a new thing for the given participant
/// </summary>
/// <param name="participant">The participant for which this thing is created</param>
/// <param name="networkId">The network ID of the thing</param>
/// <param name="thingId">The ID of the thing</param>
/// <param name="thingType">The type of thing</param>
public Thing(Participant participant, byte networkId, byte thingId, byte thingType = 0) {
this.owner = participant;
this.id = thingId;
this.type = thingType;
this.networkId = networkId;
}
/// <summary>
/// Function which can be used to create components in external engines.
/// </summary>
/// Currently this is used to create GameObjects in Unity
public virtual void CreateComponent() {
#if UNITY_5_3_OR_NEWER
this.component = Unity.Thing.Create(this);
this.component.core = this;
#endif
}
#endregion Init
#region Properties
public delegate void ChangeHandler();
public delegate void SphericalHandler(Spherical v);
public delegate void ThingHandler(Thing t);
/// <summary>
/// The participant to which this thing belongs
/// </summary>
public Participant owner;
/// <summary>
/// The network ID of this thing.
/// </summary>
public byte networkId;
/// <summary>
/// The ID of this thing
/// </summary>
public byte id;
/// <summary>
/// The type of this thing. This can be either a Thing::Type (needs casting)
/// or a byte value for custom types.
@ -201,62 +255,30 @@ namespace RoboidControl {
#endregion Properties
#region Init
/// <summary>
/// Create a new thing for the given participant
/// </summary>
/// <param name="owner">The participant for which this thing is created</param>
/// <param name="invokeEvent">True when a new thing event should be triggered</param>
public Thing(RemoteParticipant owner, bool invokeEvent = false) {
this.owner = owner;
//owner.Add(this);
if (invokeEvent)
InvokeNewThing(this);
}
/// <summary>
/// Create a new thing for the given participant
/// </summary>
/// <param name="participant">The participant for which this thing is created</param>
/// <param name="networkId">The network ID of the thing</param>
/// <param name="thingId">The ID of the thing</param>
/// <param name="thingType">The type of thing</param>
public Thing(RemoteParticipant participant, byte networkId, byte thingId, byte thingType = 0) {
this.owner = participant;
this.id = thingId;
this.type = thingType;
this.networkId = networkId;
}
/// <summary>
/// Function which can be used to create components in external engines.
/// </summary>
/// Currently this is used to create GameObjects in Unity
public virtual void CreateComponent() {
#if UNITY_5_3_OR_NEWER
this.component = Unity.Thing.Create(this);
this.component.core = this;
#endif
}
#endregion Init
#region Update
#if UNITY_5_3_OR_NEWER
// #if UNITY_5_3_OR_NEWER
/// <summary>
/// Convience function for use in Unity which removes the need for a currentTime argument
/// </summary>
public void Update() {
Update((ulong)UnityEngine.Time.time * 1000);
public void Update(bool recursive = false) {
Update(TimeManager.GetCurrentTimeMilliseconds(), recursive);
}
#endif
// #endif
/// <summary>
/// Update this thing
/// </summary>
/// <param name="currentTime">The current time in milliseconds</param>
public virtual void Update(ulong currentTime) {
public virtual void Update(ulong currentTimeMs, bool recursive = false) {
// should recurse over children...
if (recursive) {
for (byte childIx = 0; childIx < this.children.Count; childIx++) {
Thing child = this.children[childIx];
if (child == null)
continue;
child.Update(currentTimeMs, recursive);
}
}
}
/// <summary>

View File

@ -0,0 +1,51 @@
namespace RoboidControl {
/// @brief A thing which can move itself using a differential drive system
///
/// @sa @link https://en.wikipedia.org/wiki/Differential_wheeled_robot @endlink
public class DifferentialDrive : Thing {
/// @brief Create a differential drive without networking support
public DifferentialDrive() { }
/// @brief Create a differential drive with networking support
/// @param participant The local participant
public DifferentialDrive(LocalParticipant participant) : base(participant, false) { }
/// @brief Configures the dimensions of the drive
/// @param wheelDiameter The diameter of the wheels in meters
/// @param wheelSeparation The distance between the wheels in meters
///
/// These values are used to compute the desired wheel speed from the set
/// linear and angular velocity.
/// @sa SetLinearVelocity SetAngularVelocity
public void SetDriveDimensions(float wheelDiameter, float wheelSeparation) { }
/// @brief Congures the motors for the wheels
/// @param leftWheel The motor for the left wheel
/// @param rightWheel The motor for the right wheel
public void SetMotors(Thing leftWheel, Thing rightWheel) { }
/// @brief Directly specify the speeds of the motors
/// @param speedLeft The speed of the left wheel in degrees per second.
/// Positive moves the robot in the forward direction.
/// @param speedRight The speed of the right wheel in degrees per second.
/// Positive moves the robot in the forward direction.
public void SetWheelVelocity(float speedLeft, float speedRight) { }
/// @copydoc RoboidControl::Thing::Update(unsigned long)
public override void Update(ulong currentMs, bool recursive = true) { }
/// @brief The radius of a wheel in meters
protected float wheelRadius = 1.0f;
/// @brief The distance between the wheels in meters
protected float wheelSeparation = 1.0f;
/// @brief Convert revolutions per second to meters per second
protected float rpsToMs = 1.0f;
/// @brief The left wheel
protected Thing leftWheel = null;
/// @brief The right wheel
protected Thing rightWheel = null;
};
} // namespace RoboidControl

View File

@ -13,14 +13,14 @@ namespace RoboidControl {
/// Constructor for a new distance sensor
/// </summary>
/// <param name="participant">The participant for which the sensor is needed</param>
public DistanceSensor(RemoteParticipant participant) : base(participant, true) { }
public DistanceSensor(Participant participant) : base(participant, true) { }
/// <summary>
/// Create a distance sensor with the given ID
/// </summary>
/// <param name="participant">The participant for with the sensor is needed</param>
/// <param name="networkId">The network ID of the sensor</param>
/// <param name="thingId">The ID of the thing</param>
public DistanceSensor(RemoteParticipant participant, byte networkId, byte thingId) : base(participant, networkId, thingId, (byte)Type.TemperatureSensor) {
public DistanceSensor(Participant participant, byte networkId, byte thingId) : base(participant, networkId, thingId, (byte)Type.TemperatureSensor) {
}
#if UNITY_5_3_OR_NEWER

View File

@ -17,7 +17,7 @@ namespace RoboidControl {
/// <param name="participant">The participant for with the sensor is needed</param>
/// <param name="networkId">The network ID of the sensor</param>
/// <param name="thingId">The ID of the thing</param>
public TemperatureSensor(Participant participant, byte networkId, byte thingId) : base(participant, networkId, thingId, (byte)Type.TemperatureSensor) {}
public TemperatureSensor(LocalParticipant participant, byte networkId, byte thingId) : base(participant, networkId, thingId, (byte)Type.TemperatureSensor) { }
/// <summary>
/// Function to extract the temperature received in the binary message

View File

@ -7,7 +7,25 @@ namespace RoboidControl {
/// </summary>
public class TouchSensor : Thing {
public Participant thisParticipant;
/// <summary>
/// Create a touch sensor
/// </summary>
/// <param name="owner">The participant for with the sensor is needed</param>
/// <param name="invokeEvent">True when the creation should trigger an event</param>
public TouchSensor(Participant owner, bool invokeEvent = true) : base(owner, invokeEvent) {
//touchedSomething = false;
//thisParticipant = owner;
}
public TouchSensor(Participant owner, byte networkId, byte thingId) : base(owner, networkId, thingId) {
Console.Write("TouchSensor constructor");
//touchedSomething = false;
//thisParticipant = participant;
}
public TouchSensor(Thing parent) : base(parent) { }
public LocalParticipant thisParticipant;
/// <summary>
/// Value which is true when the sensor is touching something, false otherwise
@ -20,28 +38,12 @@ namespace RoboidControl {
_touchedSomething = value;
if (thisParticipant != null && this.owner != thisParticipant) {
BinaryMsg msg = new(networkId, this);
foreach (RemoteParticipant remoteParticipant in thisParticipant.owners)
foreach (Participant remoteParticipant in thisParticipant.owners)
thisParticipant.Send(remoteParticipant, msg);
}
}
}
/// <summary>
/// Create a touch sensor
/// </summary>
/// <param name="owner">The participant for with the sensor is needed</param>
/// <param name="invokeEvent">True when the creation should trigger an event</param>
public TouchSensor(RemoteParticipant owner, bool invokeEvent = true) : base(owner, invokeEvent) {
//touchedSomething = false;
//thisParticipant = owner;
}
public TouchSensor(RemoteParticipant owner, byte networkId, byte thingId) : base(owner, networkId, thingId) {
Console.Write("TouchSensor constructor");
//touchedSomething = false;
//thisParticipant = participant;
}
#if UNITY_5_3_OR_NEWER
/// @copydoc Passer::RoboidControl::Thing::CreateComponent
public override void CreateComponent() {

22
src/TimeManger.cs Normal file
View File

@ -0,0 +1,22 @@
using System.Diagnostics;
namespace RoboidControl {
public static class TimeManager {
private static readonly Stopwatch _stopwatch = new Stopwatch();
/// <summary>
/// Static constructor to start the stopwatch
/// </summary>
static TimeManager() {
_stopwatch.Start();
}
/// <summary>
/// Method to get the current time in milliseconds
/// </summary>
/// <returns>The current time in milliseconds</returns>
public static ulong GetCurrentTimeMilliseconds() {
return (ulong)_stopwatch.ElapsedMilliseconds;
}
}
}

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 239400f5314a5aa4bac98db5861f77a7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,36 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ControlCore", "ControlCore.csproj", "{F2DEE6B0-AF41-454E-AAC8-9E1E3ACC769F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{2C350E2B-9DDA-4037-BAE5-E12AB7A52398}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6601071A-9E9C-42E1-95EA-0A36C5D718E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6601071A-9E9C-42E1-95EA-0A36C5D718E4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6601071A-9E9C-42E1-95EA-0A36C5D718E4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6601071A-9E9C-42E1-95EA-0A36C5D718E4}.Release|Any CPU.Build.0 = Release|Any CPU
{DD7238DA-DBEF-4D6A-98DB-6FE28BBDB75D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DD7238DA-DBEF-4D6A-98DB-6FE28BBDB75D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD7238DA-DBEF-4D6A-98DB-6FE28BBDB75D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DD7238DA-DBEF-4D6A-98DB-6FE28BBDB75D}.Release|Any CPU.Build.0 = Release|Any CPU
{F2DEE6B0-AF41-454E-AAC8-9E1E3ACC769F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2DEE6B0-AF41-454E-AAC8-9E1E3ACC769F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2DEE6B0-AF41-454E-AAC8-9E1E3ACC769F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2DEE6B0-AF41-454E-AAC8-9E1E3ACC769F}.Release|Any CPU.Build.0 = Release|Any CPU
{2C350E2B-9DDA-4037-BAE5-E12AB7A52398}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C350E2B-9DDA-4037-BAE5-E12AB7A52398}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C350E2B-9DDA-4037-BAE5-E12AB7A52398}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C350E2B-9DDA-4037-BAE5-E12AB7A52398}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -5,7 +5,7 @@ using NUnit.Framework;
using RoboidControl;
namespace ControlCore.test {
namespace RoboidControl.test {
public class Tests {
[SetUp]
public void Setup() {
@ -13,7 +13,7 @@ namespace ControlCore.test {
[Test]
public void Test_Participant() {
Participant participant = new Participant("127.0.0.1", 7682);
LocalParticipant participant = new LocalParticipant("127.0.0.1", 7682);
ulong milliseconds = (ulong)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
ulong startTime = milliseconds;
@ -46,7 +46,7 @@ namespace ControlCore.test {
[Test]
public void Test_SiteParticipant() {
SiteServer siteServer = new SiteServer(7681);
Participant participant = new Participant("127.0.0.1", 7681);
LocalParticipant participant = new LocalParticipant("127.0.0.1", 7681);
ulong milliseconds = (ulong)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
ulong startTime = milliseconds;
@ -64,8 +64,8 @@ namespace ControlCore.test {
[Test]
public void Test_ThingMsg() {
SiteServer siteServer = new SiteServer(7681);
Participant participant = new Participant("127.0.0.1");
Thing thing = new Thing(participant) {
LocalParticipant participant = new LocalParticipant("127.0.0.1");
Thing thing = new Thing(participant, false) {
name = "First Thing",
modelUrl = "https://passer.life/extras/ant.jpg"
};

View File

@ -13,7 +13,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ControlCore.csproj" />
<ProjectReference Include="..\src\RoboidControl.csproj" />
</ItemGroup>
</Project>